a mega cool windows xp app
1#include <windows.h>
2#include "qr.h"
3
4#define ID_ABOUT 1001
5#define ID_EXIT 1002
6#define ID_GENERATE_QR 1003
7
8LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
9
10// Global QR code instance - static allocation, no new/delete
11QRCode g_qrCode;
12BOOL g_hasQrCode = FALSE;
13char g_qrText[256] = "Hello World!";
14
15int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow) {
16 const char* CLASS_NAME = "HelloWorldWindow";
17
18 WNDCLASS wc = {};
19 wc.lpfnWndProc = WindowProc;
20 wc.hInstance = hInstance;
21 wc.lpszClassName = CLASS_NAME;
22 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
23 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
24
25 RegisterClass(&wc);
26
27 HWND hwnd = CreateWindow(
28 CLASS_NAME,
29 "Hello World App",
30 WS_OVERLAPPEDWINDOW,
31 CW_USEDEFAULT, CW_USEDEFAULT, 400, 300,
32 NULL,
33 NULL,
34 hInstance,
35 NULL
36 );
37
38 if (hwnd == NULL) {
39 return 0;
40 }
41
42 // Create menu
43 HMENU hMenu = CreateMenu();
44
45 // Tools menu
46 HMENU hToolsMenu = CreatePopupMenu();
47 AppendMenu(hToolsMenu, MF_STRING, ID_GENERATE_QR, "&Generate QR Pattern");
48 AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hToolsMenu, "&Tools");
49
50 // Help menu
51 HMENU hHelpMenu = CreatePopupMenu();
52 AppendMenu(hHelpMenu, MF_STRING, ID_ABOUT, "&About");
53 AppendMenu(hHelpMenu, MF_SEPARATOR, 0, NULL);
54 AppendMenu(hHelpMenu, MF_STRING, ID_EXIT, "E&xit");
55 AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hHelpMenu, "&Help");
56
57 SetMenu(hwnd, hMenu);
58
59 ShowWindow(hwnd, nCmdShow);
60 UpdateWindow(hwnd);
61
62 MSG msg = {};
63 while (GetMessage(&msg, NULL, 0, 0)) {
64 TranslateMessage(&msg);
65 DispatchMessage(&msg);
66 }
67
68 return 0;
69}
70
71LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
72 switch (uMsg) {
73 case WM_SIZE:
74 // Trigger repaint when window is resized
75 InvalidateRect(hwnd, NULL, TRUE);
76 return 0;
77
78 case WM_DESTROY:
79 // No cleanup needed for static allocation
80 PostQuitMessage(0);
81 return 0;
82
83 case WM_PAINT: {
84 PAINTSTRUCT ps;
85 HDC hdc = BeginPaint(hwnd, &ps);
86
87 RECT rect;
88 GetClientRect(hwnd, &rect);
89
90 if (g_hasQrCode) {
91 // Draw QR code - calculate size based on window
92 int qrSize = QRCode_GetSize();
93 int moduleSize = 8;
94 int qrPixelSize = qrSize * moduleSize;
95
96 // Center horizontally and vertically with some padding
97 int startX = (rect.right - qrPixelSize) / 2;
98 int startY = (rect.bottom - qrPixelSize - 80) / 2; // Leave space for text
99
100 QRCode_DrawToHDC(&g_qrCode, hdc, startX, startY, moduleSize);
101
102 // Draw text below QR code
103 SetTextAlign(hdc, TA_CENTER);
104 SetBkMode(hdc, TRANSPARENT);
105 int textLen = 0;
106 while (g_qrText[textLen]) textLen++; // Calculate length
107 TextOut(hdc, rect.right / 2, startY + qrPixelSize + 20,
108 g_qrText, textLen);
109
110 // Add disclaimer
111 const char* disclaimer = "(Visual demo - not scannable)";
112 int disclaimerLen = 0;
113 while (disclaimer[disclaimerLen]) disclaimerLen++;
114 TextOut(hdc, rect.right / 2, startY + qrPixelSize + 40,
115 disclaimer, disclaimerLen);
116 } else {
117 // Default view - center in current window size
118 SetTextAlign(hdc, TA_CENTER);
119 SetBkMode(hdc, TRANSPARENT);
120 int centerY = rect.bottom / 2;
121 TextOut(hdc, rect.right / 2, centerY - 10, "Hello World!", 12);
122 TextOut(hdc, rect.right / 2, centerY + 10,
123 "Use Tools > Generate QR Pattern", 32);
124 }
125
126 EndPaint(hwnd, &ps);
127 return 0;
128 }
129
130 case WM_COMMAND:
131 switch (LOWORD(wParam)) {
132 case ID_ABOUT: {
133 const char* aboutText = "Hello World App\n\n"
134 "Version: 1.0.0\n"
135 "Built by: Kieran Klukas\n\n"
136 "A simple Win32 application\n"
137 "compatible with Windows XP\n\n"
138 "Features:\n"
139 "- QR Pattern Generation (visual demo)\n"
140 "- XP Compatible Design\n"
141 "- Pure Win32 API";
142 MessageBox(hwnd, aboutText, "About Hello World App",
143 MB_OK | MB_ICONINFORMATION);
144 break;
145 }
146 case ID_GENERATE_QR: {
147 // Simple input dialog using InputBox simulation
148 if (MessageBox(hwnd, "Generate QR code pattern for current text?\n\n(Note: This creates a visual QR-like pattern for demo purposes,\nnot a scannable QR code)\n\nClick OK to use default text,\nor Cancel to cycle through presets.",
149 "Generate QR Pattern", MB_OKCANCEL | MB_ICONQUESTION) == IDCANCEL) {
150
151 // For now, use a simple preset - in a real app you'd want a proper input dialog
152 const char* presets[] = {
153 "Hello World!",
154 "https://github.com/taciturnaxolotl/shortwave",
155 "Made with love by Kieran Klukas",
156 "Windows XP Forever!",
157 "QR codes are cool!"
158 };
159
160 static int presetIndex = 0;
161 const char* selectedText = presets[presetIndex % 5];
162 presetIndex++;
163
164 // Copy selected text to global buffer
165 int i = 0;
166 while (selectedText[i] && i < 255) {
167 g_qrText[i] = selectedText[i];
168 i++;
169 }
170 g_qrText[i] = '\0';
171 }
172
173 // Generate new QR code - no new/delete, just reinitialize
174 QRCode_Init(&g_qrCode, g_qrText);
175 g_hasQrCode = TRUE;
176
177 // Refresh the window
178 InvalidateRect(hwnd, NULL, TRUE);
179 break;
180 }
181 case ID_EXIT:
182 PostQuitMessage(0);
183 break;
184 }
185 return 0;
186 }
187
188 return DefWindowProc(hwnd, uMsg, wParam, lParam);
189}