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
|
// cl Main.cpp /O1 /Os /FeForm4.exe /link Kernel32.lib User32.lib // 91,648 Bytes
// g++ Form2.cpp -luser32 -lkernel32 -oForm2_gcc.exe -mwindows -m64 -s -Os // 17,920 Bytes
// cl Form4.cpp /O1 /Os /GS- /link TCLib.lib kernel32.lib user32.lib // 4,608 Bytes
//#define TCLib
#include <windows.h>
#ifdef TCLib
#include "stdio.h"
#include "tchar.h"
#else
#include <cstdio>
#include <tchar.h>
#endif
#define IDC_BUTTON 1500
#define IDC_EDIT 1505
LRESULT CALLBACK fnWndProc_OnCreate(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
HINSTANCE hIns = NULL;
HWND hEdit = NULL;
HWND hBtn = NULL;
hIns=((LPCREATESTRUCT)lParam)->hInstance;
hEdit=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),WS_CHILD|WS_VISIBLE,50,40,200,25,hWnd,(HMENU)IDC_EDIT,hIns,0);
SetWindowText(hEdit,_T("Here Is Some Text!"));
hBtn=CreateWindowEx(0,_T("button"),_T("Retrieve Text"),WS_CHILD|WS_VISIBLE,95,90,120,30,hWnd,(HMENU)IDC_BUTTON,hIns,0);
PostMessage(hWnd,WM_COMMAND,MAKEWPARAM(IDC_BUTTON,BN_CLICKED),(LPARAM)hBtn);
return 0;
}
LRESULT CALLBACK fnWndProc_OnCommand(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
TCHAR szBuffer[256];
if(LOWORD(wParam)==IDC_BUTTON && HIWORD(wParam)==BN_CLICKED)
{
GetWindowText(GetDlgItem(hWnd,IDC_EDIT),szBuffer,256);
MessageBox(hWnd,szBuffer,_T("Button Click"),MB_OK);
}
return 0;
}
LRESULT CALLBACK fnWndProc_OnClose(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
DestroyWindow(hWnd);
return 0;
}
LRESULT CALLBACK fnWndProc_OnDestroy(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
PostQuitMessage(0);
return 0;
}
LRESULT CALLBACK fnWndProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
switch(msg) // I don't personally much care for placing a lot of code
{ // in 'case' constructs under a switch statement. So at
case WM_CREATE: // left you see I created seperate 'message handling functions'
return fnWndProc_OnCreate(hWnd, msg, wParam, lParam); // to put actual code to be executed for each message to be
case WM_COMMAND: // handled. The idea illustrated here is pretty simple; in my
return fnWndProc_OnCommand(hWnd, msg, wParam, lParam); // actual production code I don't use switch logic but rather
case WM_CLOSE:
return fnWndProc_OnClose(hWnd, msg, wParam, lParam);
case WM_DESTROY: // for loop logic to iterate through a struct array containing
return fnWndProc_OnDestroy(hWnd, msg, wParam, lParam); // the message and a function pointer to the message handling
} // function that handles that specific message.
return (DefWindowProc(hWnd, msg, wParam, lParam));
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
TCHAR szClassName[] =_T("Form4");
HWND hWnd = NULL;
WNDCLASSEX wc;
MSG messages;
memset(&wc,0,sizeof(wc));
wc.lpszClassName = szClassName;
wc.lpfnWndProc = fnWndProc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
wc.hInstance = hInstance;
RegisterClassEx(&wc);
hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,200,175,320,200,HWND_DESKTOP,0,hInstance,0); // C Based Object Constructor
ShowWindow(hWnd,iShow);
while(GetMessage(&messages,NULL,0,0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
| |