1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <windows.h>
/* declare window procedure for this application. */
LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR szArgs,int nCmdShow)
{
MSG Msg; // save window messages here.
/* Run the message pump. It will run until GetMessage() returns 0 */
while (GetMessage (&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg); // Translate virtual-key messages to character messages
DispatchMessage(&Msg); // Send message to WindowProcedure
}
return Msg.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WinProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
switch (Message)
{
case VK_ESCAPE:
{
MessageBox(NULL,"You hit escape, quitting now.","Message",0);
PostQuitMessage(0);
break;
}
// handle non-trapped messages.
default:return DefWindowProc(hWnd,Message,wParam,lParam);
}
return 0; // this indicates a message was trapped.
}
| |