a mega cool windows xp app
1#include <windows.h> 2 3#define ID_ABOUT 1001 4#define ID_EXIT 1002 5 6LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); 7 8int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) { 9 const char* CLASS_NAME = "HelloWorldWindow"; 10 11 WNDCLASS wc = {}; 12 wc.lpfnWndProc = WindowProc; 13 wc.hInstance = hInstance; 14 wc.lpszClassName = CLASS_NAME; 15 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); 16 wc.hCursor = LoadCursor(NULL, IDC_ARROW); 17 18 RegisterClass(&wc); 19 20 HWND hwnd = CreateWindow( 21 CLASS_NAME, 22 "Hello World App", 23 WS_OVERLAPPEDWINDOW, 24 CW_USEDEFAULT, CW_USEDEFAULT, 400, 300, 25 NULL, 26 NULL, 27 hInstance, 28 NULL 29 ); 30 31 if (hwnd == NULL) { 32 return 0; 33 } 34 35 // Create menu 36 HMENU hMenu = CreateMenu(); 37 HMENU hSubMenu = CreatePopupMenu(); 38 39 AppendMenu(hSubMenu, MF_STRING, ID_ABOUT, "&About"); 40 AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL); 41 AppendMenu(hSubMenu, MF_STRING, ID_EXIT, "E&xit"); 42 AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, "&Help"); 43 44 SetMenu(hwnd, hMenu); 45 46 ShowWindow(hwnd, nCmdShow); 47 UpdateWindow(hwnd); 48 49 MSG msg = {}; 50 while (GetMessage(&msg, NULL, 0, 0)) { 51 TranslateMessage(&msg); 52 DispatchMessage(&msg); 53 } 54 55 return 0; 56} 57 58LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { 59 switch (uMsg) { 60 case WM_DESTROY: 61 PostQuitMessage(0); 62 return 0; 63 64 case WM_PAINT: { 65 PAINTSTRUCT ps; 66 HDC hdc = BeginPaint(hwnd, &ps); 67 68 RECT rect; 69 GetClientRect(hwnd, &rect); 70 71 // Center the text 72 SetTextAlign(hdc, TA_CENTER); 73 SetBkMode(hdc, TRANSPARENT); 74 TextOut(hdc, rect.right / 2, rect.bottom / 2 - 10, "Hello World!", 12); 75 76 EndPaint(hwnd, &ps); 77 return 0; 78 } 79 80 case WM_COMMAND: 81 switch (LOWORD(wParam)) { 82 case ID_ABOUT: { 83 const char* aboutText = "Hello World App\n\n" 84 "Version: 1.0.0\n" 85 "Built by: Kieran Klukas\n\n" 86 "A simple Win32 application\n" 87 "compatible with Windows XP"; 88 MessageBox(hwnd, aboutText, "About Hello World App", 89 MB_OK | MB_ICONINFORMATION); 90 break; 91 } 92 case ID_EXIT: 93 PostQuitMessage(0); 94 break; 95 } 96 return 0; 97 } 98 99 return DefWindowProc(hwnd, uMsg, wParam, lParam); 100}