Code:
/****************************************************
**** FirstButton -- an example to create child****
**** window controls starting with the button ****
****************************************************/
#include <windows.h>
/***************************************************
**** Function Prototypes: ****
**** - WndProc : main window procedure ****
***************************************************/
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
/***************************************************
**** Globals/Constants: ****
**** hInst : Global type HINSTANCE ****
**** NUM : Constant number of buttons ****
***************************************************/
#define NUM 1
HINSTANCE hInst;
/***************************************************
**** Main Code Section/Functions/Definitions:****
**** - WinMain ****
**** - WndProc : main window procedure ****
***************************************************/
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int nCmdShow)
{
HWND hwnd;
WNDCLASS wc;
MSG msg;
TCHAR szClassName[] = TEXT("MainWindow");
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = szClassName;
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;
if(!RegisterClass(&wc))
{
MessageBox(NULL, TEXT("Error registering window!"), szClassName, MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hInst = hInstance;
hwnd = CreateWindow(szClassName, TEXT("Main Window"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
/***************************************************
**** WndProc : main window procedure ****
***************************************************/
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndButton;
HDC hdc;
static int cyChar, cxChar;
switch(message)
{
case WM_CREATE:
cxChar = LOWORD(GetDialogBaseUnits());
cyChar = HIWORD(GetDialogBaseUnits());
hwndButton = CreateWindow("button", TEXT("firstbutton"),
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
cxChar, cyChar, 20 * cxChar, 7 * cyChar / 4,
hwnd, (HMENU) 1, hInst, NULL);
return 0;
case WM_SIZE:
return 0;
case WM_PAINT:
return 0;
case WM_COMMAND:
MessageBox(NULL, TEXT("Test"), TEXT("Test"), MB_OK);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
break;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
Garfield