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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
//Main.cpp
#ifndef UNICODE
#define UNICODE
#endif
#define MyDebug
#include <windows.h>
#include <cstdio>
#ifdef MyDebug
FILE* fp=NULL;
#endif
LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
#ifdef MyDebug
fprintf(fp," Entering fnWndProc() -- case WM_CRETE\n");
fprintf(fp," hwnd = %p\n",hwnd);
#endif
#ifdef MyDebug
fprintf(fp," Leaving fnWndProc() -- case WM_CREATE\n");
#endif
return 0;
}
case WM_DESTROY:
{
#ifdef MyDebug
fprintf(fp," Entering fnWndProc() -- case WM_DESTROY\n");
#endif
PostQuitMessage(0);
#ifdef MyDebug
fprintf(fp," Leaving fnWndProc() -- case WM_DESTROY\n");
#endif
return 0;
}
}
return (DefWindowProc(hwnd, msg, wParam, lParam));
}
int WINAPI WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
wchar_t szClassName[]=L"Form1";
WNDCLASSEX wc;
MSG messages;
HWND hWnd;
#ifdef MyDebug
fp=fopen("Output_Log.txt","w");
fprintf(fp,"Entering WinMain()\n");
#endif
memset(&wc,0,sizeof(WNDCLASSEX));
wc.lpszClassName = szClassName; wc.lpfnWndProc=fnWndProc;
wc.cbSize = sizeof (WNDCLASSEX); wc.hInstance=hIns;
wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
RegisterClassEx(&wc);
hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,75,75,320,305,HWND_DESKTOP,0,hIns,0);
#ifdef MyDebug
fprintf(fp," hWnd = %p\n",hWnd);
#endif
ShowWindow(hWnd,iShow);
while(GetMessage(&messages,NULL,0,0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
#ifdef MyDebug
fprintf(fp,"Leaving WinMain()\n");
fclose(fp);
#endif
return messages.wParam;
}
/*
Output:
Entering WinMain()
Entering fnWndProc() -- case WM_CRETE
hwnd = 002E0466
Leaving fnWndProc() -- case WM_CREATE
hWnd = 002E0466
Entering fnWndProc() -- case WM_DESTROY
Leaving fnWndProc() -- case WM_DESTROY
Leaving WinMain()
*/
|