#include
#include //必须导入此头文件
#pragma comment(lib, "comctl32.lib")
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("UIDesign");
HWND hwnd;
MSG msg;
WNDCLASSEX wndclassex = {0};
wndclassex.cbSize = sizeof(WNDCLASSEX);
wndclassex.style = CS_HREDRAW | CS_VREDRAW;
wndclassex.lpfnWndProc = WndProc;
wndclassex.cbClsExtra = 0;
wndclassex.cbWndExtra = 0;
wndclassex.hInstance = hInstance;
wndclassex.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclassex.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclassex.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndclassex.lpszMenuName = NULL;
wndclassex.lpszClassName = szAppName;
wndclassex.hIconSm = wndclassex.hIcon;
if (!RegisterClassEx (&wndclassex))
{
MessageBox (NULL, TEXT ("RegisterClassEx failed!"), szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindowEx (WS_EX_OVERLAPPEDWINDOW,
szAppName,
TEXT ("UIDesign_test"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
500,
500,
NULL,
NULL,
hInstance,
NULL);
ShowWindow (hwnd, iCmdShow);
UpdateWindow (hwnd);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
static TRACKMOUSEEVENT trmouse;
static int isIn = 0, isOut = 1;
switch(uMsg)
{
case WM_MOUSELEAVE:
hdc = GetDC (hWnd) ;
TextOut(hdc, 10, 10, "run_out", strlen("run_out"));
ReleaseDC (hWnd, hdc) ;
isIn=0;
isOut = 1;
break;
case WM_MOUSEHOVER:
if (isOut != 0)
{
hdc = GetDC (hWnd) ;
TextOut(hdc, 10, 10, "run__in", strlen("run__in"));
ReleaseDC (hWnd, hdc) ;
isIn = 0;
isOut = 0;
}
break;
case WM_MOUSEMOVE: //因为 TRACKMOUSEEVENT 只发送一次消息,且随着其它消息产生而失效,所以在此消息中调用函数。
if (isIn == 0)
{
trmouse.cbSize = sizeof(TRACKMOUSEEVENT);
trmouse.dwFlags = TME_LEAVE | TME_HOVER;
trmouse.dwHoverTime = 10;
trmouse.hwndTrack = hWnd;
if(!_TrackMouseEvent(&trmouse))
return FALSE;
isIn++;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,uMsg,wParam,lParam);
break;
}
return 0;
}
我就只是发代码了,我说一下自己的个人想法,在研究这两个消息的时候,最好不要用MessageBox来检验是否成功,而去用TextOut()这个函数为好...至于原因,在这里不详说了,有问题留言.
这里的,可不是MFC的哈!!
如果是MFC中的问题,暂时我没办法回答!!谢谢