wordpad: Add paste support.
[wine/wine-gecko.git] / programs / wordpad / wordpad.c
blob4334ed2645933da85a0825bb34456144b3cc5293
1 /*
2 * Wordpad implementation
4 * Copyright 2004 by Krzysztof Foltman
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.
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.
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
21 #define WIN32_LEAN_AND_MEAN
22 #define _WIN32_IE 0x0400
24 #include <stdarg.h>
25 #include <ctype.h>
26 #include <stdio.h>
27 #include <assert.h>
29 #include <windows.h>
30 #include <richedit.h>
31 #include <commctrl.h>
33 #include "resource.h"
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};
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};
44 static HWND hMainWnd;
45 static HWND hEditorWnd;
47 static void AddButton(HWND hwndToolBar, int nImage, int nCommand)
49 TBBUTTON button;
51 ZeroMemory(&button, sizeof(button));
52 button.iBitmap = nImage;
53 button.idCommand = nCommand;
54 button.fsState = TBSTATE_ENABLED;
55 button.fsStyle = TBSTYLE_BUTTON;
56 button.dwData = 0;
57 button.iString = -1;
58 SendMessage(hwndToolBar, TB_ADDBUTTONS, 1, (LPARAM)&button);
61 static void AddSeparator(HWND hwndToolBar)
63 TBBUTTON button;
65 ZeroMemory(&button, sizeof(button));
66 button.iBitmap = -1;
67 button.idCommand = 0;
68 button.fsState = 0;
69 button.fsStyle = TBSTYLE_SEP;
70 button.dwData = 0;
71 button.iString = -1;
72 SendMessage(hwndToolBar, TB_ADDBUTTONS, 1, (LPARAM)&button);
75 static LPSTR stream_buffer;
76 static LONG stream_buffer_size;
78 static DWORD CALLBACK stream_in(DWORD_PTR cookie, LPBYTE buffer, LONG cb, LONG *pcb)
80 LONG size = min(stream_buffer_size, cb);
82 memcpy(buffer, stream_buffer, size);
83 stream_buffer_size -= size;
84 stream_buffer += size;
85 *pcb = size;
86 return 0;
89 static void DoOpenFile(LPCWSTR szFileName)
91 HANDLE hFile;
92 LPSTR pTemp;
93 DWORD size;
94 DWORD dwNumRead;
95 EDITSTREAM es;
97 hFile = CreateFileW(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
98 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
99 if (hFile == INVALID_HANDLE_VALUE)
100 return;
102 size = GetFileSize(hFile, NULL);
103 if (size == INVALID_FILE_SIZE)
105 CloseHandle(hFile);
106 return;
108 size++;
110 pTemp = HeapAlloc(GetProcessHeap(), 0, size);
111 if (!pTemp)
113 CloseHandle(hFile);
114 return;
117 if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL))
119 CloseHandle(hFile);
120 HeapFree(GetProcessHeap(), 0, pTemp);
121 return;
123 CloseHandle(hFile);
124 pTemp[dwNumRead] = 0;
126 memset(&es, 0, sizeof(es));
127 es.pfnCallback = stream_in;
129 stream_buffer = pTemp;
130 stream_buffer_size = size;
132 SendMessage(hEditorWnd, EM_STREAMIN, SF_RTF, (LPARAM)&es);
133 HeapFree(GetProcessHeap(), 0, pTemp);
135 SetFocus(hEditorWnd);
138 static void HandleCommandLine(LPWSTR cmdline)
140 WCHAR delimiter;
141 int opt_print = 0;
143 /* skip white space */
144 while (*cmdline == ' ') cmdline++;
146 /* skip executable name */
147 delimiter = (*cmdline == '"' ? '"' : ' ');
149 if (*cmdline == delimiter) cmdline++;
150 while (*cmdline && *cmdline != delimiter) cmdline++;
151 if (*cmdline == delimiter) cmdline++;
153 while (*cmdline == ' ' || *cmdline == '-' || *cmdline == '/')
155 WCHAR option;
157 if (*cmdline++ == ' ') continue;
159 option = *cmdline;
160 if (option) cmdline++;
161 while (*cmdline == ' ') cmdline++;
163 switch (option)
165 case 'p':
166 case 'P':
167 opt_print = 1;
168 break;
172 if (*cmdline)
174 /* file name is passed on the command line */
175 if (cmdline[0] == '"')
177 cmdline++;
178 cmdline[lstrlenW(cmdline) - 1] = 0;
180 DoOpenFile(cmdline);
181 InvalidateRect(hMainWnd, NULL, FALSE);
184 if (opt_print)
185 MessageBox(hMainWnd, "Printing not implemented", "WordPad", MB_OK);
188 static LRESULT OnCreate( HWND hWnd, WPARAM wParam, LPARAM lParam)
190 HWND hToolBarWnd, hReBarWnd;
191 HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE);
192 HANDLE hDLL;
193 TBADDBITMAP ab;
194 int nStdBitmaps = 0;
195 REBARINFO rbi;
196 REBARBANDINFO rbb;
198 CreateStatusWindow(CCS_NODIVIDER|WS_CHILD|WS_VISIBLE, "RichEdit text", hWnd, IDC_STATUSBAR);
200 hReBarWnd = CreateWindowEx(WS_EX_TOOLWINDOW, REBARCLASSNAME, NULL,
201 CCS_NODIVIDER|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|RBS_VARHEIGHT|CCS_TOP,
202 CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hWnd, (HMENU)IDC_REBAR, hInstance, NULL);
204 rbi.cbSize = sizeof(rbi);
205 rbi.fMask = 0;
206 rbi.himl = NULL;
207 if(!SendMessage(hReBarWnd, RB_SETBARINFO, 0, (LPARAM)&rbi))
208 return -1;
210 hToolBarWnd = CreateToolbarEx(hReBarWnd, CCS_NOPARENTALIGN|CCS_NODIVIDER|CCS_NOMOVEY|WS_VISIBLE|WS_CHILD|TBSTYLE_TOOLTIPS|TBSTYLE_BUTTON,
211 IDC_TOOLBAR,
212 3, hInstance, IDB_TOOLBAR,
213 NULL, 0,
214 24, 24, 16, 16, sizeof(TBBUTTON));
216 ab.hInst = HINST_COMMCTRL;
217 ab.nID = IDB_STD_SMALL_COLOR;
218 nStdBitmaps = SendMessage(hToolBarWnd, TB_ADDBITMAP, 3, (LPARAM)&ab);
219 AddButton(hToolBarWnd, nStdBitmaps+STD_FILENEW, ID_FILE_NEW);
220 AddButton(hToolBarWnd, nStdBitmaps+STD_FILEOPEN, ID_FILE_OPEN);
221 AddButton(hToolBarWnd, nStdBitmaps+STD_FILESAVE, ID_FILE_SAVE);
222 AddSeparator(hToolBarWnd);
223 AddButton(hToolBarWnd, nStdBitmaps+STD_PRINT, ID_PRINT);
224 AddButton(hToolBarWnd, nStdBitmaps+STD_PRINTPRE, ID_PREVIEW);
225 AddSeparator(hToolBarWnd);
226 AddButton(hToolBarWnd, nStdBitmaps+STD_FIND, ID_FIND);
227 AddSeparator(hToolBarWnd);
228 AddButton(hToolBarWnd, nStdBitmaps+STD_CUT, ID_EDIT_CUT);
229 AddButton(hToolBarWnd, nStdBitmaps+STD_COPY, ID_EDIT_COPY);
230 AddButton(hToolBarWnd, nStdBitmaps+STD_PASTE, ID_EDIT_PASTE);
231 AddButton(hToolBarWnd, nStdBitmaps+STD_UNDO, ID_EDIT_UNDO);
232 AddButton(hToolBarWnd, nStdBitmaps+STD_REDOW, ID_EDIT_REDO);
233 AddSeparator(hToolBarWnd);
234 AddButton(hToolBarWnd, 0, ID_FORMAT_BOLD);
235 AddButton(hToolBarWnd, 1, ID_FORMAT_ITALIC);
236 AddButton(hToolBarWnd, 2, ID_FORMAT_UNDERLINE);
238 SendMessage(hToolBarWnd, TB_ADDSTRING, 0, (LPARAM)"Exit\0");
239 SendMessage(hToolBarWnd, TB_AUTOSIZE, 0, 0);
241 rbb.cbSize = sizeof(rbb);
242 rbb.fMask = RBBIM_SIZE | RBBIM_CHILDSIZE | RBBIM_CHILD | RBBIM_STYLE;
243 rbb.fStyle = RBBS_CHILDEDGE;
244 rbb.cx = 500;
245 rbb.hwndChild = hToolBarWnd;
246 rbb.cxMinChild = 0;
247 rbb.cyChild = rbb.cyMinChild = HIWORD(SendMessage(hToolBarWnd, TB_GETBUTTONSIZE, 0, 0));
249 SendMessage(hReBarWnd, RB_INSERTBAND, -1, (LPARAM)&rbb);
251 hDLL = LoadLibrary("RICHED20.DLL");
252 assert(hDLL);
254 hEditorWnd = CreateWindowExW(WS_EX_CLIENTEDGE, wszRichEditClass, NULL,
255 WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOVSCROLL|ES_WANTRETURN|WS_VSCROLL,
256 0, 0, 1000, 100, hWnd, (HMENU)IDC_EDITOR, hInstance, NULL);
257 if (!hEditorWnd)
259 fprintf(stderr, "Error code %u\n", GetLastError());
260 return -1;
262 assert(hEditorWnd);
264 SetFocus(hEditorWnd);
265 SendMessage(hEditorWnd, EM_SETEVENTMASK, 0, ENM_SELCHANGE);
266 return 0;
269 static LRESULT OnUser( HWND hWnd, WPARAM wParam, LPARAM lParam)
271 HWND hwndEditor = GetDlgItem(hWnd, IDC_EDITOR);
272 HWND hwndReBar = GetDlgItem(hWnd, IDC_REBAR);
273 HWND hwndToolBar = GetDlgItem(hwndReBar, IDC_TOOLBAR);
274 int from, to;
275 CHARFORMAT2W fmt;
277 ZeroMemory(&fmt, sizeof(fmt));
278 fmt.cbSize = sizeof(fmt);
280 SendMessage(hwndEditor, EM_GETCHARFORMAT, TRUE, (LPARAM)&fmt);
282 SendMessage(hwndEditor, EM_GETSEL, (WPARAM)&from, (LPARAM)&to);
283 SendMessage(hwndToolBar, TB_ENABLEBUTTON, ID_EDIT_UNDO,
284 SendMessage(hwndEditor, EM_CANUNDO, 0, 0));
285 SendMessage(hwndToolBar, TB_ENABLEBUTTON, ID_EDIT_REDO,
286 SendMessage(hwndEditor, EM_CANREDO, 0, 0));
287 SendMessage(hwndToolBar, TB_ENABLEBUTTON, ID_EDIT_CUT, from == to ? 0 : 1);
288 SendMessage(hwndToolBar, TB_ENABLEBUTTON, ID_EDIT_COPY, from == to ? 0 : 1);
289 SendMessage(hwndToolBar, TB_CHECKBUTTON, ID_FORMAT_BOLD, (fmt.dwMask & CFM_BOLD) && (fmt.dwEffects & CFE_BOLD));
290 SendMessage(hwndToolBar, TB_INDETERMINATE, ID_FORMAT_BOLD, !(fmt.dwMask & CFM_BOLD));
291 SendMessage(hwndToolBar, TB_CHECKBUTTON, ID_FORMAT_ITALIC, (fmt.dwMask & CFM_ITALIC) && (fmt.dwEffects & CFE_ITALIC));
292 SendMessage(hwndToolBar, TB_INDETERMINATE, ID_FORMAT_ITALIC, !(fmt.dwMask & CFM_ITALIC));
293 SendMessage(hwndToolBar, TB_CHECKBUTTON, ID_FORMAT_UNDERLINE, (fmt.dwMask & CFM_UNDERLINE) && (fmt.dwEffects & CFE_UNDERLINE));
294 SendMessage(hwndToolBar, TB_INDETERMINATE, ID_FORMAT_UNDERLINE, !(fmt.dwMask & CFM_UNDERLINE));
295 return 0;
298 static LRESULT OnNotify( HWND hWnd, WPARAM wParam, LPARAM lParam)
300 HWND hwndEditor = GetDlgItem(hWnd, IDC_EDITOR);
301 NMHDR *pHdr = (NMHDR *)lParam;
303 if (pHdr->hwndFrom != hwndEditor)
304 return 0;
306 if (pHdr->code == EN_SELCHANGE)
308 SELCHANGE *pSC = (SELCHANGE *)lParam;
309 char buf[128];
311 sprintf( buf,"selection = %d..%d, line count=%ld\n",
312 pSC->chrg.cpMin, pSC->chrg.cpMax,
313 SendMessage(hwndEditor, EM_GETLINECOUNT, 0, 0));
314 SetWindowText(GetDlgItem(hWnd, IDC_STATUSBAR), buf);
315 SendMessage(hWnd, WM_USER, 0, 0);
316 return 1;
318 return 0;
321 static LRESULT OnCommand( HWND hWnd, WPARAM wParam, LPARAM lParam)
323 HWND hwndEditor = GetDlgItem(hWnd, IDC_EDITOR);
325 if ((HWND)lParam == hwndEditor)
326 return 0;
328 switch(LOWORD(wParam))
330 case ID_FILE_EXIT:
331 PostMessage(hWnd, WM_CLOSE, 0, 0);
332 break;
334 case ID_FILE_NEW:
335 SetWindowTextA(hwndEditor, "");
336 /* FIXME: set default format too */
337 break;
339 case ID_FILE_OPEN:
340 case ID_FILE_SAVE:
341 case ID_PRINT:
342 case ID_PREVIEW:
343 case ID_FIND:
344 MessageBox(hWnd, "Not implemented", "WordPad", MB_OK);
345 break;
347 case ID_FORMAT_BOLD:
348 case ID_FORMAT_ITALIC:
349 case ID_FORMAT_UNDERLINE:
351 CHARFORMAT2W fmt;
352 int mask = CFM_BOLD;
353 if (LOWORD(wParam) == ID_FORMAT_ITALIC) mask = CFM_ITALIC;
354 if (LOWORD(wParam) == ID_FORMAT_UNDERLINE) mask = CFM_UNDERLINE;
356 ZeroMemory(&fmt, sizeof(fmt));
357 fmt.cbSize = sizeof(fmt);
358 SendMessage(hwndEditor, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
359 if (!(fmt.dwMask&mask))
360 fmt.dwEffects |= mask;
361 else
362 fmt.dwEffects ^= mask;
363 fmt.dwMask = mask;
364 SendMessage(hwndEditor, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&fmt);
365 break;
368 case ID_EDIT_CUT:
369 PostMessage(hwndEditor, WM_CUT, 0, 0);
370 break;
372 case ID_EDIT_COPY:
373 PostMessage(hwndEditor, WM_COPY, 0, 0);
374 break;
376 case ID_EDIT_PASTE:
377 PostMessage(hwndEditor, WM_PASTE, 0, 0);
378 break;
380 case ID_EDIT_SELECTALL:
382 CHARRANGE range = {0, -1};
383 SendMessage(hwndEditor, EM_EXSETSEL, 0, (LPARAM)&range);
384 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
385 return 0;
388 case ID_EDIT_GETTEXT:
390 int nLen = GetWindowTextLengthW(hwndEditor);
391 LPWSTR data = HeapAlloc( GetProcessHeap(), 0, (nLen+1)*sizeof(WCHAR) );
392 TEXTRANGEW tr;
394 GetWindowTextW(hwndEditor, data, nLen+1);
395 MessageBoxW(NULL, data, xszAppTitle, MB_OK);
397 HeapFree( GetProcessHeap(), 0, data);
398 data = HeapAlloc(GetProcessHeap(), 0, (nLen+1)*sizeof(WCHAR));
399 tr.chrg.cpMin = 0;
400 tr.chrg.cpMax = nLen;
401 tr.lpstrText = data;
402 SendMessage (hwndEditor, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
403 MessageBoxW(NULL, data, xszAppTitle, MB_OK);
404 HeapFree( GetProcessHeap(), 0, data );
406 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
407 return 0;
410 case ID_EDIT_CHARFORMAT:
411 case ID_EDIT_DEFCHARFORMAT:
413 CHARFORMAT2W cf;
414 LRESULT i;
415 ZeroMemory(&cf, sizeof(cf));
416 cf.cbSize = sizeof(cf);
417 cf.dwMask = 0;
418 i = SendMessage(hwndEditor, EM_GETCHARFORMAT,
419 LOWORD(wParam) == ID_EDIT_CHARFORMAT, (LPARAM)&cf);
420 return 0;
423 case ID_EDIT_PARAFORMAT:
425 PARAFORMAT2 pf;
426 ZeroMemory(&pf, sizeof(pf));
427 pf.cbSize = sizeof(pf);
428 SendMessage(hwndEditor, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
429 return 0;
432 case ID_EDIT_SELECTIONINFO:
434 CHARRANGE range = {0, -1};
435 char buf[128];
436 WCHAR *data = NULL;
438 SendMessage(hwndEditor, EM_EXGETSEL, 0, (LPARAM)&range);
439 data = HeapAlloc(GetProcessHeap(), 0, sizeof(*data) * (range.cpMax-range.cpMin+1));
440 SendMessage(hwndEditor, EM_GETSELTEXT, 0, (LPARAM)data);
441 sprintf(buf, "Start = %d, End = %d", range.cpMin, range.cpMax);
442 MessageBoxA(hWnd, buf, "Editor", MB_OK);
443 MessageBoxW(hWnd, data, xszAppTitle, MB_OK);
444 HeapFree( GetProcessHeap(), 0, data);
445 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
446 return 0;
449 case ID_EDIT_READONLY:
451 long nStyle = GetWindowLong(hwndEditor, GWL_STYLE);
452 if (nStyle & ES_READONLY)
453 SendMessage(hwndEditor, EM_SETREADONLY, 0, 0);
454 else
455 SendMessage(hwndEditor, EM_SETREADONLY, 1, 0);
456 return 0;
459 case ID_EDIT_MODIFIED:
460 if (SendMessage(hwndEditor, EM_GETMODIFY, 0, 0))
461 SendMessage(hwndEditor, EM_SETMODIFY, 0, 0);
462 else
463 SendMessage(hwndEditor, EM_SETMODIFY, 1, 0);
464 return 0;
466 case ID_EDIT_UNDO:
467 SendMessage(hwndEditor, EM_UNDO, 0, 0);
468 return 0;
470 case ID_EDIT_REDO:
471 SendMessage(hwndEditor, EM_REDO, 0, 0);
472 return 0;
474 case ID_ALIGN_LEFT:
475 case ID_ALIGN_CENTER:
476 case ID_ALIGN_RIGHT:
478 PARAFORMAT2 pf;
480 pf.cbSize = sizeof(pf);
481 pf.dwMask = PFM_ALIGNMENT;
482 switch(LOWORD(wParam)) {
483 case ID_ALIGN_LEFT: pf.wAlignment = PFA_LEFT; break;
484 case ID_ALIGN_CENTER: pf.wAlignment = PFA_CENTER; break;
485 case ID_ALIGN_RIGHT: pf.wAlignment = PFA_RIGHT; break;
487 SendMessage(hwndEditor, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
488 break;
491 case ID_BACK_1:
492 SendMessage(hwndEditor, EM_SETBKGNDCOLOR, 1, 0);
493 break;
495 case ID_BACK_2:
496 SendMessage(hwndEditor, EM_SETBKGNDCOLOR, 0, RGB(255,255,192));
497 break;
499 default:
500 SendMessage(hwndEditor, WM_COMMAND, wParam, lParam);
501 break;
503 return 0;
506 static LRESULT OnInitPopupMenu( HWND hWnd, WPARAM wParam, LPARAM lParam )
508 HMENU hMenu = (HMENU)wParam;
509 HWND hwndEditor = GetDlgItem(hWnd, IDC_EDITOR);
510 PARAFORMAT pf;
511 int nAlignment = -1;
513 pf.cbSize = sizeof(PARAFORMAT);
514 SendMessage(hwndEditor, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
515 CheckMenuItem(hMenu, ID_EDIT_READONLY,
516 MF_BYCOMMAND|(GetWindowLong(hwndEditor, GWL_STYLE)&ES_READONLY ? MF_CHECKED : MF_UNCHECKED));
517 CheckMenuItem(hMenu, ID_EDIT_MODIFIED,
518 MF_BYCOMMAND|(SendMessage(hwndEditor, EM_GETMODIFY, 0, 0) ? MF_CHECKED : MF_UNCHECKED));
519 if (pf.dwMask & PFM_ALIGNMENT)
520 nAlignment = pf.wAlignment;
521 CheckMenuItem(hMenu, ID_ALIGN_LEFT, MF_BYCOMMAND|(nAlignment == PFA_LEFT) ? MF_CHECKED : MF_UNCHECKED);
522 CheckMenuItem(hMenu, ID_ALIGN_CENTER, MF_BYCOMMAND|(nAlignment == PFA_CENTER) ? MF_CHECKED : MF_UNCHECKED);
523 CheckMenuItem(hMenu, ID_ALIGN_RIGHT, MF_BYCOMMAND|(nAlignment == PFA_RIGHT) ? MF_CHECKED : MF_UNCHECKED);
524 EnableMenuItem(hMenu, ID_EDIT_UNDO, MF_BYCOMMAND|(SendMessage(hwndEditor, EM_CANUNDO, 0, 0)) ? MF_ENABLED : MF_GRAYED);
525 EnableMenuItem(hMenu, ID_EDIT_REDO, MF_BYCOMMAND|(SendMessage(hwndEditor, EM_CANREDO, 0, 0)) ? MF_ENABLED : MF_GRAYED);
526 return 0;
529 static LRESULT OnSize( HWND hWnd, WPARAM wParam, LPARAM lParam )
531 int nStatusSize = 0, nTBSize = 0;
532 RECT rc;
533 HWND hwndEditor = GetDlgItem(hWnd, IDC_EDITOR);
534 HWND hwndStatusBar = GetDlgItem(hWnd, IDC_STATUSBAR);
535 HWND hwndReBar = GetDlgItem(hWnd, IDC_REBAR);
536 HWND hwndToolBar = GetDlgItem(hwndReBar, IDC_TOOLBAR);
538 if (hwndStatusBar)
540 SendMessage(hwndStatusBar, WM_SIZE, 0, 0);
541 GetClientRect(hwndStatusBar, &rc);
542 nStatusSize = rc.bottom - rc.top;
544 if (hwndToolBar)
546 rc.left = rc.top = 0;
547 rc.right = LOWORD(lParam);
548 rc.bottom = HIWORD(lParam);
549 SendMessage(hwndToolBar, TB_AUTOSIZE, 0, 0);
550 SendMessage(hwndReBar, RB_SIZETORECT, 0, (LPARAM)&rc);
551 nTBSize = SendMessage(hwndReBar, RB_GETBARHEIGHT, 0, 0);
552 GetClientRect(hwndReBar, &rc);
553 MoveWindow(hwndReBar, 0, 0, LOWORD(lParam), rc.right, FALSE);
555 if (hwndEditor)
557 GetClientRect(hWnd, &rc);
558 MoveWindow(hwndEditor, 0, nTBSize, rc.right, rc.bottom-nStatusSize-nTBSize, TRUE);
561 return DefWindowProcW(hWnd, WM_SIZE, wParam, lParam);
564 static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
566 switch(msg)
568 case WM_CREATE:
569 return OnCreate( hWnd, wParam, lParam );
571 case WM_USER:
572 return OnUser( hWnd, wParam, lParam );
574 case WM_NOTIFY:
575 return OnNotify( hWnd, wParam, lParam );
577 case WM_COMMAND:
578 return OnCommand( hWnd, wParam, lParam );
580 case WM_DESTROY:
581 PostQuitMessage(0);
582 break;
584 case WM_ACTIVATE:
585 if (LOWORD(wParam))
586 SetFocus(GetDlgItem(hWnd, IDC_EDITOR));
587 return 0;
589 case WM_INITMENUPOPUP:
590 return OnInitPopupMenu( hWnd, wParam, lParam );
592 case WM_SIZE:
593 return OnSize( hWnd, wParam, lParam );
595 default:
596 return DefWindowProcW(hWnd, msg, wParam, lParam);
599 return 0;
602 int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hOldInstance, LPSTR szCmdParagraph, int res)
604 INITCOMMONCONTROLSEX classes = {8, ICC_BAR_CLASSES|ICC_COOL_CLASSES};
605 HACCEL hAccel;
606 WNDCLASSW wc;
607 MSG msg;
609 InitCommonControlsEx(&classes);
611 hAccel = LoadAccelerators(hInstance, "MAINACCELTABLE");
613 wc.style = CS_HREDRAW | CS_VREDRAW;
614 wc.lpfnWndProc = WndProc;
615 wc.cbClsExtra = 0;
616 wc.cbWndExtra = 4;
617 wc.hInstance = hInstance;
618 wc.hIcon = NULL;
619 wc.hCursor = LoadCursor(NULL, IDC_IBEAM);
620 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
621 wc.lpszMenuName = xszMainMenu;
622 wc.lpszClassName = wszMainWndClass;
623 RegisterClassW(&wc);
625 hMainWnd = CreateWindowExW(0, wszMainWndClass, wszAppTitle, WS_OVERLAPPEDWINDOW,
626 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, hInstance, NULL);
627 ShowWindow(hMainWnd, SW_SHOWDEFAULT);
629 HandleCommandLine(GetCommandLineW());
631 while(GetMessage(&msg,0,0,0))
633 if (TranslateAccelerator(hMainWnd, hAccel, &msg))
634 continue;
635 TranslateMessage(&msg);
636 DispatchMessage(&msg);
637 if (!PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE))
638 SendMessage(hMainWnd, WM_USER, 0, 0);
641 return 0;