Dont u dare tell me parksie about any mistakes :D
#include <windows.h> //Standard Windows Header
#include <stdio.h>
HWND g_hWnd_main; //Holds The Handle To The Application
HINSTANCE g_hInstance; //Instance Of The Application
char g_szAppName[] = "wndExample"; //Name Of The Application And Main Window Class
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CLOSE: //When The Apps Quitted
DestroyWindow(g_hWnd_main); //Destroy The Window
break;
case WM_DESTROY: //When The Windows Destroyed
PostQuitMessage(0); //Quit The Application
break;
case WM_SIZE: //When The Window Is Resized
break;
case WM_KEYDOWN: //When A Key Is Pressed
break;
case WM_KEYUP: //When A Key Is Released
break;
case WM_MOVE: //When A Window Is Moved
break;
case WM_COMMAND: //When A Button/Control Is Had Someting Done To It
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam); //Pass The Messages To The Default Handler
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg; //Message Holder For The Application
WNDCLASSEX WndClassEx; //Window Class
g_hInstance = hInstance; //Pass The Instance To The Global Variable
WndClassEx.cbClsExtra = 0; //Extra Bytes In Class Definition
WndClassEx.cbSize = sizeof(WNDCLASSEX); //The Size Of The Class Data
WndClassEx.cbWndExtra = 0; //Extra Bytes For Each Window
WndClassEx.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); //Color For The Window
WndClassEx.hCursor = LoadCursor(NULL, IDC_ARROW); //Default System Arrow
WndClassEx.hIcon = NULL; //Main Application Icon
WndClassEx.hIconSm = NULL; //Small Application Icon
WndClassEx.hInstance = hInstance; //Pass The Instance To The Windows Class
WndClassEx.lpfnWndProc = (WNDPROC) WndProc; //The Message Handler Function
WndClassEx.lpszClassName = g_szAppName; //Class Name For The Window
WndClassEx.lpszMenuName = NULL; //Menu Bar Resource
WndClassEx.style = 0; //Extra Style Information
if (!RegisterClassEx(&WndClassEx)) //Register The Class
{
MessageBox(NULL, "Error - Failed To Register Class", "Error", MB_OK | MB_SYSTEMMODAL | MB_ICONEXCLAMATION);
return 0; //Quit The Function And Return FALSE
}
g_hWnd_main = CreateWindow( g_szAppName, "Window Example", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, NULL, NULL, hInstance, NULL); //Create The Window
if (!g_hWnd_main)
{
MessageBox(NULL, "Error - Failed To Create Window", "Error", MB_OK | MB_SYSTEMMODAL | MB_ICONEXCLAMATION);
return 0; //Quit The Function And Return FALSE
}
else
{
//Create Controls Here Or Under WM_CREATE Message
}
ShowWindow(g_hWnd_main, SW_SHOW); //Show The Window
UpdateWindow(g_hWnd_main); //Update The Window
SetFocus(g_hWnd_main); //Give The Window Focus
while (GetMessage(&Msg, NULL, 0, 0)) //While There Are Messages
{
TranslateMessage(&Msg); //Translate Them
DispatchMessage(&Msg); //Dispatch Them, Pass To The Message Handler Function
}
UnregisterClass(g_szAppName, hInstance); //Unregister The Class
return Msg.wParam; //Return The Code Passed To PostQuitMessage()
}