tools: Fix mkinstalldirs.
[wine] / programs / wordpad / wordpad.c
1 /*
2  * Wordpad implementation
3  *
4  * Copyright 2004 by Krzysztof Foltman
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #define WIN32_LEAN_AND_MEAN
22 #define _WIN32_IE 0x0400
23
24 #include <stdarg.h>
25 #include <ctype.h>
26 #include <stdio.h>
27 #include <assert.h>
28
29 #include <windows.h>
30 #include <richedit.h>
31 #include <commctrl.h>
32
33 #include "resource.h"
34
35
36 /* use LoadString */
37 static const WCHAR xszAppTitle[] = {'W','i','n','e',' ','W','o','r','d','p','a','d',0};
38 static const WCHAR xszMainMenu[] = {'M','A','I','N','M','E','N','U',0};
39
40 static const WCHAR wszRichEditClass[] = {'R','I','C','H','E','D','I','T','2','0','W',0};
41 static const WCHAR wszMainWndClass[] = {'W','O','R','D','P','A','D','T','O','P',0};
42 static const WCHAR wszAppTitle[] = {'W','i','n','e',' ','W','o','r','d','p','a','d',0};
43
44 static HWND hMainWnd = NULL;
45
46 static void AddButton(HWND hwndToolBar, int nImage, int nCommand)
47 {
48     TBBUTTON button;
49
50     ZeroMemory(&button, sizeof(button));
51     button.iBitmap = nImage;
52     button.idCommand = nCommand;
53     button.fsState = TBSTATE_ENABLED;
54     button.fsStyle = TBSTYLE_BUTTON;
55     button.dwData = 0;
56     button.iString = -1;
57     SendMessage(hwndToolBar, TB_ADDBUTTONS, 1, (LPARAM)&button);
58 }
59
60 static void AddSeparator(HWND hwndToolBar)
61 {
62     TBBUTTON button;
63
64     ZeroMemory(&button, sizeof(button));
65     button.iBitmap = -1;
66     button.idCommand = 0;
67     button.fsState = 0;
68     button.fsStyle = TBSTYLE_SEP;
69     button.dwData = 0;
70     button.iString = -1;
71     SendMessage(hwndToolBar, TB_ADDBUTTONS, 1, (LPARAM)&button);
72 }
73
74 static LRESULT OnCreate( HWND hWnd, WPARAM wParam, LPARAM lParam)
75 {
76     HWND hEditorWnd, hToolBarWnd, hReBarWnd;
77     HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE);
78     HANDLE hDLL;
79     TBADDBITMAP ab;
80     int nStdBitmaps = 0;
81     REBARINFO rbi;
82     REBARBANDINFO rbb;
83
84     CreateStatusWindow(CCS_NODIVIDER|WS_CHILD|WS_VISIBLE, "RichEdit text", hWnd, IDC_STATUSBAR);
85
86     hReBarWnd = CreateWindowEx(WS_EX_TOOLWINDOW, REBARCLASSNAME, NULL,
87       CCS_NODIVIDER|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|RBS_VARHEIGHT|CCS_TOP,
88       CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hWnd, (HMENU)IDC_REBAR, hInstance, NULL);
89
90     rbi.cbSize = sizeof(rbi);
91     rbi.fMask = 0;
92     rbi.himl = NULL;
93     if(!SendMessage(hReBarWnd, RB_SETBARINFO, 0, (LPARAM)&rbi))
94         return -1;
95
96     hToolBarWnd = CreateToolbarEx(hReBarWnd, CCS_NOPARENTALIGN|CCS_NODIVIDER|CCS_NOMOVEY|WS_VISIBLE|WS_CHILD|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT,
97       IDC_TOOLBAR,
98       3, hInstance, IDB_TOOLBAR,
99       NULL, 0,
100       24, 24, 16, 16, sizeof(TBBUTTON));
101
102     ab.hInst = HINST_COMMCTRL;
103     ab.nID = IDB_STD_SMALL_COLOR;
104     nStdBitmaps = SendMessage(hToolBarWnd, TB_ADDBITMAP, 3, (LPARAM)&ab);
105     AddButton(hToolBarWnd, nStdBitmaps+STD_FILENEW, ID_FILE_NEW);
106     AddButton(hToolBarWnd, nStdBitmaps+STD_FILEOPEN, ID_FILE_OPEN);
107     AddButton(hToolBarWnd, nStdBitmaps+STD_FILESAVE, ID_FILE_SAVE);
108     AddSeparator(hToolBarWnd);
109     AddButton(hToolBarWnd, nStdBitmaps+STD_CUT, ID_EDIT_CUT);
110     AddButton(hToolBarWnd, nStdBitmaps+STD_COPY, ID_EDIT_COPY);
111     AddSeparator(hToolBarWnd);
112     AddButton(hToolBarWnd, nStdBitmaps+STD_UNDO, ID_EDIT_UNDO);
113     AddButton(hToolBarWnd, nStdBitmaps+STD_REDOW, ID_EDIT_REDO);
114     AddSeparator(hToolBarWnd);
115     AddButton(hToolBarWnd, 0, ID_FORMAT_BOLD);
116     AddButton(hToolBarWnd, 1, ID_FORMAT_ITALIC);
117     AddButton(hToolBarWnd, 2, ID_FORMAT_UNDERLINE);
118
119     SendMessage(hToolBarWnd, TB_ADDSTRING, 0, (LPARAM)"Exit\0");
120     SendMessage(hToolBarWnd, TB_AUTOSIZE, 0, 0);
121
122     rbb.cbSize = sizeof(rbb);
123     rbb.fMask = RBBIM_SIZE | RBBIM_CHILDSIZE | RBBIM_CHILD | RBBIM_STYLE;
124     rbb.fStyle = RBBS_CHILDEDGE;
125     rbb.cx = 500;
126     rbb.hwndChild = hToolBarWnd;
127     rbb.cxMinChild = 0;
128     rbb.cyChild = rbb.cyMinChild = HIWORD(SendMessage(hToolBarWnd, TB_GETBUTTONSIZE, 0, 0));
129
130     SendMessage(hReBarWnd, RB_INSERTBAND, -1, (LPARAM)&rbb);
131
132     hDLL = LoadLibrary("RICHED20.DLL");
133     assert(hDLL);
134
135     hEditorWnd = CreateWindowExW(WS_EX_CLIENTEDGE, wszRichEditClass, NULL,
136       WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOVSCROLL|ES_WANTRETURN,
137       0, 0, 1000, 100, hWnd, (HMENU)IDC_EDITOR, hInstance, NULL);
138     if (!hEditorWnd)
139     {
140         fprintf(stderr, "Error code %lu\n", GetLastError());
141         return -1;
142     }
143     assert(hEditorWnd);
144
145     SetFocus(hEditorWnd);
146     SendMessage(hEditorWnd, EM_SETEVENTMASK, 0, ENM_SELCHANGE);
147     return 0;
148 }
149
150 static LRESULT OnUser( HWND hWnd, WPARAM wParam, LPARAM lParam)
151 {
152     HWND hwndEditor = GetDlgItem(hWnd, IDC_EDITOR);
153     HWND hwndReBar = GetDlgItem(hWnd, IDC_REBAR);
154     HWND hwndToolBar = GetDlgItem(hwndReBar, IDC_TOOLBAR);
155     int from, to;
156     CHARFORMAT2W fmt;
157
158     ZeroMemory(&fmt, sizeof(fmt));
159     fmt.cbSize = sizeof(fmt);
160
161     SendMessage(hwndEditor, EM_GETCHARFORMAT, TRUE, (LPARAM)&fmt);
162
163     SendMessage(hwndEditor, EM_GETSEL, (WPARAM)&from, (LPARAM)&to);
164     SendMessage(hwndToolBar, TB_ENABLEBUTTON, ID_EDIT_UNDO,
165       SendMessage(hwndEditor, EM_CANUNDO, 0, 0));
166     SendMessage(hwndToolBar, TB_ENABLEBUTTON, ID_EDIT_REDO,
167       SendMessage(hwndEditor, EM_CANREDO, 0, 0));
168     SendMessage(hwndToolBar, TB_ENABLEBUTTON, ID_EDIT_CUT, from == to ? 0 : 1);
169     SendMessage(hwndToolBar, TB_ENABLEBUTTON, ID_EDIT_COPY, from == to ? 0 : 1);
170     SendMessage(hwndToolBar, TB_CHECKBUTTON, ID_FORMAT_BOLD, (fmt.dwMask & CFM_BOLD) && (fmt.dwEffects & CFE_BOLD));
171     SendMessage(hwndToolBar, TB_INDETERMINATE, ID_FORMAT_BOLD, !(fmt.dwMask & CFM_BOLD));
172     SendMessage(hwndToolBar, TB_CHECKBUTTON, ID_FORMAT_ITALIC, (fmt.dwMask & CFM_ITALIC) && (fmt.dwEffects & CFE_ITALIC));
173     SendMessage(hwndToolBar, TB_INDETERMINATE, ID_FORMAT_ITALIC, !(fmt.dwMask & CFM_ITALIC));
174     SendMessage(hwndToolBar, TB_CHECKBUTTON, ID_FORMAT_UNDERLINE, (fmt.dwMask & CFM_UNDERLINE) && (fmt.dwEffects & CFE_UNDERLINE));
175     SendMessage(hwndToolBar, TB_INDETERMINATE, ID_FORMAT_UNDERLINE, !(fmt.dwMask & CFM_UNDERLINE));
176     return 0;
177 }
178
179 static LRESULT OnNotify( HWND hWnd, WPARAM wParam, LPARAM lParam)
180 {
181     HWND hwndEditor = GetDlgItem(hWnd, IDC_EDITOR);
182     NMHDR *pHdr = (NMHDR *)lParam;
183
184     if (pHdr->hwndFrom != hwndEditor)
185         return 0;
186
187     if (pHdr->code == EN_SELCHANGE)
188     {
189         SELCHANGE *pSC = (SELCHANGE *)lParam;
190         char buf[128];
191
192         sprintf( buf,"selection = %ld..%ld, line count=%ld\n",
193                  pSC->chrg.cpMin, pSC->chrg.cpMax,
194         SendMessage(hwndEditor, EM_GETLINECOUNT, 0, 0));
195         SetWindowText(GetDlgItem(hWnd, IDC_STATUSBAR), buf);
196         SendMessage(hWnd, WM_USER, 0, 0);
197         return 1;
198     }
199     return 0;
200 }
201
202 static LRESULT OnCommand( HWND hWnd, WPARAM wParam, LPARAM lParam)
203 {
204     HWND hwndEditor = GetDlgItem(hWnd, IDC_EDITOR);
205
206     if ((HWND)lParam == hwndEditor)
207         return 0;
208
209     switch(LOWORD(wParam))
210     {
211     case ID_FILE_EXIT:
212         PostMessage(hWnd, WM_CLOSE, 0, 0);
213         break;
214
215     case ID_FILE_NEW:
216         SetWindowTextA(hwndEditor, "");
217         /* FIXME: set default format too */
218         break;
219
220     case ID_FILE_OPEN:
221     case ID_FILE_SAVE:
222         MessageBox(hWnd, "Open/Save not implemented", "WordPad", MB_OK);
223         break;
224
225     case ID_FORMAT_BOLD:
226     case ID_FORMAT_ITALIC:
227     case ID_FORMAT_UNDERLINE:
228         {
229         CHARFORMAT2W fmt;
230         int mask = CFM_BOLD;
231         if (LOWORD(wParam) == ID_FORMAT_ITALIC) mask = CFM_ITALIC;
232         if (LOWORD(wParam) == ID_FORMAT_UNDERLINE) mask = CFM_UNDERLINE;
233
234         ZeroMemory(&fmt, sizeof(fmt));
235         fmt.cbSize = sizeof(fmt);
236         SendMessage(hwndEditor, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
237         if (!(fmt.dwMask&mask))
238             fmt.dwEffects |= mask;
239         else
240             fmt.dwEffects ^= mask;
241         fmt.dwMask = mask;
242         SendMessage(hwndEditor, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
243         break;
244         }
245
246     case ID_EDIT_CUT:
247         PostMessage(hwndEditor, WM_CUT, 0, 0);
248         break;
249
250     case ID_EDIT_COPY:
251         PostMessage(hwndEditor, WM_COPY, 0, 0);
252         break;
253
254     case ID_EDIT_SELECTALL:
255         {
256         CHARRANGE range = {0, -1};
257         SendMessage(hwndEditor, EM_EXSETSEL, 0, (LPARAM)&range);
258         /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
259         return 0;
260         }
261
262     case ID_EDIT_GETTEXT:
263         {
264         int nLen = GetWindowTextLengthW(hwndEditor);
265         LPWSTR data = HeapAlloc( GetProcessHeap(), 0, (nLen+1)*sizeof(WCHAR) );
266         TEXTRANGEW tr;
267
268         GetWindowTextW(hwndEditor, data, nLen+1);
269         MessageBoxW(NULL, data, xszAppTitle, MB_OK);
270
271         HeapFree( GetProcessHeap(), 0, data);
272         data = HeapAlloc(GetProcessHeap(), 0, (nLen+1)*sizeof(WCHAR));
273         tr.chrg.cpMin = 0;
274         tr.chrg.cpMax = nLen;
275         tr.lpstrText = data;
276         SendMessage (hwndEditor, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
277         MessageBoxW(NULL, data, xszAppTitle, MB_OK);
278         HeapFree( GetProcessHeap(), 0, data );
279
280         /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
281         return 0;
282         }
283
284     case ID_EDIT_CHARFORMAT:
285     case ID_EDIT_DEFCHARFORMAT:
286         {
287         CHARFORMAT2W cf;
288         LRESULT i;
289         ZeroMemory(&cf, sizeof(cf));
290         cf.cbSize = sizeof(cf);
291         cf.dwMask = 0;
292         i = SendMessage(hwndEditor, EM_GETCHARFORMAT,
293                         LOWORD(wParam) == ID_EDIT_CHARFORMAT, (LPARAM)&cf);
294         return 0;
295         }
296
297     case ID_EDIT_PARAFORMAT:
298         {
299         PARAFORMAT2 pf;
300         ZeroMemory(&pf, sizeof(pf));
301         pf.cbSize = sizeof(pf);
302         SendMessage(hwndEditor, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
303         return 0;
304         }
305
306     case ID_EDIT_SELECTIONINFO:
307         {
308         CHARRANGE range = {0, -1};
309         char buf[128];
310         WCHAR *data = NULL;
311
312         SendMessage(hwndEditor, EM_EXGETSEL, 0, (LPARAM)&range);
313         data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data) * (range.cpMax-range.cpMin+1));
314         SendMessage(hwndEditor, EM_GETSELTEXT, 0, (LPARAM)data);
315         sprintf(buf, "Start = %ld, End = %ld", range.cpMin, range.cpMax);
316         MessageBoxA(hWnd, buf, "Editor", MB_OK);
317         MessageBoxW(hWnd, data, xszAppTitle, MB_OK);
318         HeapFree( GetProcessHeap(), 0, data);
319         /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
320         return 0;
321         }
322
323     case ID_EDIT_READONLY:
324         {
325         long nStyle = GetWindowLong(hwndEditor, GWL_STYLE);
326         if (nStyle & ES_READONLY)
327             SendMessage(hwndEditor, EM_SETREADONLY, 0, 0);
328         else
329             SendMessage(hwndEditor, EM_SETREADONLY, 1, 0);
330         return 0;
331         }
332
333     case ID_EDIT_MODIFIED:
334         if (SendMessage(hwndEditor, EM_GETMODIFY, 0, 0))
335             SendMessage(hwndEditor, EM_SETMODIFY, 0, 0);
336         else
337             SendMessage(hwndEditor, EM_SETMODIFY, 1, 0);
338         return 0;
339
340     case ID_EDIT_UNDO:
341         SendMessage(hwndEditor, EM_UNDO, 0, 0);
342         return 0;
343
344     case ID_EDIT_REDO:
345         SendMessage(hwndEditor, EM_REDO, 0, 0);
346         return 0;
347
348     case ID_ALIGN_LEFT:
349     case ID_ALIGN_CENTER:
350     case ID_ALIGN_RIGHT:
351         {
352         PARAFORMAT2 pf;
353
354         pf.cbSize = sizeof(pf);
355         pf.dwMask = PFM_ALIGNMENT;
356         switch(LOWORD(wParam)) {
357         case ID_ALIGN_LEFT: pf.wAlignment = PFA_LEFT; break;
358         case ID_ALIGN_CENTER: pf.wAlignment = PFA_CENTER; break;
359         case ID_ALIGN_RIGHT: pf.wAlignment = PFA_RIGHT; break;
360         }
361         SendMessage(hwndEditor, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
362         break;
363         }
364
365     case ID_BACK_1:
366         SendMessage(hwndEditor, EM_SETBKGNDCOLOR, 1, 0);
367         break;
368
369     case ID_BACK_2:
370         SendMessage(hwndEditor, EM_SETBKGNDCOLOR, 0, RGB(255,255,192));
371         break;
372
373     default:
374         SendMessage(hwndEditor, WM_COMMAND, wParam, lParam);
375         break;
376     }
377     return 0;
378 }
379
380 static LRESULT OnInitPopupMenu( HWND hWnd, WPARAM wParam, LPARAM lParam )
381 {
382     HMENU hMenu = (HMENU)wParam;
383     HWND hwndEditor = GetDlgItem(hWnd, IDC_EDITOR);
384     PARAFORMAT pf;
385     int nAlignment = -1;
386
387     pf.cbSize = sizeof(PARAFORMAT);
388     SendMessage(hwndEditor, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
389     CheckMenuItem(hMenu, ID_EDIT_READONLY,
390       MF_BYCOMMAND|(GetWindowLong(hwndEditor, GWL_STYLE)&ES_READONLY ? MF_CHECKED : MF_UNCHECKED));
391     CheckMenuItem(hMenu, ID_EDIT_MODIFIED,
392       MF_BYCOMMAND|(SendMessage(hwndEditor, EM_GETMODIFY, 0, 0) ? MF_CHECKED : MF_UNCHECKED));
393     if (pf.dwMask & PFM_ALIGNMENT)
394         nAlignment = pf.wAlignment;
395     CheckMenuItem(hMenu, ID_ALIGN_LEFT, MF_BYCOMMAND|(nAlignment == PFA_LEFT) ? MF_CHECKED : MF_UNCHECKED);
396     CheckMenuItem(hMenu, ID_ALIGN_CENTER, MF_BYCOMMAND|(nAlignment == PFA_CENTER) ? MF_CHECKED : MF_UNCHECKED);
397     CheckMenuItem(hMenu, ID_ALIGN_RIGHT, MF_BYCOMMAND|(nAlignment == PFA_RIGHT) ? MF_CHECKED : MF_UNCHECKED);
398     EnableMenuItem(hMenu, ID_EDIT_UNDO, MF_BYCOMMAND|(SendMessage(hwndEditor, EM_CANUNDO, 0, 0)) ? MF_ENABLED : MF_GRAYED);
399     EnableMenuItem(hMenu, ID_EDIT_REDO, MF_BYCOMMAND|(SendMessage(hwndEditor, EM_CANREDO, 0, 0)) ? MF_ENABLED : MF_GRAYED);
400     return 0;
401 }
402
403 static LRESULT OnSize( HWND hWnd, WPARAM wParam, LPARAM lParam )
404 {
405     int nStatusSize = 0, nTBSize = 0;
406     RECT rc;
407     HWND hwndEditor = GetDlgItem(hWnd, IDC_EDITOR);
408     HWND hwndStatusBar = GetDlgItem(hWnd, IDC_STATUSBAR);
409     HWND hwndReBar = GetDlgItem(hWnd, IDC_REBAR);
410     HWND hwndToolBar = GetDlgItem(hwndReBar, IDC_TOOLBAR);
411
412     if (hwndStatusBar)
413     {
414         SendMessage(hwndStatusBar, WM_SIZE, 0, 0);
415         GetClientRect(hwndStatusBar, &rc);
416         nStatusSize = rc.bottom - rc.top;
417     }
418     if (hwndToolBar)
419     {
420         rc.left = rc.top = 0;
421         rc.right = LOWORD(lParam);
422         rc.bottom = HIWORD(lParam);
423         SendMessage(hwndToolBar, TB_AUTOSIZE, 0, 0);
424         SendMessage(hwndReBar, RB_SIZETORECT, 0, (LPARAM)&rc);
425         nTBSize = SendMessage(hwndReBar, RB_GETBARHEIGHT, 0, 0);
426         GetClientRect(hwndReBar, &rc);
427         MoveWindow(hwndReBar, 0, 0, LOWORD(lParam), rc.right, FALSE);
428     }
429     if (hwndEditor)
430     {
431         GetClientRect(hWnd, &rc);
432         MoveWindow(hwndEditor, 0, nTBSize, rc.right, rc.bottom-nStatusSize-nTBSize, TRUE);
433     }
434
435     return DefWindowProcW(hWnd, WM_SIZE, wParam, lParam);
436 }
437
438 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
439 {
440     switch(msg)
441     {
442     case WM_CREATE:
443         return OnCreate( hWnd, wParam, lParam );
444
445     case WM_USER:
446         return OnUser( hWnd, wParam, lParam );
447
448     case WM_NOTIFY:
449         return OnNotify( hWnd, wParam, lParam );
450
451     case WM_COMMAND:
452         return OnCommand( hWnd, wParam, lParam );
453
454     case WM_DESTROY:
455         PostQuitMessage(0);
456         break;
457
458     case WM_ACTIVATE:
459         if (LOWORD(wParam))
460             SetFocus(GetDlgItem(hWnd, IDC_EDITOR));
461         return 0;
462
463     case WM_INITMENUPOPUP:
464         return OnInitPopupMenu( hWnd, wParam, lParam );
465
466     case WM_SIZE:
467         return OnSize( hWnd, wParam, lParam );
468
469     default:
470         return DefWindowProcW(hWnd, msg, wParam, lParam);
471     }
472
473     return 0;
474 }
475
476 int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hOldInstance, LPSTR szCmdParagraph, int res)
477 {
478     INITCOMMONCONTROLSEX classes = {8, ICC_BAR_CLASSES|ICC_COOL_CLASSES};
479     HACCEL hAccel;
480     WNDCLASSW wc;
481     MSG msg;
482
483     InitCommonControlsEx(&classes);
484
485     hAccel = LoadAccelerators(hInstance, "MAINACCELTABLE");
486
487     wc.style = CS_HREDRAW | CS_VREDRAW;
488     wc.lpfnWndProc = WndProc;
489     wc.cbClsExtra = 0;
490     wc.cbWndExtra = 4;
491     wc.hInstance = hInstance;
492     wc.hIcon = NULL;
493     wc.hCursor = LoadCursor(NULL, IDC_IBEAM);
494     wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
495     wc.lpszMenuName = xszMainMenu;
496     wc.lpszClassName = wszMainWndClass;
497     RegisterClassW(&wc);
498
499     hMainWnd = CreateWindowExW(0, wszMainWndClass, wszAppTitle, WS_OVERLAPPEDWINDOW,
500       CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, hInstance, NULL);
501     ShowWindow(hMainWnd, SW_SHOWMAXIMIZED);
502
503     while(GetMessage(&msg,0,0,0))
504     {
505         if (TranslateAccelerator(hMainWnd, hAccel, &msg))
506             continue;
507         TranslateMessage(&msg);
508         DispatchMessage(&msg);
509         if (!PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE))
510             SendMessage(hMainWnd, WM_USER, 0, 0);
511     }
512
513     return 0;
514 }