/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
RECT rt;
PAINTSTRUCT ps;
TCHAR line[100];
POINT curpos;
switch (message) /* handle the messages */
{
case WM_CREATE:
SetTimer(hwnd,200,100,NULL);
break;
case WM_TIMER:
InvalidateRect(hwnd,NULL,FALSE);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rt);
GetCursorPos(&curpos);/*本来就有这个函数*/
TextOut(hdc,rt.right/2-10,rt.bottom/2-10,line,wsprintf(line,TEXT("x=%d y=%d"),curpos.x,curpos.y));
EndPaint(hwnd,&ps);
break;
case WM_DESTROY:
KillTimer(hwnd,200);
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}