# include <windows.h>
HWND MainWindow;
LRESULT CALLBACK WindowProcedure ( HWND Window, UINT Message, WPARAM WParameter, LPARAM LParameter );
INT WINAPI WinMain ( HINSTANCE CurrentInstance, HINSTANCE PreviousInstance, LPSTR ArgumentCommand, INT DisplayCommand )
{
WNDCLASSEX WindowClass;
WindowClass.cbSize = sizeof ( WNDCLASSEX ),
WindowClass.style = 0,
WindowClass.lpfnWndProc = WindowProcedure,
WindowClass.cbClsExtra = 0,
WindowClass.cbWndExtra = 0,
WindowClass.hInstance = CurrentInstance,
WindowClass.hIcon = NULL,
WindowClass.hCursor = NULL,
WindowClass.hbrBackground = HBRUSH ( COLOR_BTNFACE ),
WindowClass.lpszMenuName = NULL,
WindowClass.lpszClassName = "WindowClass",
WindowClass.hIconSm = NULL;
RegisterClassEx ( & WindowClass );
MainWindow = CreateWindowEx ( 0,
"WindowClass",
"Window Caption",
WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
0,
0,
256,
256,
HWND_DESKTOP,
NULL,
CurrentInstance,
NULL );
ShowWindow ( MainWindow, SW_SHOWDEFAULT );
MSG Message;
for ( ; ; )
{
if ( PeekMessage ( & Message, NULL, 0, 0, PM_REMOVE ) )
{
if ( Message.message == WM_QUIT )
{
return 0;
}
TranslateMessage ( & Message );
DispatchMessage ( & Message );
}
Sleep ( 10 );
}
}
LRESULT CALLBACK WindowProcedure ( HWND Window, UINT Message, WPARAM WParameter, LPARAM LParameter )
{
static HWND ChildButton = NULL;
switch ( Message )
{
case WM_CREATE:
{
ChildButton = CreateWindowEx ( 0,
"Button",
"Notepad",
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
96,
116,
64,
24,
Window,
NULL,
GetModuleHandle ( NULL ),
NULL );
return 0;
}
case WM_COMMAND:
{
if ( HIWORD ( WParameter ) == BN_CLICKED &&
HWND ( LParameter ) == ChildButton )
{
ShellExecute ( NULL, "Open", "C:\\WINDOWS\\notepad.exe", 0, "C:\\WINDOWS\\notepad.exe", SW_SHOWDEFAULT );
}
return 0;
}
case WM_DESTROY:
{
PostQuitMessage ( 0 );
return 0;
}
default:
{
return DefWindowProc ( Window, Message, WParameter, LParameter );
}
}
}