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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
// Main.cpp
#include <windows.h>
#include <tchar.h>
#include <cstdio>
#include "Main.h"
FILE* fp=NULL;
long fnWndProc_OnCreate(WndEventArgs& Wea)
{
data* pd=NULL;
HWND hCtl;
fp=fopen("Output.txt","w");
fprintf(fp,"Entering fnWndProc_OnCreate()\n");
Wea.hIns=((LPCREATESTRUCT)Wea.lParam)->hInstance;
hCtl=CreateWindowEx(0,_T("button"),_T("Button #1"),WS_CHILD | WS_VISIBLE,75,60,150,30,Wea.hWnd,(HMENU)IDC_BUTTON1,Wea.hIns,0);
hCtl=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD | WS_VISIBLE,75,110,150,30,Wea.hWnd,(HMENU)IDC_EDITBOX1,Wea.hIns,0);
pd=(data*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(data));
fprintf(fp," pd = %d\n\n",(int)pd);
if(!pd) // if WM_CREATE fails - just return -1
return -1;
SetWindowLongPtr(Wea.hWnd,0,(long)pd);
for(int i=0; i < 20; i++)
pd->address[i] = i;
for(int i=0; i<20; i++)
fprintf(fp," %d\t%d\t%d\n",i,(int)&pd->address[i],(int)pd->address[i]);
fprintf(fp,"Leaving fnWndProc_OnCreate()\n");
return 0;
}
long fnWndProc_OnCommand(WndEventArgs& Wea)
{
data* pd;
HWND hEdit;
switch(LOWORD(Wea.wParam))
{
case IDC_BUTTON1:
fprintf(fp,"\nEntering fnWndProc_OnCommand() case IDC_BUTTON1\n");
hEdit=GetDlgItem(Wea.hWnd,IDC_EDITBOX1);
pd=(data*)GetWindowLongPtr(Wea.hWnd,0);
fprintf(fp," pd = %d\n",(int)pd);
if(pd->lpBuffer)
{
GetWindowText(hEdit,pd->lpBuffer,255);
fprintf(fp," pd->lpBuffer = %s\n",pd->lpBuffer);
InvalidateRect(Wea.hWnd,NULL,TRUE);
}
fprintf(fp,"Leaving fnWndProc_OnCommand()\n");
break;
}
return 0;
}
long fnWndProc_OnPaint(WndEventArgs& Wea)
{
HDC hDC=NULL;
PAINTSTRUCT ps;
data* pd;
int iPrev=0;
hDC=BeginPaint(Wea.hWnd,&ps);
iPrev=SetBkMode(hDC,TRANSPARENT);
pd=(data*)GetWindowLongPtr(Wea.hWnd,0);
TextOut(hDC,75,160,pd->lpBuffer,_tcslen(pd->lpBuffer));
SetBkMode(hDC,iPrev);
EndPaint(Wea.hWnd,&ps);
return 0;
}
long fnWndProc_OnDestroy(WndEventArgs& Wea)
{
fprintf(fp,"\nEntering fnWndProc_OnDestroy()\n");
data* pd=NULL; // Set to NULL, or it will contain gaerbage non-zero number
pd=(data*)GetWindowLongPtr(Wea.hWnd,0);
if(pd)
HeapFree(GetProcessHeap(),0,pd);
PostQuitMessage(0);
fprintf(fp,"Leaving fnWndProc_OnDestroy()\n");
fclose(fp);
return 0;
}
LRESULT CALLBACK fnWndProc(HWND hwnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
WndEventArgs Wea;
for(unsigned int i=0; i<dim(EventHandler); i++)
{
if(EventHandler[i].iMsg==msg)
{
Wea.hWnd=hwnd, Wea.lParam=lParam, Wea.wParam=wParam;
return (*EventHandler[i].fnPtr)(Wea);
}
}
return (DefWindowProc(hwnd, msg, wParam, lParam));
}
int WINAPI WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
TCHAR szClassName[]=_T("TextOut");
WNDCLASSEX wc;
MSG messages;
HWND hWnd;
wc.lpszClassName=szClassName; wc.lpfnWndProc=fnWndProc;
wc.cbSize=sizeof (WNDCLASSEX); wc.style=0;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION); wc.hInstance=hIns;
wc.hIconSm=LoadIcon(NULL, IDI_APPLICATION); wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)COLOR_BTNSHADOW; wc.cbWndExtra=sizeof(void*);
wc.lpszMenuName=NULL; wc.cbClsExtra=0;
RegisterClassEx(&wc);
hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,75,75,320,305,HWND_DESKTOP,0,hIns,0);
ShowWindow(hWnd,iShow);
while(GetMessage(&messages,NULL,0,0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
|