- Merge from trunk up to r45543
[reactos.git] / base / applications / paint / main.c
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: base/applications/paint/main.c
5 * PURPOSE: Initializing everything
6 * PROGRAMMERS: Benedikt Freisen
7 */
8
9 /* INCLUDES *********************************************************/
10
11 #include <windows.h>
12 #include <windowsx.h>
13 #include <commctrl.h>
14 #include <stdio.h>
15 #include <tchar.h>
16 #include "definitions.h"
17
18 #include "drawing.h"
19 #include "dib.h"
20
21 #include "globalvar.h"
22 #include "history.h"
23 #include "mouse.h"
24
25 #include "winproc.h"
26 #include "palette.h"
27 #include "toolsettings.h"
28 #include "selection.h"
29 #include "sizebox.h"
30
31 /* FUNCTIONS ********************************************************/
32
33 HDC hDrawingDC;
34 HDC hSelDC;
35 int *bmAddress;
36 BITMAPINFO bitmapinfo;
37 int imgXRes = 400;
38 int imgYRes = 300;
39
40 HBITMAP hBms[HISTORYSIZE];
41 int currInd = 0;
42 int undoSteps = 0;
43 int redoSteps = 0;
44 BOOL imageSaved = TRUE;
45
46 short startX;
47 short startY;
48 short lastX;
49 short lastY;
50 int lineWidth = 1;
51 int shapeStyle = 0;
52 int brushStyle = 0;
53 int activeTool = 7;
54 int airBrushWidth = 5;
55 int rubberRadius = 4;
56 int transpBg = 0;
57 int zoom = 1000;
58 int rectSel_src[4];
59 int rectSel_dest[4];
60 HWND hSelection;
61 HWND hImageArea;
62 HBITMAP hSelBm;
63 HBITMAP hSelMask;
64
65 /* initial palette colors; may be changed by the user during execution */
66 int palColors[28] = { 0x000000, 0x464646, 0x787878, 0x300099, 0x241ced, 0x0078ff, 0x0ec2ff,
67 0x00f2ff, 0x1de6a8, 0x4cb122, 0xefb700, 0xf36d4d, 0x99362f, 0x98316f,
68 0xffffff, 0xdcdcdc, 0xb4b4b4, 0x3c5a9c, 0xb1a3ff, 0x7aaae5, 0x9ce4f5,
69 0xbdf9ff, 0xbcf9d3, 0x61bb9d, 0xead999, 0xd19a70, 0x8e6d54, 0xd5a5b5
70 };
71
72 /* foreground and background colors with initial value */
73 int fgColor = 0x00000000;
74 int bgColor = 0x00ffffff;
75
76 HWND hStatusBar;
77 HWND hScrollbox;
78 HWND hMainWnd;
79 HWND hPalWin;
80 HWND hToolBoxContainer;
81 HWND hToolSettings;
82 HWND hTrackbarZoom;
83 CHOOSECOLOR choosecolor;
84 OPENFILENAME ofn;
85 OPENFILENAME sfn;
86 HICON hNontranspIcon;
87 HICON hTranspIcon;
88
89 HCURSOR hCurFill;
90 HCURSOR hCurColor;
91 HCURSOR hCurZoom;
92 HCURSOR hCurPen;
93 HCURSOR hCurAirbrush;
94
95 HWND hScrlClient;
96
97 HWND hToolBtn[16];
98
99 HINSTANCE hProgInstance;
100
101 TCHAR filename[256];
102 TCHAR filepathname[1000];
103 BOOL isAFile = FALSE;
104 int fileSize;
105 int fileHPPM = 2834;
106 int fileVPPM = 2834;
107 SYSTEMTIME fileTime;
108
109 BOOL showGrid = FALSE;
110 BOOL showMiniature = FALSE;
111
112 HWND hwndMiniature;
113
114 HWND hSizeboxLeftTop;
115 HWND hSizeboxCenterTop;
116 HWND hSizeboxRightTop;
117 HWND hSizeboxLeftCenter;
118 HWND hSizeboxRightCenter;
119 HWND hSizeboxLeftBottom;
120 HWND hSizeboxCenterBottom;
121 HWND hSizeboxRightBottom;
122
123 /* entry point */
124
125 int WINAPI
126 _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR lpszArgument, int nFunsterStil)
127 {
128 HWND hwnd; /* This is the handle for our window */
129 MSG messages; /* Here messages to the application are saved */
130
131 WNDCLASSEX wclScroll;
132 WNDCLASSEX wincl;
133 WNDCLASSEX wclPal;
134 WNDCLASSEX wclSettings;
135 WNDCLASSEX wclSelection;
136
137 TCHAR progtitle[1000];
138 TCHAR resstr[100];
139 HMENU menu;
140 HWND hToolbar;
141 HIMAGELIST hImageList;
142 HANDLE haccel;
143 HBITMAP tempBm;
144 int i;
145 TCHAR tooltips[16][30];
146
147 TCHAR *c;
148 TCHAR sfnFilename[1000];
149 TCHAR sfnFiletitle[256];
150 TCHAR sfnFilter[1000];
151 TCHAR ofnFilename[1000];
152 TCHAR ofnFiletitle[256];
153 TCHAR ofnFilter[1000];
154 TCHAR miniaturetitle[100];
155 int custColors[16] = { 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff,
156 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff, 0xffffff
157 };
158
159 hProgInstance = hThisInstance;
160
161 /* Necessary */
162 InitCommonControls();
163
164 /* initializing and registering the window class used for the main window */
165 wincl.hInstance = hThisInstance;
166 wincl.lpszClassName = _T("WindowsApp");
167 wincl.lpfnWndProc = WindowProcedure;
168 wincl.style = CS_DBLCLKS;
169 wincl.cbSize = sizeof(WNDCLASSEX);
170 wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
171 wincl.hIconSm = LoadIcon(hThisInstance, MAKEINTRESOURCE(500));
172 wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
173 wincl.lpszMenuName = NULL;
174 wincl.cbClsExtra = 0;
175 wincl.cbWndExtra = 0;
176 wincl.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
177 RegisterClassEx (&wincl);
178
179 /* initializing and registering the window class used for the scroll box */
180 wclScroll.hInstance = hThisInstance;
181 wclScroll.lpszClassName = _T("Scrollbox");
182 wclScroll.lpfnWndProc = WindowProcedure;
183 wclScroll.style = 0;
184 wclScroll.cbSize = sizeof(WNDCLASSEX);
185 wclScroll.hIcon = NULL;
186 wclScroll.hIconSm = NULL;
187 wclScroll.hCursor = LoadCursor(NULL, IDC_ARROW);
188 wclScroll.lpszMenuName = NULL;
189 wclScroll.cbClsExtra = 0;
190 wclScroll.cbWndExtra = 0;
191 wclScroll.hbrBackground = GetSysColorBrush(COLOR_APPWORKSPACE);
192 RegisterClassEx (&wclScroll);
193
194 /* initializing and registering the window class used for the palette window */
195 wclPal.hInstance = hThisInstance;
196 wclPal.lpszClassName = _T("Palette");
197 wclPal.lpfnWndProc = PalWinProc;
198 wclPal.style = CS_DBLCLKS;
199 wclPal.cbSize = sizeof(WNDCLASSEX);
200 wclPal.hIcon = NULL;
201 wclPal.hIconSm = NULL;
202 wclPal.hCursor = LoadCursor(NULL, IDC_ARROW);
203 wclPal.lpszMenuName = NULL;
204 wclPal.cbClsExtra = 0;
205 wclPal.cbWndExtra = 0;
206 wclPal.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
207 RegisterClassEx (&wclPal);
208
209 /* initializing and registering the window class for the settings window */
210 wclSettings.hInstance = hThisInstance;
211 wclSettings.lpszClassName = _T("ToolSettings");
212 wclSettings.lpfnWndProc = SettingsWinProc;
213 wclSettings.style = CS_DBLCLKS;
214 wclSettings.cbSize = sizeof(WNDCLASSEX);
215 wclSettings.hIcon = NULL;
216 wclSettings.hIconSm = NULL;
217 wclSettings.hCursor = LoadCursor(NULL, IDC_ARROW);
218 wclSettings.lpszMenuName = NULL;
219 wclSettings.cbClsExtra = 0;
220 wclSettings.cbWndExtra = 0;
221 wclSettings.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
222 RegisterClassEx (&wclSettings);
223
224 /* initializing and registering the window class for the selection frame */
225 wclSelection.hInstance = hThisInstance;
226 wclSelection.lpszClassName = _T("Selection");
227 wclSelection.lpfnWndProc = SelectionWinProc;
228 wclSelection.style = CS_DBLCLKS;
229 wclSelection.cbSize = sizeof(WNDCLASSEX);
230 wclSelection.hIcon = NULL;
231 wclSelection.hIconSm = NULL;
232 wclSelection.hCursor = LoadCursor(NULL, IDC_SIZEALL);
233 wclSelection.lpszMenuName = NULL;
234 wclSelection.cbClsExtra = 0;
235 wclSelection.cbWndExtra = 0;
236 wclSelection.hbrBackground = NULL;
237 RegisterClassEx (&wclSelection);
238
239 /* initializing and registering the window class for the size boxes */
240 wclSettings.hInstance = hThisInstance;
241 wclSettings.lpszClassName = _T("Sizebox");
242 wclSettings.lpfnWndProc = SizeboxWinProc;
243 wclSettings.style = CS_DBLCLKS;
244 wclSettings.cbSize = sizeof(WNDCLASSEX);
245 wclSettings.hIcon = NULL;
246 wclSettings.hIconSm = NULL;
247 wclSettings.hCursor = LoadCursor(NULL, IDC_ARROW);
248 wclSettings.lpszMenuName = NULL;
249 wclSettings.cbClsExtra = 0;
250 wclSettings.cbWndExtra = 0;
251 wclSettings.hbrBackground = GetSysColorBrush(COLOR_HIGHLIGHT);
252 RegisterClassEx (&wclSettings);
253
254 LoadString(hThisInstance, IDS_DEFAULTFILENAME, filename, SIZEOF(filename));
255 LoadString(hThisInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
256 _stprintf(progtitle, resstr, filename);
257 LoadString(hThisInstance, IDS_MINIATURETITLE, miniaturetitle, SIZEOF(miniaturetitle));
258
259 /* create main window */
260 hwnd =
261 CreateWindowEx(0, _T("WindowsApp"), progtitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 544,
262 375, HWND_DESKTOP, NULL, hThisInstance, NULL);
263 hMainWnd = hwnd;
264
265 hwndMiniature =
266 CreateWindowEx(WS_EX_PALETTEWINDOW, _T("WindowsApp"), miniaturetitle,
267 WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME, 180, 200, 120, 100, hwnd,
268 NULL, hThisInstance, NULL);
269
270 /* loading and setting the window menu from resource */
271 menu = LoadMenu(hThisInstance, MAKEINTRESOURCE(ID_MENU));
272 SetMenu(hwnd, menu);
273 haccel = LoadAccelerators(hThisInstance, MAKEINTRESOURCE(800));
274
275 /* preloading the draw transparent/nontransparent icons for later use */
276 hNontranspIcon =
277 LoadImage(hThisInstance, MAKEINTRESOURCE(IDI_NONTRANSPARENT), IMAGE_ICON, 40, 30, LR_DEFAULTCOLOR);
278 hTranspIcon =
279 LoadImage(hThisInstance, MAKEINTRESOURCE(IDI_TRANSPARENT), IMAGE_ICON, 40, 30, LR_DEFAULTCOLOR);
280
281 hCurFill = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_FILL));
282 hCurColor = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_COLOR));
283 hCurZoom = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_ZOOM));
284 hCurPen = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_PEN));
285 hCurAirbrush = LoadIcon(hThisInstance, MAKEINTRESOURCE(IDC_AIRBRUSH));
286
287 CreateWindowEx(0, _T("STATIC"), _T(""), WS_CHILD | WS_VISIBLE | SS_ETCHEDHORZ, 0, 0, 5000, 2, hwnd, NULL,
288 hThisInstance, NULL);
289
290 hToolBoxContainer =
291 CreateWindowEx(0, _T("WindowsApp"), _T(""), WS_CHILD | WS_VISIBLE, 2, 2, 52, 350, hwnd, NULL,
292 hThisInstance, NULL);
293 /* creating the 16 bitmap radio buttons and setting the bitmap */
294
295
296 /*
297 * FIXME: Unintentionally there is a line above the tool bar.
298 * To prevent cropping of the buttons height has been increased from 200 to 205
299 */
300 hToolbar =
301 CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
302 WS_CHILD | WS_VISIBLE | CCS_NOPARENTALIGN | CCS_VERT | CCS_NORESIZE | TBSTYLE_TOOLTIPS,
303 1, 1, 50, 205, hToolBoxContainer, NULL, hThisInstance, NULL);
304 hImageList = ImageList_Create(16, 16, ILC_COLOR24 | ILC_MASK, 16, 0);
305 SendMessage(hToolbar, TB_SETIMAGELIST, 0, (LPARAM) hImageList);
306 tempBm = LoadImage(hThisInstance, MAKEINTRESOURCE(IDB_TOOLBARICONS), IMAGE_BITMAP, 256, 16, 0);
307 ImageList_AddMasked(hImageList, tempBm, 0xff00ff);
308 DeleteObject(tempBm);
309 SendMessage(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
310
311 for(i = 0; i < 16; i++)
312 {
313 TBBUTTON tbbutton;
314 int wrapnow = 0;
315
316 if (i % 2 == 1)
317 wrapnow = TBSTATE_WRAP;
318
319 LoadString(hThisInstance, IDS_TOOLTIP1 + i, tooltips[i], 30);
320 ZeroMemory(&tbbutton, sizeof(TBBUTTON));
321 tbbutton.iString = (INT_PTR) tooltips[i];
322 tbbutton.fsStyle = TBSTYLE_CHECKGROUP;
323 tbbutton.fsState = TBSTATE_ENABLED | wrapnow;
324 tbbutton.idCommand = ID_FREESEL + i;
325 tbbutton.iBitmap = i;
326 SendMessage(hToolbar, TB_ADDBUTTONS, 1, (LPARAM) &tbbutton);
327 }
328
329 SendMessage(hToolbar, TB_CHECKBUTTON, ID_PEN, MAKELONG(TRUE, 0));
330 SendMessage(hToolbar, TB_SETMAXTEXTROWS, 0, 0);
331 SendMessage(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(25, 25));
332
333 /* creating the tool settings child window */
334 hToolSettings =
335 CreateWindowEx(0, _T("ToolSettings"), _T(""), WS_CHILD | WS_VISIBLE, 5, 208, 42, 140,
336 hToolBoxContainer, NULL, hThisInstance, NULL);
337 hTrackbarZoom =
338 CreateWindowEx(0, TRACKBAR_CLASS, _T(""), WS_CHILD | TBS_VERT | TBS_AUTOTICKS, 1, 1, 40, 64,
339 hToolSettings, NULL, hThisInstance, NULL);
340 SendMessage(hTrackbarZoom, TBM_SETRANGE, (WPARAM) TRUE, (LPARAM) MAKELONG(0, 6));
341 SendMessage(hTrackbarZoom, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) 3);
342
343 /* creating the palette child window */
344 hPalWin =
345 CreateWindowEx(0, _T("Palette"), _T(""), WS_CHILD | WS_VISIBLE, 56, 9, 255, 32, hwnd, NULL,
346 hThisInstance, NULL);
347
348 /* creating the scroll box */
349 hScrollbox =
350 CreateWindowEx(WS_EX_CLIENTEDGE, _T("Scrollbox"), _T(""),
351 WS_CHILD | WS_GROUP | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE, 56, 49, 472, 248, hwnd,
352 NULL, hThisInstance, NULL);
353
354 /* creating the status bar */
355 hStatusBar =
356 CreateWindowEx(0, STATUSCLASSNAME, _T(""), SBARS_SIZEGRIP | WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, hwnd,
357 NULL, hThisInstance, NULL);
358 SendMessage(hStatusBar, SB_SETMINHEIGHT, 21, 0);
359
360 hScrlClient =
361 CreateWindowEx(0, _T("Scrollbox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 500, 500, hScrollbox, NULL,
362 hThisInstance, NULL);
363
364 /* create selection window (initially hidden) */
365 hSelection =
366 CreateWindowEx(WS_EX_TRANSPARENT, _T("Selection"), _T(""), WS_CHILD | BS_OWNERDRAW, 350, 0, 100, 100,
367 hScrlClient, NULL, hThisInstance, NULL);
368
369 /* creating the window inside the scroll box, on which the image in hDrawingDC's bitmap is drawn */
370 hImageArea =
371 CreateWindowEx(0, _T("Scrollbox"), _T(""), WS_CHILD | WS_VISIBLE, 3, 3, imgXRes, imgYRes, hScrlClient,
372 NULL, hThisInstance, NULL);
373
374 hDrawingDC = CreateCompatibleDC(GetDC(hImageArea));
375 hSelDC = CreateCompatibleDC(GetDC(hImageArea));
376 SelectObject(hDrawingDC, CreatePen(PS_SOLID, 0, fgColor));
377 SelectObject(hDrawingDC, CreateSolidBrush(bgColor));
378
379 hBms[0] = CreateDIBWithProperties(imgXRes, imgYRes);
380 SelectObject(hDrawingDC, hBms[0]);
381 Rectangle(hDrawingDC, 0 - 1, 0 - 1, imgXRes + 1, imgYRes + 1);
382
383 if (lpszArgument[0] != 0)
384 {
385 HBITMAP bmNew = NULL;
386 LoadDIBFromFile(&bmNew, lpszArgument, &fileTime, &fileSize, &fileHPPM, &fileVPPM);
387 if (bmNew != NULL)
388 {
389 TCHAR tempstr[1000];
390 TCHAR resstr[100];
391 TCHAR *temp;
392 insertReversible(bmNew);
393 GetFullPathName(lpszArgument, SIZEOF(filepathname), filepathname, &temp);
394 _tcscpy(filename, temp);
395 LoadString(hProgInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
396 _stprintf(tempstr, resstr, filename);
397 SetWindowText(hMainWnd, tempstr);
398 clearHistory();
399 isAFile = TRUE;
400 }
401 }
402
403 /* initializing the CHOOSECOLOR structure for use with ChooseColor */
404 choosecolor.lStructSize = sizeof(CHOOSECOLOR);
405 choosecolor.hwndOwner = hwnd;
406 choosecolor.hInstance = NULL;
407 choosecolor.rgbResult = 0x00ffffff;
408 choosecolor.lpCustColors = (COLORREF*) &custColors;
409 choosecolor.Flags = 0;
410 choosecolor.lCustData = 0;
411 choosecolor.lpfnHook = NULL;
412 choosecolor.lpTemplateName = NULL;
413
414 /* initializing the OPENFILENAME structure for use with GetOpenFileName and GetSaveFileName */
415 CopyMemory(ofnFilename, filename, sizeof(filename));
416 LoadString(hThisInstance, IDS_OPENFILTER, ofnFilter, SIZEOF(ofnFilter));
417 for(c = ofnFilter; *c; c++)
418 if (*c == '\1')
419 *c = '\0';
420 ZeroMemory(&ofn, sizeof(OPENFILENAME));
421 ofn.lStructSize = sizeof(OPENFILENAME);
422 ofn.hwndOwner = hwnd;
423 ofn.hInstance = hThisInstance;
424 ofn.lpstrFilter = ofnFilter;
425 ofn.lpstrFile = ofnFilename;
426 ofn.nMaxFile = SIZEOF(ofnFilename);
427 ofn.lpstrFileTitle = ofnFiletitle;
428 ofn.nMaxFileTitle = SIZEOF(ofnFiletitle);
429 ofn.Flags = OFN_HIDEREADONLY;
430
431 CopyMemory(sfnFilename, filename, sizeof(filename));
432 LoadString(hThisInstance, IDS_SAVEFILTER, sfnFilter, SIZEOF(sfnFilter));
433 for(c = sfnFilter; *c; c++)
434 if (*c == '\1')
435 *c = '\0';
436 ZeroMemory(&sfn, sizeof(OPENFILENAME));
437 sfn.lStructSize = sizeof(OPENFILENAME);
438 sfn.hwndOwner = hwnd;
439 sfn.hInstance = hThisInstance;
440 sfn.lpstrFilter = sfnFilter;
441 sfn.lpstrFile = sfnFilename;
442 sfn.nMaxFile = SIZEOF(sfnFilename);
443 sfn.lpstrFileTitle = sfnFiletitle;
444 sfn.nMaxFileTitle = SIZEOF(sfnFiletitle);
445 sfn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
446
447 /* creating the size boxes */
448 hSizeboxLeftTop =
449 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
450 hThisInstance, NULL);
451 hSizeboxCenterTop =
452 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
453 hThisInstance, NULL);
454 hSizeboxRightTop =
455 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
456 hThisInstance, NULL);
457 hSizeboxLeftCenter =
458 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
459 hThisInstance, NULL);
460 hSizeboxRightCenter =
461 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
462 hThisInstance, NULL);
463 hSizeboxLeftBottom =
464 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
465 hThisInstance, NULL);
466 hSizeboxCenterBottom =
467 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
468 hThisInstance, NULL);
469 hSizeboxRightBottom =
470 CreateWindowEx(0, _T("Sizebox"), _T(""), WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL,
471 hThisInstance, NULL);
472 /* placing the size boxes around the image */
473 SendMessage(hImageArea, WM_SIZE, 0, 0);
474
475 /* by moving the window, the things in WM_SIZE are done */
476 MoveWindow(hwnd, 100, 100, 600, 450, TRUE);
477
478 /* Make the window visible on the screen */
479 ShowWindow (hwnd, nFunsterStil);
480
481 /* Run the message loop. It will run until GetMessage() returns 0 */
482 while (GetMessage(&messages, NULL, 0, 0))
483 {
484 TranslateAccelerator(hwnd, haccel, &messages);
485
486 /* Translate virtual-key messages into character messages */
487 TranslateMessage(&messages);
488 /* Send message to WindowProcedure */
489 DispatchMessage(&messages);
490 }
491
492 /* The program return-value is 0 - The value that PostQuitMessage() gave */
493 return messages.wParam;
494 }