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 #define MAX_STRING_LEN 255
39 static const WCHAR xszAppTitle
[] = {'W','i','n','e',' ','W','o','r','d','p','a','d',0};
40 static const WCHAR xszMainMenu
[] = {'M','A','I','N','M','E','N','U',0};
42 static const WCHAR wszRichEditClass
[] = {'R','I','C','H','E','D','I','T','2','0','W',0};
43 static const WCHAR wszMainWndClass
[] = {'W','O','R','D','P','A','D','T','O','P',0};
44 static const WCHAR wszAppTitle
[] = {'W','i','n','e',' ','W','o','r','d','p','a','d',0};
47 static HWND hEditorWnd
;
49 static char szFilter
[MAX_STRING_LEN
];
51 /* Load string resources */
52 static void DoLoadStrings()
55 char files_rtf
[] = "*.rtf";
56 char files_txt
[] = "*.txt";
57 char files_all
[] = "*.*";
58 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
60 LoadString(hInstance
, STRING_RICHTEXT_FILES_RTF
, p
, MAX_STRING_LEN
);
62 lstrcpy(p
, files_rtf
);
64 LoadString(hInstance
, STRING_TEXT_FILES_TXT
, p
, MAX_STRING_LEN
);
66 lstrcpy(p
, files_txt
);
68 LoadString(hInstance
, STRING_ALL_FILES
, p
, MAX_STRING_LEN
);
70 lstrcpy(p
, files_all
);
75 static void AddButton(HWND hwndToolBar
, int nImage
, int nCommand
)
79 ZeroMemory(&button
, sizeof(button
));
80 button
.iBitmap
= nImage
;
81 button
.idCommand
= nCommand
;
82 button
.fsState
= TBSTATE_ENABLED
;
83 button
.fsStyle
= TBSTYLE_BUTTON
;
86 SendMessage(hwndToolBar
, TB_ADDBUTTONS
, 1, (LPARAM
)&button
);
89 static void AddSeparator(HWND hwndToolBar
)
93 ZeroMemory(&button
, sizeof(button
));
97 button
.fsStyle
= TBSTYLE_SEP
;
100 SendMessage(hwndToolBar
, TB_ADDBUTTONS
, 1, (LPARAM
)&button
);
103 static LPSTR stream_buffer
;
104 static LONG stream_buffer_size
;
106 static DWORD CALLBACK
stream_in(DWORD_PTR cookie
, LPBYTE buffer
, LONG cb
, LONG
*pcb
)
108 LONG size
= min(stream_buffer_size
, cb
);
110 memcpy(buffer
, stream_buffer
, size
);
111 stream_buffer_size
-= size
;
112 stream_buffer
+= size
;
117 static void DoOpenFile(LPCWSTR szFileName
)
125 char szCaption
[MAX_PATH
];
126 char szAppTitle
[sizeof(wszAppTitle
)];
127 char szSeparator
[] = " - ";
129 hFile
= CreateFileW(szFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
130 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
131 if (hFile
== INVALID_HANDLE_VALUE
)
134 size
= GetFileSize(hFile
, NULL
);
135 if (size
== INVALID_FILE_SIZE
)
142 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
);
149 if (!ReadFile(hFile
, pTemp
, size
, &dwNumRead
, NULL
))
152 HeapFree(GetProcessHeap(), 0, pTemp
);
156 pTemp
[dwNumRead
] = 0;
158 memset(&es
, 0, sizeof(es
));
159 es
.pfnCallback
= stream_in
;
161 stream_buffer
= pTemp
;
162 stream_buffer_size
= size
;
164 SendMessage(hEditorWnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
)&es
);
165 HeapFree(GetProcessHeap(), 0, pTemp
);
167 SetFocus(hEditorWnd
);
169 WideCharToMultiByte(CP_ACP
, 0, wszAppTitle
, -1, szAppTitle
, sizeof(wszAppTitle
), NULL
, NULL
);
171 WideCharToMultiByte(CP_ACP
, 0, szFileName
, -1, szCaption
, MAX_PATH
, NULL
, NULL
);
173 lstrcat(szCaption
, szSeparator
);
174 lstrcat(szCaption
, szAppTitle
);
176 SetWindowText(hMainWnd
, szCaption
);
179 static void DialogOpenFile()
183 char szFile
[MAX_PATH
] = "";
184 char szDefExt
[] = "rtf";
186 ZeroMemory(&ofn
, sizeof(ofn
));
188 ofn
.lStructSize
= sizeof(ofn
);
189 ofn
.Flags
= OFN_HIDEREADONLY
| OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
190 ofn
.hwndOwner
= hMainWnd
;
191 ofn
.lpstrFilter
= szFilter
;
192 ofn
.lpstrFile
= szFile
;
193 ofn
.nMaxFile
= MAX_PATH
;
194 ofn
.lpstrDefExt
= szDefExt
;
196 if(GetOpenFileName(&ofn
))
198 WCHAR szOpenFile
[MAX_PATH
];
200 MultiByteToWideChar(CP_ACP
, 0, ofn
.lpstrFile
, MAX_PATH
, szOpenFile
, sizeof(szOpenFile
)/sizeof(szOpenFile
[0]));
202 DoOpenFile(szOpenFile
);
206 static void HandleCommandLine(LPWSTR cmdline
)
211 /* skip white space */
212 while (*cmdline
== ' ') cmdline
++;
214 /* skip executable name */
215 delimiter
= (*cmdline
== '"' ? '"' : ' ');
217 if (*cmdline
== delimiter
) cmdline
++;
218 while (*cmdline
&& *cmdline
!= delimiter
) cmdline
++;
219 if (*cmdline
== delimiter
) cmdline
++;
221 while (*cmdline
== ' ' || *cmdline
== '-' || *cmdline
== '/')
225 if (*cmdline
++ == ' ') continue;
228 if (option
) cmdline
++;
229 while (*cmdline
== ' ') cmdline
++;
242 /* file name is passed on the command line */
243 if (cmdline
[0] == '"')
246 cmdline
[lstrlenW(cmdline
) - 1] = 0;
249 InvalidateRect(hMainWnd
, NULL
, FALSE
);
253 MessageBox(hMainWnd
, "Printing not implemented", "WordPad", MB_OK
);
256 static void DoDefaultFont()
258 static const WCHAR szFaceName
[] = {'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n',0};
261 ZeroMemory(&fmt
, sizeof(fmt
));
263 fmt
.cbSize
= sizeof(fmt
);
264 fmt
.dwMask
= CFM_FACE
;
266 lstrcpyW(fmt
.szFaceName
, szFaceName
);
268 SendMessage(hEditorWnd
, EM_SETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&fmt
);
271 static LRESULT
OnCreate( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
273 HWND hToolBarWnd
, hReBarWnd
;
274 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
281 CreateStatusWindow(CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
, "RichEdit text", hWnd
, IDC_STATUSBAR
);
283 hReBarWnd
= CreateWindowEx(WS_EX_TOOLWINDOW
, REBARCLASSNAME
, NULL
,
284 CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|WS_CLIPCHILDREN
|RBS_VARHEIGHT
|CCS_TOP
,
285 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, hWnd
, (HMENU
)IDC_REBAR
, hInstance
, NULL
);
287 rbi
.cbSize
= sizeof(rbi
);
290 if(!SendMessage(hReBarWnd
, RB_SETBARINFO
, 0, (LPARAM
)&rbi
))
293 hToolBarWnd
= CreateToolbarEx(hReBarWnd
, CCS_NOPARENTALIGN
|CCS_NOMOVEY
|WS_VISIBLE
|WS_CHILD
|TBSTYLE_TOOLTIPS
|TBSTYLE_BUTTON
,
295 3, hInstance
, IDB_TOOLBAR
,
297 24, 24, 16, 16, sizeof(TBBUTTON
));
299 ab
.hInst
= HINST_COMMCTRL
;
300 ab
.nID
= IDB_STD_SMALL_COLOR
;
301 nStdBitmaps
= SendMessage(hToolBarWnd
, TB_ADDBITMAP
, 3, (LPARAM
)&ab
);
302 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILENEW
, ID_FILE_NEW
);
303 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILEOPEN
, ID_FILE_OPEN
);
304 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILESAVE
, ID_FILE_SAVE
);
305 AddSeparator(hToolBarWnd
);
306 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINT
, ID_PRINT
);
307 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINTPRE
, ID_PREVIEW
);
308 AddSeparator(hToolBarWnd
);
309 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FIND
, ID_FIND
);
310 AddSeparator(hToolBarWnd
);
311 AddButton(hToolBarWnd
, nStdBitmaps
+STD_CUT
, ID_EDIT_CUT
);
312 AddButton(hToolBarWnd
, nStdBitmaps
+STD_COPY
, ID_EDIT_COPY
);
313 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PASTE
, ID_EDIT_PASTE
);
314 AddButton(hToolBarWnd
, nStdBitmaps
+STD_UNDO
, ID_EDIT_UNDO
);
315 AddButton(hToolBarWnd
, nStdBitmaps
+STD_REDOW
, ID_EDIT_REDO
);
316 AddSeparator(hToolBarWnd
);
317 AddButton(hToolBarWnd
, 0, ID_FORMAT_BOLD
);
318 AddButton(hToolBarWnd
, 1, ID_FORMAT_ITALIC
);
319 AddButton(hToolBarWnd
, 2, ID_FORMAT_UNDERLINE
);
321 SendMessage(hToolBarWnd
, TB_ADDSTRING
, 0, (LPARAM
)"Exit\0");
322 SendMessage(hToolBarWnd
, TB_AUTOSIZE
, 0, 0);
324 rbb
.cbSize
= sizeof(rbb
);
325 rbb
.fMask
= RBBIM_SIZE
| RBBIM_CHILDSIZE
| RBBIM_CHILD
| RBBIM_STYLE
;
326 rbb
.fStyle
= RBBS_CHILDEDGE
;
328 rbb
.hwndChild
= hToolBarWnd
;
330 rbb
.cyChild
= rbb
.cyMinChild
= HIWORD(SendMessage(hToolBarWnd
, TB_GETBUTTONSIZE
, 0, 0));
332 SendMessage(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
334 hDLL
= LoadLibrary("RICHED20.DLL");
337 hEditorWnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, wszRichEditClass
, NULL
,
338 WS_CHILD
|WS_VISIBLE
|ES_MULTILINE
|ES_AUTOVSCROLL
|ES_WANTRETURN
|WS_VSCROLL
,
339 0, 0, 1000, 100, hWnd
, (HMENU
)IDC_EDITOR
, hInstance
, NULL
);
342 fprintf(stderr
, "Error code %u\n", GetLastError());
347 SetFocus(hEditorWnd
);
348 SendMessage(hEditorWnd
, EM_SETEVENTMASK
, 0, ENM_SELCHANGE
);
357 static LRESULT
OnUser( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
359 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
360 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
361 HWND hwndToolBar
= GetDlgItem(hwndReBar
, IDC_TOOLBAR
);
365 ZeroMemory(&fmt
, sizeof(fmt
));
366 fmt
.cbSize
= sizeof(fmt
);
368 SendMessage(hwndEditor
, EM_GETCHARFORMAT
, TRUE
, (LPARAM
)&fmt
);
370 SendMessage(hwndEditor
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
371 SendMessage(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_UNDO
,
372 SendMessage(hwndEditor
, EM_CANUNDO
, 0, 0));
373 SendMessage(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_REDO
,
374 SendMessage(hwndEditor
, EM_CANREDO
, 0, 0));
375 SendMessage(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_CUT
, from
== to
? 0 : 1);
376 SendMessage(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_COPY
, from
== to
? 0 : 1);
377 SendMessage(hwndToolBar
, TB_CHECKBUTTON
, ID_FORMAT_BOLD
, (fmt
.dwMask
& CFM_BOLD
) && (fmt
.dwEffects
& CFE_BOLD
));
378 SendMessage(hwndToolBar
, TB_INDETERMINATE
, ID_FORMAT_BOLD
, !(fmt
.dwMask
& CFM_BOLD
));
379 SendMessage(hwndToolBar
, TB_CHECKBUTTON
, ID_FORMAT_ITALIC
, (fmt
.dwMask
& CFM_ITALIC
) && (fmt
.dwEffects
& CFE_ITALIC
));
380 SendMessage(hwndToolBar
, TB_INDETERMINATE
, ID_FORMAT_ITALIC
, !(fmt
.dwMask
& CFM_ITALIC
));
381 SendMessage(hwndToolBar
, TB_CHECKBUTTON
, ID_FORMAT_UNDERLINE
, (fmt
.dwMask
& CFM_UNDERLINE
) && (fmt
.dwEffects
& CFE_UNDERLINE
));
382 SendMessage(hwndToolBar
, TB_INDETERMINATE
, ID_FORMAT_UNDERLINE
, !(fmt
.dwMask
& CFM_UNDERLINE
));
386 static LRESULT
OnNotify( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
388 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
389 NMHDR
*pHdr
= (NMHDR
*)lParam
;
391 if (pHdr
->hwndFrom
!= hwndEditor
)
394 if (pHdr
->code
== EN_SELCHANGE
)
396 SELCHANGE
*pSC
= (SELCHANGE
*)lParam
;
399 sprintf( buf
,"selection = %d..%d, line count=%ld",
400 pSC
->chrg
.cpMin
, pSC
->chrg
.cpMax
,
401 SendMessage(hwndEditor
, EM_GETLINECOUNT
, 0, 0));
402 SetWindowText(GetDlgItem(hWnd
, IDC_STATUSBAR
), buf
);
403 SendMessage(hWnd
, WM_USER
, 0, 0);
409 static LRESULT
OnCommand( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
411 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
413 if ((HWND
)lParam
== hwndEditor
)
416 switch(LOWORD(wParam
))
419 PostMessage(hWnd
, WM_CLOSE
, 0, 0);
423 SetWindowTextA(hwndEditor
, "");
424 SetWindowTextW(hMainWnd
, wszAppTitle
);
425 /* FIXME: set default format too */
436 MessageBox(hWnd
, "Not implemented", "WordPad", MB_OK
);
440 case ID_FORMAT_ITALIC
:
441 case ID_FORMAT_UNDERLINE
:
445 if (LOWORD(wParam
) == ID_FORMAT_ITALIC
) mask
= CFM_ITALIC
;
446 if (LOWORD(wParam
) == ID_FORMAT_UNDERLINE
) mask
= CFM_UNDERLINE
;
448 ZeroMemory(&fmt
, sizeof(fmt
));
449 fmt
.cbSize
= sizeof(fmt
);
450 SendMessage(hwndEditor
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
451 if (!(fmt
.dwMask
&mask
))
452 fmt
.dwEffects
|= mask
;
454 fmt
.dwEffects
^= mask
;
456 SendMessage(hwndEditor
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
461 PostMessage(hwndEditor
, WM_CUT
, 0, 0);
465 PostMessage(hwndEditor
, WM_COPY
, 0, 0);
469 PostMessage(hwndEditor
, WM_PASTE
, 0, 0);
473 PostMessage(hwndEditor
, WM_CLEAR
, 0, 0);
476 case ID_EDIT_SELECTALL
:
478 CHARRANGE range
= {0, -1};
479 SendMessage(hwndEditor
, EM_EXSETSEL
, 0, (LPARAM
)&range
);
480 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
484 case ID_EDIT_GETTEXT
:
486 int nLen
= GetWindowTextLengthW(hwndEditor
);
487 LPWSTR data
= HeapAlloc( GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
) );
490 GetWindowTextW(hwndEditor
, data
, nLen
+1);
491 MessageBoxW(NULL
, data
, xszAppTitle
, MB_OK
);
493 HeapFree( GetProcessHeap(), 0, data
);
494 data
= HeapAlloc(GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
));
496 tr
.chrg
.cpMax
= nLen
;
498 SendMessage (hwndEditor
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
499 MessageBoxW(NULL
, data
, xszAppTitle
, MB_OK
);
500 HeapFree( GetProcessHeap(), 0, data
);
502 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
506 case ID_EDIT_CHARFORMAT
:
507 case ID_EDIT_DEFCHARFORMAT
:
511 ZeroMemory(&cf
, sizeof(cf
));
512 cf
.cbSize
= sizeof(cf
);
514 i
= SendMessage(hwndEditor
, EM_GETCHARFORMAT
,
515 LOWORD(wParam
) == ID_EDIT_CHARFORMAT
, (LPARAM
)&cf
);
519 case ID_EDIT_PARAFORMAT
:
522 ZeroMemory(&pf
, sizeof(pf
));
523 pf
.cbSize
= sizeof(pf
);
524 SendMessage(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
528 case ID_EDIT_SELECTIONINFO
:
530 CHARRANGE range
= {0, -1};
534 SendMessage(hwndEditor
, EM_EXGETSEL
, 0, (LPARAM
)&range
);
535 data
= HeapAlloc(GetProcessHeap(), 0, sizeof(*data
) * (range
.cpMax
-range
.cpMin
+1));
536 SendMessage(hwndEditor
, EM_GETSELTEXT
, 0, (LPARAM
)data
);
537 sprintf(buf
, "Start = %d, End = %d", range
.cpMin
, range
.cpMax
);
538 MessageBoxA(hWnd
, buf
, "Editor", MB_OK
);
539 MessageBoxW(hWnd
, data
, xszAppTitle
, MB_OK
);
540 HeapFree( GetProcessHeap(), 0, data
);
541 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
545 case ID_EDIT_READONLY
:
547 long nStyle
= GetWindowLong(hwndEditor
, GWL_STYLE
);
548 if (nStyle
& ES_READONLY
)
549 SendMessage(hwndEditor
, EM_SETREADONLY
, 0, 0);
551 SendMessage(hwndEditor
, EM_SETREADONLY
, 1, 0);
555 case ID_EDIT_MODIFIED
:
556 if (SendMessage(hwndEditor
, EM_GETMODIFY
, 0, 0))
557 SendMessage(hwndEditor
, EM_SETMODIFY
, 0, 0);
559 SendMessage(hwndEditor
, EM_SETMODIFY
, 1, 0);
563 SendMessage(hwndEditor
, EM_UNDO
, 0, 0);
567 SendMessage(hwndEditor
, EM_REDO
, 0, 0);
571 case ID_ALIGN_CENTER
:
576 pf
.cbSize
= sizeof(pf
);
577 pf
.dwMask
= PFM_ALIGNMENT
;
578 switch(LOWORD(wParam
)) {
579 case ID_ALIGN_LEFT
: pf
.wAlignment
= PFA_LEFT
; break;
580 case ID_ALIGN_CENTER
: pf
.wAlignment
= PFA_CENTER
; break;
581 case ID_ALIGN_RIGHT
: pf
.wAlignment
= PFA_RIGHT
; break;
583 SendMessage(hwndEditor
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
588 SendMessage(hwndEditor
, EM_SETBKGNDCOLOR
, 1, 0);
592 SendMessage(hwndEditor
, EM_SETBKGNDCOLOR
, 0, RGB(255,255,192));
596 SendMessage(hwndEditor
, WM_COMMAND
, wParam
, lParam
);
602 static LRESULT
OnInitPopupMenu( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
604 HMENU hMenu
= (HMENU
)wParam
;
605 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
609 pf
.cbSize
= sizeof(PARAFORMAT
);
610 SendMessage(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
611 CheckMenuItem(hMenu
, ID_EDIT_READONLY
,
612 MF_BYCOMMAND
|(GetWindowLong(hwndEditor
, GWL_STYLE
)&ES_READONLY
? MF_CHECKED
: MF_UNCHECKED
));
613 CheckMenuItem(hMenu
, ID_EDIT_MODIFIED
,
614 MF_BYCOMMAND
|(SendMessage(hwndEditor
, EM_GETMODIFY
, 0, 0) ? MF_CHECKED
: MF_UNCHECKED
));
615 if (pf
.dwMask
& PFM_ALIGNMENT
)
616 nAlignment
= pf
.wAlignment
;
617 CheckMenuItem(hMenu
, ID_ALIGN_LEFT
, MF_BYCOMMAND
|(nAlignment
== PFA_LEFT
) ? MF_CHECKED
: MF_UNCHECKED
);
618 CheckMenuItem(hMenu
, ID_ALIGN_CENTER
, MF_BYCOMMAND
|(nAlignment
== PFA_CENTER
) ? MF_CHECKED
: MF_UNCHECKED
);
619 CheckMenuItem(hMenu
, ID_ALIGN_RIGHT
, MF_BYCOMMAND
|(nAlignment
== PFA_RIGHT
) ? MF_CHECKED
: MF_UNCHECKED
);
620 EnableMenuItem(hMenu
, ID_EDIT_UNDO
, MF_BYCOMMAND
|(SendMessage(hwndEditor
, EM_CANUNDO
, 0, 0)) ? MF_ENABLED
: MF_GRAYED
);
621 EnableMenuItem(hMenu
, ID_EDIT_REDO
, MF_BYCOMMAND
|(SendMessage(hwndEditor
, EM_CANREDO
, 0, 0)) ? MF_ENABLED
: MF_GRAYED
);
625 static LRESULT
OnSize( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
627 int nStatusSize
= 0, nTBSize
= 0;
629 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
630 HWND hwndStatusBar
= GetDlgItem(hWnd
, IDC_STATUSBAR
);
631 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
632 HWND hwndToolBar
= GetDlgItem(hwndReBar
, IDC_TOOLBAR
);
636 SendMessage(hwndStatusBar
, WM_SIZE
, 0, 0);
637 GetClientRect(hwndStatusBar
, &rc
);
638 nStatusSize
= rc
.bottom
- rc
.top
;
642 rc
.left
= rc
.top
= 0;
643 rc
.right
= LOWORD(lParam
);
644 rc
.bottom
= HIWORD(lParam
);
645 SendMessage(hwndToolBar
, TB_AUTOSIZE
, 0, 0);
646 SendMessage(hwndReBar
, RB_SIZETORECT
, 0, (LPARAM
)&rc
);
647 nTBSize
= SendMessage(hwndReBar
, RB_GETBARHEIGHT
, 0, 0);
648 GetClientRect(hwndReBar
, &rc
);
649 MoveWindow(hwndReBar
, 0, 0, LOWORD(lParam
), rc
.right
, FALSE
);
653 GetClientRect(hWnd
, &rc
);
654 MoveWindow(hwndEditor
, 0, nTBSize
, rc
.right
, rc
.bottom
-nStatusSize
-nTBSize
, TRUE
);
657 return DefWindowProcW(hWnd
, WM_SIZE
, wParam
, lParam
);
660 static LRESULT CALLBACK
WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
665 return OnCreate( hWnd
, wParam
, lParam
);
668 return OnUser( hWnd
, wParam
, lParam
);
671 return OnNotify( hWnd
, wParam
, lParam
);
674 return OnCommand( hWnd
, wParam
, lParam
);
682 SetFocus(GetDlgItem(hWnd
, IDC_EDITOR
));
685 case WM_INITMENUPOPUP
:
686 return OnInitPopupMenu( hWnd
, wParam
, lParam
);
689 return OnSize( hWnd
, wParam
, lParam
);
692 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
698 int CALLBACK
WinMain(HINSTANCE hInstance
, HINSTANCE hOldInstance
, LPSTR szCmdParagraph
, int res
)
700 INITCOMMONCONTROLSEX classes
= {8, ICC_BAR_CLASSES
|ICC_COOL_CLASSES
};
705 InitCommonControlsEx(&classes
);
707 hAccel
= LoadAccelerators(hInstance
, "MAINACCELTABLE");
709 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
710 wc
.lpfnWndProc
= WndProc
;
713 wc
.hInstance
= hInstance
;
715 wc
.hCursor
= LoadCursor(NULL
, IDC_IBEAM
);
716 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
717 wc
.lpszMenuName
= xszMainMenu
;
718 wc
.lpszClassName
= wszMainWndClass
;
721 hMainWnd
= CreateWindowExW(0, wszMainWndClass
, wszAppTitle
, WS_OVERLAPPEDWINDOW
,
722 CW_USEDEFAULT
, CW_USEDEFAULT
, 680, 260, NULL
, NULL
, hInstance
, NULL
);
723 ShowWindow(hMainWnd
, SW_SHOWDEFAULT
);
725 HandleCommandLine(GetCommandLineW());
727 while(GetMessage(&msg
,0,0,0))
729 if (TranslateAccelerator(hMainWnd
, hAccel
, &msg
))
731 TranslateMessage(&msg
);
732 DispatchMessage(&msg
);
733 if (!PeekMessage(&msg
, 0, 0, 0, PM_NOREMOVE
))
734 SendMessage(hMainWnd
, WM_USER
, 0, 0);