/* file: main.cpp */
/* This is a demonstration of Win32 Programming */
/* Includes */
#include <windows.h>
/* Function prototyes */
HWND Window( __in WNDPROC, __in_opt HWND Parent, __in char* title, __in char* cName, __in HINSTANCE, __in int x, __in int y, __in int width, __in int height, __in DWORD style, __in DWORD StyleEx);
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
/* WinMain - the entry point to the application */
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ){
MSG Msg = {0}; // the message handler for the main application
MSG cMsg = {0}; // the child window message handler
/* Create an instance of the window */
//hWnd = CreateMainWindow("Win32 01", "MyWindow", hInstance, 0, 0, 640,480);
HWND hWnd = Window( WndProc, NULL, "Main Window", "MyWin32", hInstance, 0, 0, 640, 480, WS_OVERLAPPEDWINDOW, WS_EX_CLIENTEDGE);
/* Create a child window */
HWND Child1 = Window( NULL, hWnd, "Child Window 1", "MyWin32", hInstance, 0, 0, 312, 225, WS_CHILDWINDOW, WS_EX_STATICEDGE);
HWND Child2 = Window( NULL, hWnd, "Child Window 2", "MyWin32", hInstance, 312, 0, 312, 225, WS_CHILDWINDOW, WS_EX_STATICEDGE);
HWND Child3 = Window( NULL, hWnd, "Child Window 3", "MyWin32", hInstance, 0, 225, 312, 225, WS_CHILDWINDOW, WS_EX_STATICEDGE);
HWND Child4 = Window( NULL, hWnd, "Child Window 4", "MyWin32", hInstance, 312, 225, 312, 225, WS_CHILDWINDOW, WS_EX_STATICEDGE);
while(Msg.message != WM_QUIT)
{
// If there are Window messages for the main window then process them.
if(PeekMessage( &Msg, hWnd, 0, 0, PM_REMOVE ))
{
TranslateMessage( &Msg );
DispatchMessage( &Msg );
}
// Otherwise, Process the child windows.
else
{
}
}
return Msg.wParam;
}
/* Function Definitions */
HWND Window( __in WNDPROC WndProcr, __in_opt HWND Parent, __in char* title, __in char* cName, __in HINSTANCE hInstance, __in int x, __in int y, __in int width, __in int height, __in DWORD Style, __in DWORD StyleEx){
HWND hWnd;
WNDCLASSEX wcex; // the window class descriptor
/* Firstly fill out the Window class structure */
wcex.cbSize = sizeof(WNDCLASSEX); // the size of the structure
wcex.cbClsExtra = 0; // no extra bytes
wcex.cbWndExtra = 0; // no extra bytes for the window
wcex.style = CS_HREDRAW | CS_VREDRAW; // style of the window
wcex.hCursor = LoadCursor( NULL, IDC_ARROW );
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hIconSm = LoadIcon( NULL, IDI_WINLOGO );
wcex.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
wcex.hInstance = hInstance;
wcex.lpfnWndProc = WndProcr;
wcex.lpszClassName = cName;
wcex.lpszMenuName = NULL;
RegisterClassEx(&wcex);
/* Create the window */
hWnd = CreateWindowEx( StyleEx,
cName,
title,
Style,
x, y,
width, height,
Parent, NULL,
hInstance,
NULL);
if( !hWnd ){
MessageBox( NULL, "Creation of window Failed.", "Error", MB_OK | MB_IConerror );
return NULL;
}
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
return hWnd;
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ){
switch (uMsg){
case WM_CREATE: break;
case WM_CLOSE: DestroyWindow(hWnd); break;
case WM_DESTROY: PostQuitMessage(0); break;
case WM_KEYDOWN: if( wParam == VK_ESCAPE )
PostQuitMessage(0);
break;
default: return DefWindowProc(hWnd, uMsg, wParam, lParam); break;
}
return 0;
}
Please advise.
Regards
Dave

New Topic/Question
Reply




MultiQuote




|