对话框中有CListCtrl控件时,在CListCtrl控件上移动鼠标,对话框收不到鼠标移动消息怎么办?
解决方案 »
- MFC动态创建问题
- 关于重叠结构的多客户端问题
- 我编写的自动升级程序
- 如何做个配置工具读写INI?多谢大家
- 我在 Cmainframe 用一个对话框工具条CDialogBar 上面添加拉控件ID 号为IDC_CHECK 的 checkbox 我如何在 程序中得到 CDialogBar 上复选
- 如何判断某process的一个thread属于哪个module?
- 急!!!!!!!有哪位好心的高高手肯帮帮我解决一道有关VC++进程的题目?!!!!!!(转)
- 我用CreateProcess创建了一个进程用来执行另外一个控制台程序,但一运行就会死掉!
- .pdg文件格式怎么打开?
- 高分请教:急,如何将删除的文件找回来!!!
- 怎样将两个工程文件加在一起
- 如何动态设置picture控件图片
在 CMyLiStCtrl 重载虚函数 PreTranslateMessage
BOOL CMyLiStCtrl::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_MOUSEMOVE)//鼠标移动消息
{
CWnd *pWnd = GetParent(); //获取父窗口指针
if(pWnd && pWnd->GetSafeHwnd()) //父窗口指针有效
{
//计算此控件与父窗口的位置偏差
CRect this_rect;
GetWindowRect(&this_rect);
CRect parent_rect;
pWnd->GetWindowRect(&parent_rect);
CPoint offset(this_rect.left - parent_rect.left,this_rect.top - parent_rect.top);
//当前窗口中的鼠标位置
CPoint point(LOWORD(pMsg->lParam),HIWORD(pMsg->lParam)); //换算到父窗口位置
CPoint parentPoint = point + offset; //传递消息给父窗口
::PostMessage(pWnd->m_hWnd,WM_MOUSEMOVE,pMsg->wParam,MAKELONG(parentPoint.x,parentPoint.y));
}
} return CListCtrl::PreTranslateMessage(pMsg);
}在对话框头文件中 #include "MyLiStCtrl.h"
把 CListCtrl 修改为 CMyLiStCtrl 即可
BOOL CMouseMoveOnLstCtlDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_MOUSEMOVE && GetFocus()->GetDlgCtrlID() == IDC_LIST1)
{
AfxMessageBox("MOVE ON LISTCTRL");
}
return CDialog::PreTranslateMessage(pMsg);
}但有个缺点是只有在listctrl获得焦点时才会弹出消息框
不过可以将GetFocus()->GetDlgCtrlID() == IDC_LIST1条件变为判断当前坐标点是否在clistctrl的矩形区域内 再&& pMsg->message == WM_MOUSEMOVE 应该可以
BOOL CMouseMoveOnLstCtlDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_MOUSEMOVE && GetFocus()->GetDlgCtrlID() == IDC_LIST1)
{
AfxMessageBox("MOVE ON LISTCTRL");
}
return CDialog::PreTranslateMessage(pMsg);
}但有个缺点是只有在listctrl获得焦点时才会弹出消息框
不过可以将GetFocus()->GetDlgCtrlID() == IDC_LIST1条件变为判断当前坐标点是否在clistctrl的矩形区域内 再&& pMsg->message == WM_MOUSEMOVE 应该可以
BOOL CMouseMoveOnLstCtlDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_MOUSEMOVE && GetFocus()->GetDlgCtrlID() == IDC_LIST1)
{
AfxMessageBox("MOVE ON LISTCTRL");
}
return CDialog::PreTranslateMessage(pMsg);
}但有个缺点是只有在listctrl获得焦点时才会弹出消息框
不过可以将GetFocus()->GetDlgCtrlID() == IDC_LIST1条件变为判断当前坐标点是否在clistctrl的矩形区域内 再&& pMsg->message == WM_MOUSEMOVE 应该可以
SetTimer(1,4000,NULL); //启动4秒钟定时器加入 WM_TIMER 定时器消息映射
OnTimer( UINT nIDEvent )
{
if(nIDEvent == 1)//为4秒钟关闭对话框定时器
{
KillTimer(1); //关闭定时器
EndDialog(IDCANCEL); 结束对话框
return;
}
}重载 PreTranslateMessage
PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
//
if(pMsg->message == WM_MOUSEFIRST) //鼠标开始移动
{
KillTimer(1); //关闭定时器
}
}//在规定的时间中有鼠标在对话框上移动就关闭定时器