16,472
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <windows.h>
#include <windowsx.h>
#include "Resource.h"
#include "MainDlg.h"
void Main_OnMouseMove(HWND hwnd, int x, int y, UINT keyFlags);
BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);
HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);
HANDLE_MSG(hWnd, WM_MOUSEMOVE, Main_OnMouseMove);
}
return FALSE;
}
void Main_OnMouseMove(HWND hwnd, int x, int y, UINT keyFlags)
{
RECT rect;
POINT pt;
pt.x=x;
pt.y=y;
GetWindowRect(GetDlgItem(hwnd,IDC_OK),&rect);
TCHAR str[256];
wsprintf(str,TEXT("%d %d"),x,y);
SetWindowText(hwnd,str);
if (PtInRect(&rect,pt)) //一样收不到。当鼠标进入Button1时处理。 调试发现:当鼠标到Button时,根本不走这个函数。
{
MessageBox(hwnd,TEXT(""),TEXT(""),MB_OK);
}
}
BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
return TRUE;
}
void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{
case IDC_OK:
{
MessageBox(hwnd,TEXT("点击了OKs!"),TEXT("提示"),MB_OK);
}
break;
default:
break;
}
}
void Main_OnClose(HWND hwnd)
{
EndDialog(hwnd, 0);
}