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
|
/*
Form1 -- Basic Simple Template Program For Win32 Programming With The Windows Api.
*/
//Main.cpp
#include <windows.h>
#include <cstdio>
#include <tchar.h>
#include "Form1.h"
#define MyDebug
FILE* fp=NULL;
long fnWndProc_OnCreate(WndEventArgs& Wea) // This is your Form_Load() From VB
{
#ifdef MyDebug
fp=fopen("Output.txt","w");
if(fp)
{
fprintf(fp,"Entering fnWndProc_OnCreate()\n");
fprintf(fp," Output.txt Opened In fnWndProc_OnCreate()\n");
fprintf(fp," Wea.hWnd = %d\n",Wea.hWnd);
}
#endif
Wea.hIns=((LPCREATESTRUCT)Wea.lParam)->hInstance;
#ifdef MyDebug
if(fp)
fprintf(fp,"Leaving fnWndProc_OnCreate()\n\n");
#endif
return 0;
}
long fnWndProc_OnDestroy(WndEventArgs& Wea)
{
#ifdef MyDebug
fprintf(fp,"Entering fnWndProc_OnDestroy()\n");
fprintf(fp," Wea.hWnd = %d\n",Wea.hWnd);
fprintf(fp,"Leaving fnWndProc_OnDestroy()\n");
fclose(fp);
#endif
PostQuitMessage(0);
return 0;
}
long __stdcall fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam,LPARAM lParam)
{
WndEventArgs Wea; //This procedure loops through the EVENTHANDER array
//of structs to try to make a match with the msg parameter
for(unsigned int i=0; i<2; i++) //of the WndProc. If a match is made the event handling
{ //procedure is called through a function pointer -
if(EventHandler[i].iMsg==msg) //(EventHandler[i].fnPtr). If no match is found the
{ //msg is passed onto DefWindowProc().
Wea.hWnd=hwnd, Wea.lParam=lParam, Wea.wParam=wParam;
return (EventHandler[i].fnPtr)(Wea);
}
}
return (DefWindowProc(hwnd, msg, wParam, lParam));
}
int __stdcall WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
TCHAR szClassName[]=_T("Form1");
WNDCLASSEX wc={};
MSG messages;
HWND hWnd;
wc.lpszClassName=szClassName;
wc.lpfnWndProc=fnWndProc;
wc.cbSize=sizeof (WNDCLASSEX);
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance=hIns;
wc.hbrBackground=(HBRUSH)COLOR_BTNSHADOW;
RegisterClassEx(&wc);
hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,100,100,350,300,HWND_DESKTOP,0,hIns,0);
ShowWindow(hWnd,iShow);
while(GetMessage(&messages,NULL,0,0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
|