C++获取程序窗口外的鼠标坐标
2011-04-19 14:58
585 查看
首先 你可以在OnInitDialog里设置一个定时器
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
SetTimer(1,100,NULL);//时间设置短一点 显示的也快点
return TRUE; // return TRUE unless you set the focus to a control
然后为对话框添加WM_TIME消息
void CAdcDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
POINT pos;
GetCursorPos(&pos); //取鼠标的坐标
CString str;
str.Format("%d,%d",pos.x,pos.y);
m_dd=str;
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
SetTimer(1,100,NULL);//时间设置短一点 显示的也快点
return TRUE; // return TRUE unless you set the focus to a control
然后为对话框添加WM_TIME消息
void CAdcDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
POINT pos;
GetCursorPos(&pos); //取鼠标的坐标
CString str;
str.Format("%d,%d",pos.x,pos.y);
m_dd=str;
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
相关文章推荐
- 002--VS C++ 获取鼠标坐标并显示在窗口上
- C++获取窗口坐标并移动窗口
- C#如何获取鼠标相对当前窗口的坐标
- 解决C#获取鼠标相对当前窗口坐标的实现方法
- js中获取各种窗口的大小和鼠标坐标
- Java获取窗口鼠标坐标以及键盘
- Windows程序获取鼠标下窗口句柄的例子
- js中获取各种窗口的大小和鼠标坐标
- C#如何获取鼠标相对当前窗口的坐标(转自博客园)
- C#如何获取鼠标相对当前窗口的坐标
- C++获取鼠标坐标并移动鼠标
- C#如何获取鼠标相对当前窗口的坐标
- js获取各种窗口的大小和鼠标坐标
- c++鼠标点点,获取坐标值,放入到txt文件中
- delphi2010获取鼠标指向窗口的位置及鼠标在窗口内的相对位置坐标
- 一个获取当前鼠标坐标和颜色rgb值的小程序
- js中获取各种窗口的大小和鼠标坐标
- C++获取鼠标坐标并移动鼠标
- C++获取任务栏打开程序窗口示例
- matlab练习程序(获取鼠标坐标)