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
|
//Form9.cpp -- compiler switches /O1 /Oi /Os /GL /D 8704 bytes; 116 lines
#include <windows.h>
#include <tchar.h>
#define IDC_LOVE 1500
#define IDC_HATE 1505
#define TXT_LOVE 1510
#define TXT_HATE 1515
#define dim(x) (sizeof(x) / sizeof(x[0]))
struct WndEventArgs
{
HWND hWnd;
WPARAM wParam;
LPARAM lParam;
HINSTANCE hIns;
};
long fnWndProc_OnCreate (WndEventArgs& Wea);
long fnWndProc_OnCommand (WndEventArgs& Wea);
long fnWndProc_OnDestroy (WndEventArgs& Wea);
struct EVENTHANDLER
{
unsigned int iMsg;
long (*fnPtr)(WndEventArgs&);
};
const EVENTHANDLER EventHandler[]=
{
{WM_CREATE, fnWndProc_OnCreate},
{WM_COMMAND, fnWndProc_OnCommand},
{WM_DESTROY, fnWndProc_OnDestroy}
};
long fnWndProc_OnCreate(WndEventArgs& Wea)
{
Wea.hIns=((LPCREATESTRUCT)Wea.lParam)->hInstance;
CreateWindowEx(0,_T("button"),_T("Love"),WS_CHILD|WS_VISIBLE,125,15,80,30,Wea.hWnd,(HMENU)IDC_LOVE,Wea.hIns,0);
CreateWindowEx(WS_EX_CLIENTEDGE,"edit",_T(""),WS_CHILD|WS_VISIBLE,25,60,285,22,Wea.hWnd,(HMENU)TXT_LOVE,Wea.hIns,0);
CreateWindowEx(0,_T("button"),_T("Hate"),WS_CHILD|WS_VISIBLE,125,105,80,30,Wea.hWnd,(HMENU)IDC_HATE,Wea.hIns,0);
CreateWindowEx(WS_EX_CLIENTEDGE,"edit",_T(""),WS_CHILD|WS_VISIBLE,25,150,285,22,Wea.hWnd,(HMENU)TXT_HATE,Wea.hIns,0);
return 0;
}
long fnWndProc_OnCommand(WndEventArgs& Wea)
{
switch(LOWORD(Wea.wParam))
{
case IDC_LOVE:
SetWindowText(GetDlgItem(Wea.hWnd,TXT_LOVE),_T("The World Needs More Love!"));
MessageBox(Wea.hWnd,_T("...More Love!"),_T("This Is What You Want..."),MB_OK);
break;
case IDC_HATE:
SetWindowText(GetDlgItem(Wea.hWnd,TXT_HATE),_T("The World Needs More Hate!"));
MessageBox(Wea.hWnd,_T("...More Hate!"),_T("This Is What You Want..."),MB_OK);
break;
}
return 0;
}
long fnWndProc_OnDestroy(WndEventArgs& Wea)
{
DestroyWindow(Wea.hWnd);
PostQuitMessage(0);
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 __stdcall WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
TCHAR szClassName[]=_T("Form9");
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=0;
wc.lpszMenuName=NULL; wc.cbClsExtra=0;
RegisterClassEx(&wc);
hWnd=CreateWindowEx(0,szClassName,_T("Form9"),WS_OVERLAPPEDWINDOW,200,100,340,240,HWND_DESKTOP,0,hIns,0);
ShowWindow(hWnd,iShow);
while(GetMessage(&messages,NULL,0,0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
|