2 * Wordpad implementation
4 * Copyright 2004 by Krzysztof Foltman
5 * Copyright 2007 by Alexander N. Sørnes <alex@thehandofagony.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WIN32_LEAN_AND_MEAN
23 #define _WIN32_IE 0x0400
25 #define MAX_STRING_LEN 255
43 #ifdef NONAMELESSUNION
54 static const WCHAR xszAppTitle
[] = {'W','i','n','e',' ','W','o','r','d','p','a','d',0};
55 static const WCHAR xszMainMenu
[] = {'M','A','I','N','M','E','N','U',0};
57 static const WCHAR wszRichEditClass
[] = {'R','I','C','H','E','D','I','T','2','0','W',0};
58 static const WCHAR wszMainWndClass
[] = {'W','O','R','D','P','A','D','T','O','P',0};
59 static const WCHAR wszAppTitle
[] = {'W','i','n','e',' ','W','o','r','d','p','a','d',0};
61 static const WCHAR key_recentfiles
[] = {'R','e','c','e','n','t',' ','f','i','l','e',
62 ' ','l','i','s','t',0};
63 static const WCHAR key_options
[] = {'O','p','t','i','o','n','s',0};
64 static const WCHAR key_rtf
[] = {'R','T','F',0};
65 static const WCHAR key_text
[] = {'T','e','x','t',0};
67 static const WCHAR var_file
[] = {'F','i','l','e','%','d',0};
68 static const WCHAR var_framerect
[] = {'F','r','a','m','e','R','e','c','t',0};
69 static const WCHAR var_barstate0
[] = {'B','a','r','S','t','a','t','e','0',0};
70 static const WCHAR var_pagemargin
[] = {'P','a','g','e','M','a','r','g','i','n',0};
72 static const WCHAR stringFormat
[] = {'%','2','d','\0'};
75 static HWND hEditorWnd
;
77 static HMENU hPopupMenu
;
79 static UINT ID_FINDMSGSTRING
;
81 static WCHAR wszFilter
[MAX_STRING_LEN
*4+6*3+5];
82 static WCHAR wszDefaultFileName
[MAX_STRING_LEN
];
83 static WCHAR wszSaveChanges
[MAX_STRING_LEN
];
84 static WCHAR wszPrintFilter
[MAX_STRING_LEN
*2+6+4+1];
85 static WCHAR units_cmW
[MAX_STRING_LEN
];
87 static char units_cmA
[MAX_STRING_LEN
];
89 static LRESULT
OnSize( HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
91 /* Load string resources */
92 static void DoLoadStrings(void)
95 static const WCHAR files_rtf
[] = {'*','.','r','t','f','\0'};
96 static const WCHAR files_txt
[] = {'*','.','t','x','t','\0'};
97 static const WCHAR files_all
[] = {'*','.','*','\0'};
98 static const WCHAR files_prn
[] = {'*','.','P','R','N',0};
99 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
101 LoadStringW(hInstance
, STRING_RICHTEXT_FILES_RTF
, p
, MAX_STRING_LEN
);
102 p
+= lstrlenW(p
) + 1;
103 lstrcpyW(p
, files_rtf
);
104 p
+= lstrlenW(p
) + 1;
105 LoadStringW(hInstance
, STRING_TEXT_FILES_TXT
, p
, MAX_STRING_LEN
);
106 p
+= lstrlenW(p
) + 1;
107 lstrcpyW(p
, files_txt
);
108 p
+= lstrlenW(p
) + 1;
109 LoadStringW(hInstance
, STRING_TEXT_FILES_UNICODE_TXT
, p
, MAX_STRING_LEN
);
110 p
+= lstrlenW(p
) + 1;
111 lstrcpyW(p
, files_txt
);
112 p
+= lstrlenW(p
) + 1;
113 LoadStringW(hInstance
, STRING_ALL_FILES
, p
, MAX_STRING_LEN
);
114 p
+= lstrlenW(p
) + 1;
115 lstrcpyW(p
, files_all
);
116 p
+= lstrlenW(p
) + 1;
120 LoadStringW(hInstance
, STRING_PRINTER_FILES_PRN
, p
, MAX_STRING_LEN
);
121 p
+= lstrlenW(p
) + 1;
122 lstrcpyW(p
, files_prn
);
123 p
+= lstrlenW(p
) + 1;
124 LoadStringW(hInstance
, STRING_ALL_FILES
, p
, MAX_STRING_LEN
);
125 p
+= lstrlenW(p
) + 1;
126 lstrcpyW(p
, files_all
);
127 p
+= lstrlenW(p
) + 1;
130 p
= wszDefaultFileName
;
131 LoadStringW(hInstance
, STRING_DEFAULT_FILENAME
, p
, MAX_STRING_LEN
);
134 LoadStringW(hInstance
, STRING_PROMPT_SAVE_CHANGES
, p
, MAX_STRING_LEN
);
136 LoadStringA(hInstance
, STRING_UNITS_CM
, units_cmA
, MAX_STRING_LEN
);
137 LoadStringW(hInstance
, STRING_UNITS_CM
, units_cmW
, MAX_STRING_LEN
);
140 static void AddButton(HWND hwndToolBar
, int nImage
, int nCommand
)
144 ZeroMemory(&button
, sizeof(button
));
145 button
.iBitmap
= nImage
;
146 button
.idCommand
= nCommand
;
147 button
.fsState
= TBSTATE_ENABLED
;
148 button
.fsStyle
= TBSTYLE_BUTTON
;
151 SendMessageW(hwndToolBar
, TB_ADDBUTTONSW
, 1, (LPARAM
)&button
);
154 static void AddTextButton(HWND hWnd
, int string
, int command
, int id
)
157 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
158 static const WCHAR button
[] = {'B','U','T','T','O','N',0};
159 WCHAR text
[MAX_STRING_LEN
];
163 LoadStringW(hInstance
, string
, text
, MAX_STRING_LEN
);
164 hButton
= CreateWindowW(button
, text
,
165 WS_VISIBLE
| WS_CHILD
, 5, 5, 100, 15,
166 hMainWnd
, (HMENU
)command
, hInstance
, NULL
);
168 rb
.cbSize
= sizeof(rb
);
169 rb
.fMask
= RBBIM_SIZE
| RBBIM_CHILDSIZE
| RBBIM_STYLE
| RBBIM_CHILD
| RBBIM_IDEALSIZE
| RBBIM_ID
;
170 rb
.fStyle
= RBBS_NOGRIPPER
| RBBS_VARIABLEHEIGHT
;
171 rb
.hwndChild
= hButton
;
172 rb
.cyChild
= rb
.cyMinChild
= 22;
173 rb
.cx
= rb
.cxMinChild
= 90;
180 SendMessageW(hWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rb
);
181 SetWindowPos(hButton
, 0, 0, 0, 90, 22, SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOZORDER
);
184 static void AddSeparator(HWND hwndToolBar
)
188 ZeroMemory(&button
, sizeof(button
));
190 button
.idCommand
= 0;
192 button
.fsStyle
= TBSTYLE_SEP
;
195 SendMessageW(hwndToolBar
, TB_ADDBUTTONSW
, 1, (LPARAM
)&button
);
198 static DWORD CALLBACK
stream_in(DWORD_PTR cookie
, LPBYTE buffer
, LONG cb
, LONG
*pcb
)
200 HANDLE hFile
= (HANDLE
)cookie
;
203 if(!ReadFile(hFile
, buffer
, cb
, &read
, 0))
211 static DWORD CALLBACK
stream_out(DWORD_PTR cookie
, LPBYTE buffer
, LONG cb
, LONG
*pcb
)
215 HANDLE hFile
= (HANDLE
)cookie
;
217 ret
= WriteFile(hFile
, buffer
, cb
, &written
, 0);
219 if(!ret
|| (cb
!= written
))
228 static LPWSTR
file_basename(LPWSTR path
)
230 LPWSTR pos
= path
+ lstrlenW(path
);
234 if(*pos
== '\\' || *pos
== '/')
244 static WCHAR wszFileName
[MAX_PATH
];
245 static WPARAM fileFormat
= SF_RTF
;
247 static void set_caption(LPCWSTR wszNewFileName
)
249 static const WCHAR wszSeparator
[] = {' ','-',' '};
254 wszNewFileName
= wszDefaultFileName
;
256 wszNewFileName
= file_basename((LPWSTR
)wszNewFileName
);
258 wszCaption
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
259 lstrlenW(wszNewFileName
)*sizeof(WCHAR
)+sizeof(wszSeparator
)+sizeof(wszAppTitle
));
264 memcpy(wszCaption
, wszNewFileName
, lstrlenW(wszNewFileName
)*sizeof(WCHAR
));
265 length
+= lstrlenW(wszNewFileName
);
266 memcpy(wszCaption
+ length
, wszSeparator
, sizeof(wszSeparator
));
267 length
+= sizeof(wszSeparator
) / sizeof(WCHAR
);
268 memcpy(wszCaption
+ length
, wszAppTitle
, sizeof(wszAppTitle
));
270 SetWindowTextW(hMainWnd
, wszCaption
);
272 HeapFree(GetProcessHeap(), 0, wszCaption
);
275 static LRESULT
registry_get_handle(HKEY
*hKey
, LPDWORD action
, LPCWSTR subKey
)
278 static const WCHAR wszProgramKey
[] = {'S','o','f','t','w','a','r','e','\\',
279 'M','i','c','r','o','s','o','f','t','\\',
280 'W','i','n','d','o','w','s','\\',
281 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
282 'A','p','p','l','e','t','s','\\',
283 'W','o','r','d','p','a','d',0};
284 LPWSTR key
= (LPWSTR
)wszProgramKey
;
288 WCHAR backslash
[] = {'\\',0};
289 key
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
290 (lstrlenW(wszProgramKey
)+lstrlenW(subKey
)+lstrlenW(backslash
)+1)
296 lstrcpyW(key
, wszProgramKey
);
297 lstrcatW(key
, backslash
);
298 lstrcatW(key
, subKey
);
303 ret
= RegCreateKeyExW(HKEY_CURRENT_USER
, key
, 0, NULL
, REG_OPTION_NON_VOLATILE
,
304 KEY_READ
| KEY_WRITE
, NULL
, hKey
, action
);
307 ret
= RegOpenKeyExW(HKEY_CURRENT_USER
, key
, 0, KEY_READ
| KEY_WRITE
, hKey
);
311 HeapFree(GetProcessHeap(), 0, key
);
318 static void registry_set_options(void)
323 if(registry_get_handle(&hKey
, &action
, (LPWSTR
)key_options
) == ERROR_SUCCESS
)
327 GetWindowRect(hMainWnd
, &rc
);
329 RegSetValueExW(hKey
, var_framerect
, 0, REG_BINARY
, (LPBYTE
)&rc
, sizeof(RECT
));
331 RegSetValueExW(hKey
, var_pagemargin
, 0, REG_BINARY
, (LPBYTE
)&margins
, sizeof(RECT
));
335 static RECT
registry_read_winrect(void)
339 DWORD size
= sizeof(RECT
);
341 ZeroMemory(&rc
, sizeof(RECT
));
342 if(registry_get_handle(&hKey
, 0, (LPWSTR
)key_options
) != ERROR_SUCCESS
||
343 RegQueryValueExW(hKey
, var_framerect
, 0, NULL
, (LPBYTE
)&rc
, &size
) !=
344 ERROR_SUCCESS
|| size
!= sizeof(RECT
))
356 static void truncate_path(LPWSTR file
, LPWSTR out
, LPWSTR pos1
, LPWSTR pos2
)
358 static const WCHAR dots
[] = {'.','.','.',0};
367 static void format_filelist_filename(LPWSTR file
, LPWSTR out
)
370 LPWSTR truncpos1
, truncpos2
;
371 WCHAR myDocs
[MAX_STRING_LEN
];
373 SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, SHGFP_TYPE_CURRENT
, (LPWSTR
)&myDocs
);
374 pos_basename
= file_basename(file
);
378 *(pos_basename
-1) = 0;
379 if(!lstrcmpiW(file
, myDocs
) || (lstrlenW(pos_basename
) > FILELIST_ENTRY_LENGTH
))
381 truncpos1
= pos_basename
;
382 *(pos_basename
-1) = '\\';
386 BOOL morespace
= FALSE
;
388 *(pos_basename
-1) = '\\';
390 for(pos
= file
; pos
< pos_basename
; pos
++)
392 if(*pos
== '\\' || *pos
== '/')
396 if((pos
- file
+ lstrlenW(pos_basename
)) > FILELIST_ENTRY_LENGTH
)
404 if((pos
- file
+ lstrlenW(pos_basename
)) > FILELIST_ENTRY_LENGTH
)
413 for(pos
= pos_basename
; pos
>= truncpos1
; pos
--)
415 if(*pos
== '\\' || *pos
== '/')
417 if((truncpos1
- file
+ lstrlenW(pos_basename
) + pos_basename
- pos
) > FILELIST_ENTRY_LENGTH
)
426 if(truncpos1
== pos_basename
)
427 lstrcatW(out
, pos_basename
);
428 else if(truncpos1
== truncpos2
|| !truncpos2
)
431 truncate_path(file
, out
, truncpos1
, truncpos2
? truncpos2
: (pos_basename
-1));
434 static void registry_read_filelist(HWND hMainWnd
)
438 if(registry_get_handle(&hFileKey
, 0, key_recentfiles
) == ERROR_SUCCESS
)
440 WCHAR itemText
[MAX_PATH
+3], buffer
[MAX_PATH
];
441 /* The menu item name is not the same as the file name, so we need to store
442 the file name here */
443 static WCHAR file1
[MAX_PATH
], file2
[MAX_PATH
], file3
[MAX_PATH
], file4
[MAX_PATH
];
444 WCHAR numFormat
[] = {'&','%','d',' ',0};
445 LPWSTR pFile
[] = {file1
, file2
, file3
, file4
};
446 DWORD pathSize
= MAX_PATH
*sizeof(WCHAR
);
450 HMENU hMenu
= GetMenu(hMainWnd
);
452 mi
.cbSize
= sizeof(MENUITEMINFOW
);
453 mi
.fMask
= MIIM_ID
| MIIM_DATA
| MIIM_STRING
| MIIM_FTYPE
;
454 mi
.fType
= MFT_STRING
;
455 mi
.dwTypeData
= itemText
;
456 mi
.wID
= ID_FILE_RECENT1
;
458 RemoveMenu(hMenu
, ID_FILE_RECENT_SEPARATOR
, MF_BYCOMMAND
);
459 for(i
= 0; i
< FILELIST_ENTRIES
; i
++)
461 wsprintfW(key
, var_file
, i
+1);
462 RemoveMenu(hMenu
, ID_FILE_RECENT1
+i
, MF_BYCOMMAND
);
463 if(RegQueryValueExW(hFileKey
, (LPWSTR
)key
, 0, NULL
, (LPBYTE
)pFile
[i
], &pathSize
)
467 mi
.dwItemData
= (DWORD
)pFile
[i
];
468 wsprintfW(itemText
, numFormat
, i
+1);
470 lstrcpyW(buffer
, pFile
[i
]);
472 format_filelist_filename(buffer
, itemText
);
474 InsertMenuItemW(hMenu
, ID_FILE_EXIT
, FALSE
, &mi
);
476 pathSize
= MAX_PATH
*sizeof(WCHAR
);
478 mi
.fType
= MFT_SEPARATOR
;
479 mi
.fMask
= MIIM_FTYPE
| MIIM_ID
;
480 InsertMenuItemW(hMenu
, ID_FILE_EXIT
, FALSE
, &mi
);
482 RegCloseKey(hFileKey
);
486 static void registry_set_filelist(LPCWSTR newFile
)
491 if(registry_get_handle(&hKey
, &action
, key_recentfiles
) == ERROR_SUCCESS
)
493 LPCWSTR pFiles
[FILELIST_ENTRIES
];
495 HMENU hMenu
= GetMenu(hMainWnd
);
499 mi
.cbSize
= sizeof(MENUITEMINFOW
);
500 mi
.fMask
= MIIM_DATA
;
502 for(i
= 0; i
< FILELIST_ENTRIES
; i
++)
505 for(i
= 0; GetMenuItemInfoW(hMenu
, ID_FILE_RECENT1
+i
, FALSE
, &mi
); i
++)
506 pFiles
[i
] = (LPWSTR
)mi
.dwItemData
;
508 if(lstrcmpiW(newFile
, pFiles
[0]))
510 for(i
= 0; pFiles
[i
] && i
< FILELIST_ENTRIES
; i
++)
512 if(!lstrcmpiW(pFiles
[i
], newFile
))
515 for(j
= 0; pFiles
[j
] && j
< i
; j
++)
517 pFiles
[i
-j
] = pFiles
[i
-j
-1];
529 for(i
= 0; pFiles
[i
] && i
< FILELIST_ENTRIES
-1; i
++)
530 pFiles
[FILELIST_ENTRIES
-1-i
] = pFiles
[FILELIST_ENTRIES
-2-i
];
535 for(i
= 0; pFiles
[i
] && i
< FILELIST_ENTRIES
; i
++)
537 wsprintfW(buffer
, var_file
, i
+1);
538 RegSetValueExW(hKey
, (LPWSTR
)&buffer
, 0, REG_SZ
, (LPBYTE
)pFiles
[i
],
539 (lstrlenW(pFiles
[i
])+1)*sizeof(WCHAR
));
544 registry_read_filelist(hMainWnd
);
547 static BOOL
validate_endptr(LPCSTR endptr
, BOOL units
)
549 if(!endptr
|| !*endptr
)
552 while(*endptr
== ' ')
556 return *endptr
!= '\0';
558 /* FIXME: Allow other units and convert between them */
559 if(!lstrcmpA(endptr
, units_cmA
))
562 return *endptr
!= '\0';
565 static BOOL
number_from_string(LPCWSTR string
, float *num
, BOOL units
)
568 char buffer
[MAX_STRING_LEN
];
569 char *endptr
= buffer
;
571 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
, MAX_STRING_LEN
, NULL
, NULL
);
574 ret
= strtod(buffer
, &endptr
);
576 if((ret
== 0 && errno
!= 0) || endptr
== buffer
|| validate_endptr(endptr
, units
))
586 static void set_size(float size
)
590 ZeroMemory(&fmt
, sizeof(fmt
));
591 fmt
.cbSize
= sizeof(fmt
);
592 fmt
.dwMask
= CFM_SIZE
;
593 fmt
.yHeight
= (int)(size
* 20.0);
594 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
597 static void add_size(HWND hSizeListWnd
, unsigned size
)
600 COMBOBOXEXITEMW cbItem
;
601 cbItem
.mask
= CBEIF_TEXT
;
604 wsprintfW(buffer
, stringFormat
, size
);
605 cbItem
.pszText
= (LPWSTR
)buffer
;
606 SendMessageW(hSizeListWnd
, CBEM_INSERTITEMW
, 0, (LPARAM
)&cbItem
);
609 static void populate_size_list(HWND hSizeListWnd
)
611 HWND hReBarWnd
= GetDlgItem(hMainWnd
, IDC_REBAR
);
612 HWND hFontListWnd
= GetDlgItem(hReBarWnd
, IDC_FONTLIST
);
613 COMBOBOXEXITEMW cbFontItem
;
615 HWND hListEditWnd
= (HWND
)SendMessageW(hSizeListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
616 HDC hdc
= GetDC(hMainWnd
);
617 static const unsigned choices
[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
622 ZeroMemory(&fmt
, sizeof(fmt
));
623 fmt
.cbSize
= sizeof(fmt
);
624 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
626 cbFontItem
.mask
= CBEIF_LPARAM
;
627 cbFontItem
.iItem
= SendMessageW(hFontListWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)fmt
.szFaceName
);
628 SendMessageW(hFontListWnd
, CBEM_GETITEMW
, 0, (LPARAM
)&cbFontItem
);
630 fontStyle
= (DWORD
)LOWORD(cbFontItem
.lParam
);
632 SendMessageW(hSizeListWnd
, CB_RESETCONTENT
, 0, 0);
634 if((fontStyle
& RASTER_FONTTYPE
) && cbFontItem
.iItem
)
636 add_size(hSizeListWnd
, (BYTE
)MulDiv(HIWORD(cbFontItem
.lParam
), 72,
637 GetDeviceCaps(hdc
, LOGPIXELSY
)));
640 for(i
= 0; i
< sizeof(choices
)/sizeof(choices
[0]); i
++)
641 add_size(hSizeListWnd
, choices
[i
]);
644 wsprintfW(buffer
, stringFormat
, fmt
.yHeight
/ 20);
645 SendMessageW(hListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)buffer
);
648 static void update_size_list(void)
650 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
651 HWND hwndSizeList
= GetDlgItem(hReBar
, IDC_SIZELIST
);
652 HWND hwndSizeListEdit
= (HWND
)SendMessageW(hwndSizeList
, CBEM_GETEDITCONTROL
, 0, 0);
653 WCHAR fontSize
[MAX_STRING_LEN
], sizeBuffer
[MAX_STRING_LEN
];
656 ZeroMemory(&fmt
, sizeof(fmt
));
657 fmt
.cbSize
= sizeof(fmt
);
659 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
661 SendMessageW(hwndSizeListEdit
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)fontSize
);
662 wsprintfW(sizeBuffer
, stringFormat
, fmt
.yHeight
/ 20);
664 if(lstrcmpW(fontSize
, sizeBuffer
))
665 SendMessageW(hwndSizeListEdit
, WM_SETTEXT
, 0, (LPARAM
)sizeBuffer
);
668 static void update_font_list(void)
670 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
671 HWND hFontList
= GetDlgItem(hReBar
, IDC_FONTLIST
);
672 HWND hFontListEdit
= (HWND
)SendMessageW(hFontList
, CBEM_GETEDITCONTROL
, 0, 0);
673 WCHAR fontName
[MAX_STRING_LEN
];
676 ZeroMemory(&fmt
, sizeof(fmt
));
677 fmt
.cbSize
= sizeof(fmt
);
679 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
680 SendMessageW(hFontListEdit
, WM_GETTEXT
, MAX_PATH
, (LPARAM
)fontName
);
682 if(lstrcmpW(fontName
, fmt
.szFaceName
))
684 SendMessageW(hFontListEdit
, WM_SETTEXT
, 0, (LPARAM
)fmt
.szFaceName
);
685 populate_size_list(GetDlgItem(hReBar
, IDC_SIZELIST
));
692 static void clear_formatting(void)
696 pf
.cbSize
= sizeof(pf
);
697 pf
.dwMask
= PFM_ALIGNMENT
;
698 pf
.wAlignment
= PFA_LEFT
;
699 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
702 static int reg_formatindex(WPARAM format
)
704 return (format
& SF_TEXT
) ? 1 : 0;
707 static int fileformat_number(WPARAM format
)
711 if(format
== SF_TEXT
)
714 } else if (format
== (SF_TEXT
| SF_UNICODE
))
721 static WPARAM
fileformat_flags(int format
)
723 WPARAM flags
[] = { SF_RTF
, SF_TEXT
, SF_TEXT
| SF_UNICODE
};
725 return flags
[format
];
728 static void set_font(LPCWSTR wszFaceName
)
730 HWND hReBarWnd
= GetDlgItem(hMainWnd
, IDC_REBAR
);
731 HWND hSizeListWnd
= GetDlgItem(hReBarWnd
, IDC_SIZELIST
);
732 HWND hFontListWnd
= GetDlgItem(hReBarWnd
, IDC_FONTLIST
);
733 HWND hFontListEditWnd
= (HWND
)SendMessageW(hFontListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
736 ZeroMemory(&fmt
, sizeof(fmt
));
738 fmt
.cbSize
= sizeof(fmt
);
739 fmt
.dwMask
= CFM_FACE
;
741 lstrcpyW(fmt
.szFaceName
, wszFaceName
);
743 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
745 populate_size_list(hSizeListWnd
);
747 SendMessageW(hFontListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)(LPWSTR
)wszFaceName
);
750 static void set_default_font(void)
752 static const WCHAR richTextFont
[] = {'T','i','m','e','s',' ','N','e','w',' ',
753 'R','o','m','a','n',0};
754 static const WCHAR plainTextFont
[] = {'C','o','u','r','i','e','r',' ','N','e','w',0};
758 ZeroMemory(&fmt
, sizeof(fmt
));
760 fmt
.cbSize
= sizeof(fmt
);
761 fmt
.dwMask
= CFM_FACE
| CFM_BOLD
| CFM_ITALIC
| CFM_UNDERLINE
;
764 if(fileFormat
& SF_RTF
)
767 font
= plainTextFont
;
769 lstrcpyW(fmt
.szFaceName
, font
);
771 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&fmt
);
774 static void add_font(LPWSTR fontName
, DWORD fontType
, HWND hListWnd
, NEWTEXTMETRICEXW
*ntmc
)
776 COMBOBOXEXITEMW cbItem
;
777 WCHAR buffer
[MAX_PATH
];
780 cbItem
.mask
= CBEIF_TEXT
;
781 cbItem
.pszText
= buffer
;
782 cbItem
.cchTextMax
= MAX_STRING_LEN
;
785 while(SendMessageW(hListWnd
, CBEM_GETITEMW
, 0, (LPARAM
)&cbItem
))
787 if(lstrcmpiW(cbItem
.pszText
, fontName
) <= 0)
792 cbItem
.pszText
= fontName
;
794 cbItem
.mask
|= CBEIF_LPARAM
;
795 if(fontType
& RASTER_FONTTYPE
)
796 fontHeight
= ntmc
->ntmTm
.tmHeight
- ntmc
->ntmTm
.tmInternalLeading
;
798 cbItem
.lParam
= MAKELONG(fontType
,fontHeight
);
799 SendMessageW(hListWnd
, CBEM_INSERTITEMW
, 0, (LPARAM
)&cbItem
);
802 static void dialog_choose_font(void)
807 HDC hDC
= GetDC(hMainWnd
);
809 ZeroMemory(&cf
, sizeof(cf
));
810 cf
.lStructSize
= sizeof(cf
);
811 cf
.hwndOwner
= hMainWnd
;
813 cf
.Flags
= CF_SCREENFONTS
| CF_NOSCRIPTSEL
| CF_INITTOLOGFONTSTRUCT
| CF_EFFECTS
;
815 ZeroMemory(&fmt
, sizeof(fmt
));
816 fmt
.cbSize
= sizeof(fmt
);
818 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
819 lstrcpyW(cf
.lpLogFont
->lfFaceName
, fmt
.szFaceName
);
820 cf
.lpLogFont
->lfItalic
= (fmt
.dwEffects
& CFE_ITALIC
) ? TRUE
: FALSE
;
821 cf
.lpLogFont
->lfWeight
= (fmt
.dwEffects
& CFE_BOLD
) ? FW_BOLD
: FW_NORMAL
;
822 cf
.lpLogFont
->lfUnderline
= (fmt
.dwEffects
& CFE_UNDERLINE
) ? TRUE
: FALSE
;
823 cf
.lpLogFont
->lfStrikeOut
= (fmt
.dwEffects
& CFE_STRIKEOUT
) ? TRUE
: FALSE
;
824 cf
.lpLogFont
->lfHeight
= -MulDiv(fmt
.yHeight
/ 20, GetDeviceCaps(hDC
, LOGPIXELSY
), 72);
825 cf
.rgbColors
= fmt
.crTextColor
;
829 ZeroMemory(&fmt
, sizeof(fmt
));
830 fmt
.cbSize
= sizeof(fmt
);
831 fmt
.dwMask
= CFM_BOLD
| CFM_ITALIC
| CFM_SIZE
| CFM_UNDERLINE
| CFM_STRIKEOUT
| CFM_COLOR
;
832 fmt
.yHeight
= cf
.iPointSize
* 2;
834 if(cf
.nFontType
& BOLD_FONTTYPE
)
835 fmt
.dwEffects
|= CFE_BOLD
;
836 if(cf
.nFontType
& ITALIC_FONTTYPE
)
837 fmt
.dwEffects
|= CFE_ITALIC
;
838 if(cf
.lpLogFont
->lfUnderline
== TRUE
)
839 fmt
.dwEffects
|= CFE_UNDERLINE
;
840 if(cf
.lpLogFont
->lfStrikeOut
== TRUE
)
841 fmt
.dwEffects
|= CFE_STRIKEOUT
;
843 fmt
.crTextColor
= cf
.rgbColors
;
845 SendMessageW(hEditorWnd
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
846 set_font(cf
.lpLogFont
->lfFaceName
);
851 int CALLBACK
enum_font_proc(const LOGFONTW
*lpelfe
, const TEXTMETRICW
*lpntme
,
852 DWORD FontType
, LPARAM lParam
)
854 HWND hListWnd
= (HWND
) lParam
;
856 if(SendMessageW(hListWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)lpelfe
->lfFaceName
) == CB_ERR
)
859 add_font((LPWSTR
)lpelfe
->lfFaceName
, FontType
, hListWnd
, (NEWTEXTMETRICEXW
*)lpntme
);
865 static void populate_font_list(HWND hListWnd
)
867 HDC hdc
= GetDC(hMainWnd
);
869 HWND hListEditWnd
= (HWND
)SendMessageW(hListWnd
, CBEM_GETEDITCONTROL
, 0, 0);
872 fontinfo
.lfCharSet
= DEFAULT_CHARSET
;
873 *fontinfo
.lfFaceName
= '\0';
874 fontinfo
.lfPitchAndFamily
= 0;
876 EnumFontFamiliesExW(hdc
, &fontinfo
, enum_font_proc
,
877 (LPARAM
)hListWnd
, 0);
879 ZeroMemory(&fmt
, sizeof(fmt
));
880 fmt
.cbSize
= sizeof(fmt
);
881 SendMessageW(hEditorWnd
, EM_GETCHARFORMAT
, SCF_DEFAULT
, (LPARAM
)&fmt
);
882 SendMessageW(hListEditWnd
, WM_SETTEXT
, 0, (LPARAM
)fmt
.szFaceName
);
885 static void update_window(void)
889 GetWindowRect(hMainWnd
, &rect
);
891 (void) OnSize(hMainWnd
, SIZE_RESTORED
, MAKELONG(rect
.bottom
, rect
.right
));
894 static DWORD barState
[2];
895 static DWORD wordWrap
[2];
897 static BOOL
is_bar_visible(int bandId
)
899 return barState
[reg_formatindex(fileFormat
)] & (1 << bandId
);
902 static void store_bar_state(int bandId
, BOOL show
)
904 int formatIndex
= reg_formatindex(fileFormat
);
907 barState
[formatIndex
] |= (1 << bandId
);
909 barState
[formatIndex
] &= ~(1 << bandId
);
912 static void set_toolbar_state(int bandId
, BOOL show
)
914 HWND hwndReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
916 SendMessageW(hwndReBar
, RB_SHOWBAND
, SendMessageW(hwndReBar
, RB_IDTOINDEX
, bandId
, 0), show
);
918 if(bandId
== BANDID_TOOLBAR
)
920 REBARBANDINFOW rbbinfo
;
921 int index
= SendMessageW(hwndReBar
, RB_IDTOINDEX
, BANDID_FONTLIST
, 0);
923 rbbinfo
.cbSize
= sizeof(rbbinfo
);
924 rbbinfo
.fMask
= RBBIM_STYLE
;
926 SendMessageW(hwndReBar
, RB_GETBANDINFO
, index
, (LPARAM
)&rbbinfo
);
929 rbbinfo
.fStyle
&= ~RBBS_BREAK
;
931 rbbinfo
.fStyle
|= RBBS_BREAK
;
933 SendMessageW(hwndReBar
, RB_SETBANDINFO
, index
, (LPARAM
)&rbbinfo
);
936 if(bandId
== BANDID_TOOLBAR
|| bandId
== BANDID_FORMATBAR
)
937 store_bar_state(bandId
, show
);
940 static void set_statusbar_state(BOOL show
)
942 HWND hStatusWnd
= GetDlgItem(hMainWnd
, IDC_STATUSBAR
);
944 ShowWindow(hStatusWnd
, show
? SW_SHOW
: SW_HIDE
);
945 store_bar_state(BANDID_STATUSBAR
, show
);
948 static void set_bar_states(void)
950 set_toolbar_state(BANDID_TOOLBAR
, is_bar_visible(BANDID_TOOLBAR
));
951 set_toolbar_state(BANDID_FONTLIST
, is_bar_visible(BANDID_FORMATBAR
));
952 set_toolbar_state(BANDID_SIZELIST
, is_bar_visible(BANDID_FORMATBAR
));
953 set_toolbar_state(BANDID_FORMATBAR
, is_bar_visible(BANDID_FORMATBAR
));
954 set_statusbar_state(is_bar_visible(BANDID_STATUSBAR
));
959 static HGLOBAL devMode
;
960 static HGLOBAL devNames
;
962 static HDC
make_dc(void)
964 if(devNames
&& devMode
)
966 LPDEVNAMES dn
= GlobalLock(devNames
);
967 LPDEVMODEW dm
= GlobalLock(devMode
);
970 ret
= CreateDCW((LPWSTR
)dn
+ dn
->wDriverOffset
,
971 (LPWSTR
)dn
+ dn
->wDeviceOffset
, 0, dm
);
983 static LONG
twips_to_pixels(int twips
, int dpi
)
985 float ret
= ((float)twips
/ ((float)567 * 2.54)) * (float)dpi
;
989 static LONG
devunits_to_twips(int units
, int dpi
)
991 float ret
= ((float)units
/ (float)dpi
) * (float)567 * 2.54;
995 static LONG
centmm_to_twips(int mm
)
997 return MulDiv(mm
, 567, 1000);
1000 static LONG
twips_to_centmm(int twips
)
1002 return MulDiv(twips
, 1000, 567);
1005 static RECT
get_print_rect(HDC hdc
)
1012 int dpiY
= GetDeviceCaps(hdc
, LOGPIXELSY
);
1013 int dpiX
= GetDeviceCaps(hdc
, LOGPIXELSX
);
1014 width
= devunits_to_twips(GetDeviceCaps(hdc
, PHYSICALWIDTH
), dpiX
);
1015 height
= devunits_to_twips(GetDeviceCaps(hdc
, PHYSICALHEIGHT
), dpiY
);
1018 width
= centmm_to_twips(18500);
1019 height
= centmm_to_twips(27000);
1022 rc
.left
= margins
.left
;
1023 rc
.right
= width
- margins
.right
;
1024 rc
.top
= margins
.top
;
1025 rc
.bottom
= height
- margins
.bottom
;
1030 static void target_device(void)
1032 HDC hdc
= make_dc();
1034 int index
= reg_formatindex(fileFormat
);
1036 if(wordWrap
[index
] == ID_WORDWRAP_MARGIN
)
1038 RECT rc
= get_print_rect(hdc
);
1044 HDC hMaindc
= GetDC(hMainWnd
);
1045 hdc
= CreateCompatibleDC(hMaindc
);
1046 ReleaseDC(hMainWnd
, hMaindc
);
1049 SendMessageW(hEditorWnd
, EM_SETTARGETDEVICE
, (WPARAM
)hdc
, width
);
1054 static void set_fileformat(WPARAM format
)
1057 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
1058 fileFormat
= format
;
1060 if(format
& SF_TEXT
)
1061 hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_TXT
));
1063 hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_RTF
));
1065 SendMessageW(hMainWnd
, WM_SETICON
, ICON_BIG
, (LPARAM
)hIcon
);
1072 static void DoOpenFile(LPCWSTR szOpenFileName
)
1078 WPARAM format
= SF_TEXT
;
1080 hFile
= CreateFileW(szOpenFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
1081 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1082 if (hFile
== INVALID_HANDLE_VALUE
)
1085 ReadFile(hFile
, fileStart
, 5, &readOut
, NULL
);
1086 SetFilePointer(hFile
, 0, NULL
, FILE_BEGIN
);
1088 if(readOut
>= 2 && (BYTE
)fileStart
[0] == 0xff && (BYTE
)fileStart
[1] == 0xfe)
1090 format
= SF_TEXT
| SF_UNICODE
;
1091 SetFilePointer(hFile
, 2, NULL
, FILE_BEGIN
);
1092 } else if(readOut
>= 5)
1094 static const char header
[] = "{\\rtf";
1095 static const BYTE STG_magic
[] = { 0xd0,0xcf,0x11,0xe0 };
1097 if(!memcmp(header
, fileStart
, 5))
1099 else if (!memcmp(STG_magic
, fileStart
, sizeof(STG_magic
)))
1102 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_OLE_STORAGE_NOT_SUPPORTED
), wszAppTitle
,
1103 MB_OK
| MB_ICONEXCLAMATION
);
1108 es
.dwCookie
= (DWORD_PTR
)hFile
;
1109 es
.pfnCallback
= stream_in
;
1112 set_fileformat(format
);
1113 SendMessageW(hEditorWnd
, EM_STREAMIN
, format
, (LPARAM
)&es
);
1117 SetFocus(hEditorWnd
);
1119 set_caption(szOpenFileName
);
1121 lstrcpyW(wszFileName
, szOpenFileName
);
1122 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
1123 registry_set_filelist(szOpenFileName
);
1127 static void DoSaveFile(LPCWSTR wszSaveFileName
, WPARAM format
)
1133 hFile
= CreateFileW(wszSaveFileName
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
1134 FILE_ATTRIBUTE_NORMAL
, NULL
);
1136 if(hFile
== INVALID_HANDLE_VALUE
)
1139 if(format
== (SF_TEXT
| SF_UNICODE
))
1141 static const BYTE unicode
[] = {0xff,0xfe};
1143 WriteFile(hFile
, &unicode
, sizeof(unicode
), &writeOut
, 0);
1145 if(writeOut
!= sizeof(unicode
))
1149 stream
.dwCookie
= (DWORD_PTR
)hFile
;
1150 stream
.pfnCallback
= stream_out
;
1152 ret
= SendMessageW(hEditorWnd
, EM_STREAMOUT
, format
, (LPARAM
)&stream
);
1156 SetFocus(hEditorWnd
);
1161 gt
.flags
= GTL_DEFAULT
;
1164 if(SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0))
1168 lstrcpyW(wszFileName
, wszSaveFileName
);
1169 set_caption(wszFileName
);
1170 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
1171 set_fileformat(format
);
1174 static void DialogSaveFile(void)
1178 WCHAR wszFile
[MAX_PATH
] = {'\0'};
1179 static const WCHAR wszDefExt
[] = {'r','t','f','\0'};
1181 ZeroMemory(&sfn
, sizeof(sfn
));
1183 sfn
.lStructSize
= sizeof(sfn
);
1184 sfn
.Flags
= OFN_HIDEREADONLY
| OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
;
1185 sfn
.hwndOwner
= hMainWnd
;
1186 sfn
.lpstrFilter
= wszFilter
;
1187 sfn
.lpstrFile
= wszFile
;
1188 sfn
.nMaxFile
= MAX_PATH
;
1189 sfn
.lpstrDefExt
= wszDefExt
;
1190 sfn
.nFilterIndex
= fileformat_number(fileFormat
)+1;
1192 while(GetSaveFileNameW(&sfn
))
1194 if(fileformat_flags(sfn
.nFilterIndex
-1) != SF_RTF
)
1196 if(MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_SAVE_LOSEFORMATTING
),
1197 wszAppTitle
, MB_YESNO
| MB_ICONEXCLAMATION
) != IDYES
)
1202 DoSaveFile(sfn
.lpstrFile
, fileformat_flags(sfn
.nFilterIndex
-1));
1207 DoSaveFile(sfn
.lpstrFile
, fileformat_flags(sfn
.nFilterIndex
-1));
1213 static BOOL
prompt_save_changes(void)
1218 gt
.flags
= GTL_NUMCHARS
;
1220 if(!SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0))
1224 if(!SendMessageW(hEditorWnd
, EM_GETMODIFY
, 0, 0))
1229 LPWSTR displayFileName
;
1234 displayFileName
= wszDefaultFileName
;
1236 displayFileName
= file_basename(wszFileName
);
1238 text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1239 (lstrlenW(displayFileName
)+lstrlenW(wszSaveChanges
))*sizeof(WCHAR
));
1244 wsprintfW(text
, wszSaveChanges
, displayFileName
);
1246 ret
= MessageBoxW(hMainWnd
, text
, wszAppTitle
, MB_YESNOCANCEL
| MB_ICONEXCLAMATION
);
1248 HeapFree(GetProcessHeap(), 0, text
);
1257 DoSaveFile(wszFileName
, fileFormat
);
1268 static void DialogOpenFile(void)
1272 WCHAR wszFile
[MAX_PATH
] = {'\0'};
1273 static const WCHAR wszDefExt
[] = {'r','t','f','\0'};
1275 ZeroMemory(&ofn
, sizeof(ofn
));
1277 ofn
.lStructSize
= sizeof(ofn
);
1278 ofn
.Flags
= OFN_HIDEREADONLY
| OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
;
1279 ofn
.hwndOwner
= hMainWnd
;
1280 ofn
.lpstrFilter
= wszFilter
;
1281 ofn
.lpstrFile
= wszFile
;
1282 ofn
.nMaxFile
= MAX_PATH
;
1283 ofn
.lpstrDefExt
= wszDefExt
;
1284 ofn
.nFilterIndex
= fileformat_number(fileFormat
)+1;
1286 if(GetOpenFileNameW(&ofn
))
1288 if(prompt_save_changes())
1289 DoOpenFile(ofn
.lpstrFile
);
1293 static LPWSTR
dialog_print_to_file(void)
1296 static WCHAR file
[MAX_PATH
] = {'O','U','T','P','U','T','.','P','R','N',0};
1297 static const WCHAR defExt
[] = {'P','R','N',0};
1299 ZeroMemory(&ofn
, sizeof(ofn
));
1301 ofn
.lStructSize
= sizeof(ofn
);
1302 ofn
.Flags
= OFN_PATHMUSTEXIST
| OFN_HIDEREADONLY
| OFN_OVERWRITEPROMPT
;
1303 ofn
.hwndOwner
= hMainWnd
;
1304 ofn
.lpstrFilter
= (LPWSTR
)wszPrintFilter
;
1305 ofn
.lpstrFile
= (LPWSTR
)file
;
1306 ofn
.nMaxFile
= MAX_PATH
;
1307 ofn
.lpstrDefExt
= (LPWSTR
)defExt
;
1309 if(GetSaveFileNameW(&ofn
))
1310 return (LPWSTR
)file
;
1315 static int get_num_pages(FORMATRANGE fr
)
1322 fr
.chrg
.cpMin
= SendMessageW(hEditorWnd
, EM_FORMATRANGE
, TRUE
,
1325 while(fr
.chrg
.cpMin
&& fr
.chrg
.cpMin
< fr
.chrg
.cpMax
);
1330 static void char_from_pagenum(FORMATRANGE
*fr
, int page
)
1334 for(i
= 1; i
<= page
; i
++)
1339 fr
->chrg
.cpMin
= SendMessageW(hEditorWnd
, EM_FORMATRANGE
, TRUE
, (LPARAM
)fr
);
1343 static void print(LPPRINTDLGW pd
)
1347 int printedPages
= 0;
1350 fr
.hdcTarget
= pd
->hDC
;
1352 fr
.rc
= get_print_rect(fr
.hdc
);
1354 fr
.rcPage
.right
= fr
.rc
.right
+ margins
.right
;
1356 fr
.rcPage
.bottom
= fr
.rc
.bottom
+ margins
.bottom
;
1358 ZeroMemory(&di
, sizeof(di
));
1359 di
.cbSize
= sizeof(di
);
1360 di
.lpszDocName
= (LPWSTR
)wszFileName
;
1362 if(pd
->Flags
& PD_PRINTTOFILE
)
1364 di
.lpszOutput
= dialog_print_to_file();
1369 if(pd
->Flags
& PD_SELECTION
)
1371 SendMessageW(hEditorWnd
, EM_EXGETSEL
, 0, (LPARAM
)&fr
.chrg
);
1375 gt
.flags
= GTL_DEFAULT
;
1378 fr
.chrg
.cpMax
= SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0);
1380 if(pd
->Flags
& PD_PAGENUMS
)
1381 char_from_pagenum(&fr
, pd
->nToPage
);
1384 StartDocW(fr
.hdc
, &di
);
1387 if(StartPage(fr
.hdc
) <= 0)
1390 fr
.chrg
.cpMin
= SendMessageW(hEditorWnd
, EM_FORMATRANGE
, TRUE
, (LPARAM
)&fr
);
1392 if(EndPage(fr
.hdc
) <= 0)
1396 if((pd
->Flags
& PD_PAGENUMS
) && (printedPages
> (pd
->nToPage
- pd
->nFromPage
)))
1399 while(fr
.chrg
.cpMin
&& fr
.chrg
.cpMin
< fr
.chrg
.cpMax
);
1402 SendMessageW(hEditorWnd
, EM_FORMATRANGE
, FALSE
, 0);
1406 static void dialog_printsetup(void)
1410 ZeroMemory(&ps
, sizeof(ps
));
1411 ps
.lStructSize
= sizeof(ps
);
1412 ps
.hwndOwner
= hMainWnd
;
1413 ps
.Flags
= PSD_INHUNDREDTHSOFMILLIMETERS
| PSD_MARGINS
;
1414 ps
.rtMargin
.left
= twips_to_centmm(margins
.left
);
1415 ps
.rtMargin
.right
= twips_to_centmm(margins
.right
);
1416 ps
.rtMargin
.top
= twips_to_centmm(margins
.top
);
1417 ps
.rtMargin
.bottom
= twips_to_centmm(margins
.bottom
);
1418 ps
.hDevMode
= devMode
;
1419 ps
.hDevNames
= devNames
;
1421 if(PageSetupDlgW(&ps
))
1423 margins
.left
= centmm_to_twips(ps
.rtMargin
.left
);
1424 margins
.right
= centmm_to_twips(ps
.rtMargin
.right
);
1425 margins
.top
= centmm_to_twips(ps
.rtMargin
.top
);
1426 margins
.bottom
= centmm_to_twips(ps
.rtMargin
.bottom
);
1427 devMode
= ps
.hDevMode
;
1428 devNames
= ps
.hDevNames
;
1433 static void get_default_printer_opts(void)
1436 ZeroMemory(&pd
, sizeof(pd
));
1438 ZeroMemory(&pd
, sizeof(pd
));
1439 pd
.lStructSize
= sizeof(pd
);
1440 pd
.Flags
= PD_RETURNDC
| PD_RETURNDEFAULT
;
1441 pd
.hwndOwner
= hMainWnd
;
1442 pd
.hDevMode
= devMode
;
1446 devMode
= pd
.hDevMode
;
1447 devNames
= pd
.hDevNames
;
1450 static void print_quick(void)
1454 ZeroMemory(&pd
, sizeof(pd
));
1460 static void dialog_print(void)
1466 ZeroMemory(&pd
, sizeof(pd
));
1467 pd
.lStructSize
= sizeof(pd
);
1468 pd
.hwndOwner
= hMainWnd
;
1469 pd
.Flags
= PD_RETURNDC
| PD_USEDEVMODECOPIESANDCOLLATE
;
1472 pd
.hDevMode
= devMode
;
1473 pd
.hDevNames
= devNames
;
1475 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
1477 pd
.Flags
|= PD_NOSELECTION
;
1481 devMode
= pd
.hDevMode
;
1482 devNames
= pd
.hDevNames
;
1487 typedef struct _previewinfo
1494 } previewinfo
, *ppreviewinfo
;
1496 static previewinfo preview
;
1498 static void preview_bar_show(BOOL show
)
1500 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
1507 AddTextButton(hReBar
, STRING_PREVIEW_PRINT
, ID_PRINT
, BANDID_PREVIEW_BTN1
);
1508 AddTextButton(hReBar
, STRING_PREVIEW_NEXTPAGE
, ID_PREVIEW_NEXTPAGE
, BANDID_PREVIEW_BTN2
);
1509 AddTextButton(hReBar
, STRING_PREVIEW_PREVPAGE
, ID_PREVIEW_PREVPAGE
, BANDID_PREVIEW_BTN3
);
1510 AddTextButton(hReBar
, STRING_PREVIEW_CLOSE
, ID_FILE_EXIT
, BANDID_PREVIEW_BTN4
);
1512 rb
.cbSize
= sizeof(rb
);
1513 rb
.fMask
= RBBIM_SIZE
| RBBIM_CHILDSIZE
| RBBIM_STYLE
| RBBIM_CHILD
| RBBIM_IDEALSIZE
| RBBIM_ID
;
1514 rb
.fStyle
= RBBS_NOGRIPPER
| RBBS_VARIABLEHEIGHT
;
1515 rb
.cyChild
= rb
.cyMinChild
= 22;
1516 rb
.cx
= rb
.cxMinChild
= 90;
1518 rb
.wID
= BANDID_PREVIEW_BUFFER
;
1520 SendMessageW(hReBar
, RB_INSERTBAND
, -1, (LPARAM
)&rb
);
1523 for(i
= 0; i
<= PREVIEW_BUTTONS
; i
++)
1524 SendMessageW(hReBar
, RB_DELETEBAND
, SendMessageW(hReBar
, RB_IDTOINDEX
, BANDID_PREVIEW_BTN1
+i
, 0), 0);
1528 static void preview_exit(void)
1530 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
1531 HMENU hMenu
= LoadMenuW(hInstance
, xszMainMenu
);
1534 preview
.window
.right
= 0;
1535 preview
.window
.bottom
= 0;
1538 ShowWindow(hEditorWnd
, TRUE
);
1540 preview_bar_show(FALSE
);
1542 SetMenu(hMainWnd
, hMenu
);
1543 registry_read_filelist(hMainWnd
);
1548 static LRESULT
print_preview(void)
1553 RECT window
, background
;
1554 HBITMAP hBitmapCapture
, hBitmapScaled
;
1555 int bmWidth
, bmHeight
, bmNewWidth
, bmNewHeight
;
1556 float ratioWidth
, ratioHeight
, ratio
;
1557 int xOffset
, yOffset
;
1559 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
1562 hdc
= BeginPaint(hMainWnd
, &ps
);
1563 GetClientRect(hMainWnd
, &window
);
1565 fr
.hdcTarget
= make_dc();
1566 fr
.rc
= get_print_rect(fr
.hdcTarget
);
1569 fr
.rcPage
.bottom
= fr
.rc
.bottom
+ margins
.bottom
;
1570 fr
.rcPage
.right
= fr
.rc
.right
+ margins
.right
;
1572 bmWidth
= twips_to_pixels(fr
.rcPage
.right
, GetDeviceCaps(hdc
, LOGPIXELSX
));
1573 bmHeight
= twips_to_pixels(fr
.rcPage
.bottom
, GetDeviceCaps(hdc
, LOGPIXELSY
));
1575 hBitmapCapture
= CreateCompatibleBitmap(hdc
, bmWidth
, bmHeight
);
1581 preview
.hdc
= CreateCompatibleDC(hdc
);
1582 fr
.hdc
= preview
.hdc
;
1583 gt
.flags
= GTL_DEFAULT
;
1586 fr
.chrg
.cpMax
= SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0);
1589 paper
.right
= bmWidth
;
1591 paper
.bottom
= bmHeight
;
1594 preview
.pages
= get_num_pages(fr
);
1596 SelectObject(preview
.hdc
, hBitmapCapture
);
1598 char_from_pagenum(&fr
, preview
.page
);
1600 FillRect(preview
.hdc
, &paper
, GetStockObject(WHITE_BRUSH
));
1601 SendMessageW(hEditorWnd
, EM_FORMATRANGE
, TRUE
, (LPARAM
)&fr
);
1602 SendMessageW(hEditorWnd
, EM_FORMATRANGE
, FALSE
, 0);
1604 EnableWindow(GetDlgItem(hReBar
, ID_PREVIEW_PREVPAGE
), preview
.page
> 1);
1605 EnableWindow(GetDlgItem(hReBar
, ID_PREVIEW_NEXTPAGE
), preview
.page
< preview
.pages
);
1608 barheight
= SendMessageW(hReBar
, RB_GETBARHEIGHT
, 0, 0);
1609 ratioWidth
= ((float)window
.right
- 20.0) / (float)bmHeight
;
1610 ratioHeight
= ((float)window
.bottom
- 20.0 - (float)barheight
) / (float)bmHeight
;
1612 if(ratioWidth
> ratioHeight
)
1613 ratio
= ratioHeight
;
1617 bmNewWidth
= (int)((float)bmWidth
* ratio
);
1618 bmNewHeight
= (int)((float)bmHeight
* ratio
);
1619 hBitmapScaled
= CreateCompatibleBitmap(hdc
, bmNewWidth
, bmNewHeight
);
1621 xOffset
= ((window
.right
- bmNewWidth
) / 2);
1622 yOffset
= ((window
.bottom
- bmNewHeight
+ barheight
) / 2);
1624 if(window
.right
!= preview
.window
.right
|| window
.bottom
!= preview
.window
.bottom
)
1626 DeleteDC(preview
.hdcSized
),
1627 preview
.hdcSized
= CreateCompatibleDC(hdc
);
1628 SelectObject(preview
.hdcSized
, hBitmapScaled
);
1630 StretchBlt(preview
.hdcSized
, 0, 0, bmNewWidth
, bmNewHeight
, preview
.hdc
, 0, 0, bmWidth
, bmHeight
, SRCCOPY
);
1633 window
.top
= barheight
;
1634 FillRect(hdc
, &window
, GetStockObject(GRAY_BRUSH
));
1636 SelectObject(hdc
, hBitmapScaled
);
1638 background
.left
= xOffset
- 2;
1639 background
.right
= xOffset
+ bmNewWidth
+ 2;
1640 background
.top
= yOffset
- 2;
1641 background
.bottom
= yOffset
+ bmNewHeight
+ 2;
1643 FillRect(hdc
, &background
, GetStockObject(BLACK_BRUSH
));
1645 BitBlt(hdc
, xOffset
, yOffset
, bmNewWidth
, bmNewHeight
, preview
.hdcSized
, 0, 0, SRCCOPY
);
1647 DeleteDC(fr
.hdcTarget
);
1648 preview
.window
= window
;
1650 EndPaint(hMainWnd
, &ps
);
1655 static LRESULT
preview_command(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
1657 switch(LOWORD(wParam
))
1660 PostMessageW(hMainWnd
, WM_CLOSE
, 0, 0);
1663 case ID_PREVIEW_NEXTPAGE
:
1664 case ID_PREVIEW_PREVPAGE
:
1666 HWND hReBar
= GetDlgItem(hMainWnd
, IDC_REBAR
);
1669 if(LOWORD(wParam
) == ID_PREVIEW_NEXTPAGE
)
1675 preview
.window
.right
= 0;
1677 GetClientRect(hMainWnd
, &rc
);
1678 rc
.top
+= SendMessageW(hReBar
, RB_GETBARHEIGHT
, 0, 0);
1679 InvalidateRect(hMainWnd
, &rc
, TRUE
);
1693 static void dialog_about(void)
1695 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
1696 HICON icon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_WORDPAD
));
1697 ShellAboutW(hMainWnd
, wszAppTitle
, 0, icon
);
1700 static INT_PTR CALLBACK
formatopts_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1706 LPPROPSHEETPAGEW ps
= (LPPROPSHEETPAGEW
)lParam
;
1709 HWND hIdWnd
= GetDlgItem(hWnd
, IDC_PAGEFMT_ID
);
1711 sprintf(id
, "%d\n", (int)ps
->lParam
);
1712 SetWindowTextA(hIdWnd
, id
);
1713 if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_WINDOW
)
1714 wrap
= IDC_PAGEFMT_WW
;
1715 else if(wordWrap
[ps
->lParam
] == ID_WORDWRAP_MARGIN
)
1716 wrap
= IDC_PAGEFMT_WM
;
1719 CheckRadioButton(hWnd
, IDC_PAGEFMT_WW
,
1720 IDC_PAGEFMT_WM
, wrap
);
1722 if(barState
[ps
->lParam
] & (1 << BANDID_TOOLBAR
))
1723 CheckDlgButton(hWnd
, IDC_PAGEFMT_TB
, TRUE
);
1724 if(barState
[ps
->lParam
] & (1 << BANDID_FORMATBAR
))
1725 CheckDlgButton(hWnd
, IDC_PAGEFMT_FB
, TRUE
);
1726 if(barState
[ps
->lParam
] & (BANDID_STATUSBAR
))
1727 CheckDlgButton(hWnd
, IDC_PAGEFMT_SB
, TRUE
);
1732 switch(LOWORD(wParam
))
1734 case IDC_PAGEFMT_WW
:
1735 case IDC_PAGEFMT_WM
:
1736 CheckRadioButton(hWnd
, IDC_PAGEFMT_WW
, IDC_PAGEFMT_WM
,
1740 case IDC_PAGEFMT_TB
:
1741 case IDC_PAGEFMT_FB
:
1742 case IDC_PAGEFMT_SB
:
1743 CheckDlgButton(hWnd
, LOWORD(wParam
),
1744 !IsDlgButtonChecked(hWnd
, LOWORD(wParam
)));
1750 LPNMHDR header
= (LPNMHDR
)lParam
;
1751 if(header
->code
== PSN_APPLY
)
1753 HWND hIdWnd
= GetDlgItem(hWnd
, IDC_PAGEFMT_ID
);
1757 GetWindowTextA(hIdWnd
, sid
, 4);
1759 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WW
))
1760 wordWrap
[id
] = ID_WORDWRAP_WINDOW
;
1761 else if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_WM
))
1762 wordWrap
[id
] = ID_WORDWRAP_MARGIN
;
1764 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_TB
))
1765 barState
[id
] |= (1 << BANDID_TOOLBAR
);
1767 barState
[id
] &= ~(1 << BANDID_TOOLBAR
);
1769 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_FB
))
1770 barState
[id
] |= (1 << BANDID_FORMATBAR
);
1772 barState
[id
] &= ~(1 << BANDID_FORMATBAR
);
1774 if(IsDlgButtonChecked(hWnd
, IDC_PAGEFMT_SB
))
1775 barState
[id
] |= (1 << BANDID_STATUSBAR
);
1777 barState
[id
] &= ~(1 << BANDID_STATUSBAR
);
1785 static void dialog_viewproperties(void)
1787 PROPSHEETPAGEW psp
[2];
1788 PROPSHEETHEADERW psh
;
1790 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
1791 LPCPROPSHEETPAGEW ppsp
= (LPCPROPSHEETPAGEW
)&psp
;
1793 psp
[0].dwSize
= sizeof(PROPSHEETPAGEW
);
1794 psp
[0].dwFlags
= PSP_USETITLE
;
1795 U(psp
[0]).pszTemplate
= MAKEINTRESOURCEW(IDD_FORMATOPTS
);
1796 psp
[0].pfnDlgProc
= formatopts_proc
;
1797 psp
[0].hInstance
= hInstance
;
1798 psp
[0].lParam
= reg_formatindex(SF_TEXT
);
1799 psp
[0].pfnCallback
= NULL
;
1800 psp
[0].pszTitle
= MAKEINTRESOURCEW(STRING_VIEWPROPS_TEXT
);
1801 for(i
= 1; i
< sizeof(psp
)/sizeof(psp
[0]); i
++)
1803 psp
[i
].dwSize
= psp
[0].dwSize
;
1804 psp
[i
].dwFlags
= psp
[0].dwFlags
;
1805 U(psp
[i
]).pszTemplate
= U(psp
[0]).pszTemplate
;
1806 psp
[i
].pfnDlgProc
= psp
[0].pfnDlgProc
;
1807 psp
[i
].hInstance
= psp
[0].hInstance
;
1808 psp
[i
].lParam
= reg_formatindex(SF_RTF
);
1809 psp
[i
].pfnCallback
= psp
[0].pfnCallback
;
1810 psp
[i
].pszTitle
= MAKEINTRESOURCEW(STRING_VIEWPROPS_RICHTEXT
);
1813 psh
.dwSize
= sizeof(psh
);
1814 psh
.dwFlags
= PSH_USEICONID
| PSH_PROPSHEETPAGE
| PSH_NOAPPLYNOW
;
1815 psh
.hwndParent
= hMainWnd
;
1816 psh
.hInstance
= hInstance
;
1817 psh
.pszCaption
= MAKEINTRESOURCEW(STRING_VIEWPROPS_TITLE
);
1818 psh
.nPages
= sizeof(psp
)/sizeof(psp
[0]);
1819 U3(psh
).ppsp
= ppsp
;
1820 U(psh
).pszIcon
= MAKEINTRESOURCEW(IDI_WORDPAD
);
1822 if(fileFormat
& SF_RTF
)
1823 U2(psh
).nStartPage
= 1;
1825 U2(psh
).nStartPage
= 0;
1826 PropertySheetW(&psh
);
1831 static void HandleCommandLine(LPWSTR cmdline
)
1836 /* skip white space */
1837 while (*cmdline
== ' ') cmdline
++;
1839 /* skip executable name */
1840 delimiter
= (*cmdline
== '"' ? '"' : ' ');
1842 if (*cmdline
== delimiter
) cmdline
++;
1843 while (*cmdline
&& *cmdline
!= delimiter
) cmdline
++;
1844 if (*cmdline
== delimiter
) cmdline
++;
1846 while (*cmdline
== ' ' || *cmdline
== '-' || *cmdline
== '/')
1850 if (*cmdline
++ == ' ') continue;
1853 if (option
) cmdline
++;
1854 while (*cmdline
== ' ') cmdline
++;
1867 /* file name is passed on the command line */
1868 if (cmdline
[0] == '"')
1871 cmdline
[lstrlenW(cmdline
) - 1] = 0;
1873 DoOpenFile(cmdline
);
1874 InvalidateRect(hMainWnd
, NULL
, FALSE
);
1878 MessageBox(hMainWnd
, "Printing not implemented", "WordPad", MB_OK
);
1881 static LRESULT
handle_findmsg(LPFINDREPLACEW pFr
)
1883 if(pFr
->Flags
& FR_DIALOGTERM
)
1886 pFr
->Flags
= FR_FINDNEXT
;
1890 if(pFr
->Flags
& FR_FINDNEXT
|| pFr
->Flags
& FR_REPLACE
|| pFr
->Flags
& FR_REPLACEALL
)
1892 DWORD flags
= FR_DOWN
;
1894 static CHARRANGE cr
;
1899 HMENU hMenu
= GetMenu(hMainWnd
);
1902 mi
.cbSize
= sizeof(mi
);
1903 mi
.fMask
= MIIM_DATA
;
1905 SetMenuItemInfoW(hMenu
, ID_FIND_NEXT
, FALSE
, &mi
);
1907 gt
.flags
= GTL_NUMCHARS
;
1910 length
= SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0);
1912 if(pFr
->lCustData
== -1)
1914 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&startPos
, (LPARAM
)&end
);
1915 cr
.cpMin
= startPos
;
1916 pFr
->lCustData
= startPos
;
1918 if(cr
.cpMin
== length
)
1922 startPos
= pFr
->lCustData
;
1925 if(cr
.cpMax
> length
)
1933 ft
.lpstrText
= pFr
->lpstrFindWhat
;
1935 if(pFr
->Flags
& FR_MATCHCASE
)
1936 flags
|= FR_MATCHCASE
;
1937 if(pFr
->Flags
& FR_WHOLEWORD
)
1938 flags
|= FR_WHOLEWORD
;
1940 ret
= SendMessageW(hEditorWnd
, EM_FINDTEXTW
, (WPARAM
)flags
, (LPARAM
)&ft
);
1944 if(cr
.cpMax
== length
&& cr
.cpMax
!= startPos
)
1946 ft
.chrg
.cpMin
= cr
.cpMin
= 0;
1947 ft
.chrg
.cpMax
= cr
.cpMax
= startPos
;
1949 ret
= SendMessageW(hEditorWnd
, EM_FINDTEXTW
, (WPARAM
)flags
, (LPARAM
)&ft
);
1955 pFr
->lCustData
= -1;
1956 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_SEARCH_FINISHED
), wszAppTitle
,
1957 MB_OK
| MB_ICONASTERISK
);
1960 end
= ret
+ lstrlenW(pFr
->lpstrFindWhat
);
1962 SendMessageW(hEditorWnd
, EM_SETSEL
, (WPARAM
)ret
, (LPARAM
)end
);
1963 SendMessageW(hEditorWnd
, EM_SCROLLCARET
, 0, 0);
1965 if(pFr
->Flags
& FR_REPLACE
|| pFr
->Flags
& FR_REPLACEALL
)
1966 SendMessageW(hEditorWnd
, EM_REPLACESEL
, TRUE
, (LPARAM
)pFr
->lpstrReplaceWith
);
1968 if(pFr
->Flags
& FR_REPLACEALL
)
1969 handle_findmsg(pFr
);
1976 static void dialog_find(LPFINDREPLACEW fr
, BOOL replace
)
1978 static WCHAR findBuffer
[MAX_STRING_LEN
];
1980 ZeroMemory(fr
, sizeof(FINDREPLACEW
));
1981 fr
->lStructSize
= sizeof(FINDREPLACEW
);
1982 fr
->hwndOwner
= hMainWnd
;
1983 fr
->Flags
= FR_HIDEUPDOWN
;
1984 fr
->lpstrFindWhat
= findBuffer
;
1986 fr
->wFindWhatLen
= MAX_STRING_LEN
*sizeof(WCHAR
);
1989 hFindWnd
= ReplaceTextW(fr
);
1991 hFindWnd
= FindTextW(fr
);
1994 static void registry_read_options(void)
1997 DWORD size
= sizeof(RECT
);
1999 if(registry_get_handle(&hKey
, 0, key_options
) != ERROR_SUCCESS
||
2000 RegQueryValueExW(hKey
, var_pagemargin
, 0, NULL
, (LPBYTE
)&margins
,
2001 &size
) != ERROR_SUCCESS
|| size
!= sizeof(RECT
))
2004 margins
.bottom
= 1417;
2005 margins
.left
= 1757;
2006 margins
.right
= 1757;
2012 static void registry_read_formatopts(int index
, LPCWSTR key
)
2016 BOOL fetched
= FALSE
;
2017 barState
[index
] = 0;
2018 wordWrap
[index
] = 0;
2020 if(registry_get_handle(&hKey
, &action
, key
) != ERROR_SUCCESS
)
2023 if(action
== REG_OPENED_EXISTING_KEY
)
2025 DWORD size
= sizeof(DWORD
);
2027 if(RegQueryValueExW(hKey
, var_barstate0
, 0, NULL
, (LPBYTE
)&barState
[index
],
2028 &size
) == ERROR_SUCCESS
)
2033 barState
[index
] = (1 << BANDID_TOOLBAR
) | (1 << BANDID_FORMATBAR
) | (1 << BANDID_RULER
) | (1 << BANDID_STATUSBAR
);
2035 if(index
== reg_formatindex(SF_RTF
))
2036 wordWrap
[index
] = ID_WORDWRAP_WINDOW
;
2037 else if(index
== reg_formatindex(SF_TEXT
))
2038 wordWrap
[index
] = ID_WORDWRAP_WINDOW
; /* FIXME: should be ID_WORDWRAP_NONE once we support it */
2043 static void registry_read_formatopts_all(void)
2045 registry_read_formatopts(reg_formatindex(SF_RTF
), key_rtf
);
2046 registry_read_formatopts(reg_formatindex(SF_TEXT
), key_text
);
2049 static void registry_set_formatopts(int index
, LPCWSTR key
)
2054 if(registry_get_handle(&hKey
, &action
, key
) == ERROR_SUCCESS
)
2056 RegSetValueExW(hKey
, var_barstate0
, 0, REG_DWORD
, (LPBYTE
)&barState
[index
],
2063 static void registry_set_formatopts_all(void)
2065 registry_set_formatopts(reg_formatindex(SF_RTF
), key_rtf
);
2066 registry_set_formatopts(reg_formatindex(SF_TEXT
), key_text
);
2069 static int current_units_to_twips(float number
)
2071 int twips
= (int)(number
* 567);
2075 static void append_current_units(LPWSTR buffer
)
2077 static const WCHAR space
[] = {' '};
2078 lstrcatW(buffer
, space
);
2079 lstrcatW(buffer
, units_cmW
);
2082 static void number_with_units(LPWSTR buffer
, int number
)
2084 float converted
= (float)number
/ 567;
2085 char string
[MAX_STRING_LEN
];
2087 sprintf(string
, "%.2f ", converted
);
2088 lstrcatA(string
, units_cmA
);
2089 MultiByteToWideChar(CP_ACP
, 0, string
, -1, buffer
, MAX_STRING_LEN
);
2092 BOOL CALLBACK
datetime_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2098 WCHAR buffer
[MAX_STRING_LEN
];
2100 HWND hListWnd
= GetDlgItem(hWnd
, IDC_DATETIME
);
2103 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &st
, 0, (LPWSTR
)&buffer
,
2105 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
2106 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_LONGDATE
, &st
, 0, (LPWSTR
)&buffer
,
2108 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
2109 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, &st
, 0, (LPWSTR
)&buffer
, MAX_STRING_LEN
);
2110 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
2112 SendMessageW(hListWnd
, LB_SETSEL
, TRUE
, 0);
2117 switch(LOWORD(wParam
))
2122 HWND hListWnd
= GetDlgItem(hWnd
, IDC_DATETIME
);
2124 index
= SendMessageW(hListWnd
, LB_GETCURSEL
, 0, 0);
2128 WCHAR buffer
[MAX_STRING_LEN
];
2129 SendMessageW(hListWnd
, LB_GETTEXT
, index
, (LPARAM
)&buffer
);
2130 SendMessageW(hEditorWnd
, EM_REPLACESEL
, TRUE
, (LPARAM
)&buffer
);
2136 EndDialog(hWnd
, wParam
);
2143 BOOL CALLBACK
newfile_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2149 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
, GWLP_HINSTANCE
);
2150 WCHAR buffer
[MAX_STRING_LEN
];
2151 HWND hListWnd
= GetDlgItem(hWnd
, IDC_NEWFILE
);
2153 LoadStringW(hInstance
, STRING_NEWFILE_RICHTEXT
, (LPWSTR
)buffer
, MAX_STRING_LEN
);
2154 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
2155 LoadStringW(hInstance
, STRING_NEWFILE_TXT
, (LPWSTR
)buffer
, MAX_STRING_LEN
);
2156 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
2157 LoadStringW(hInstance
, STRING_NEWFILE_TXT_UNICODE
, (LPWSTR
)buffer
, MAX_STRING_LEN
);
2158 SendMessageW(hListWnd
, LB_ADDSTRING
, 0, (LPARAM
)&buffer
);
2160 SendMessageW(hListWnd
, LB_SETSEL
, TRUE
, 0);
2165 switch(LOWORD(wParam
))
2170 HWND hListWnd
= GetDlgItem(hWnd
, IDC_NEWFILE
);
2171 index
= SendMessageW(hListWnd
, LB_GETCURSEL
, 0, 0);
2174 EndDialog(hWnd
, MAKELONG(fileformat_flags(index
),0));
2179 EndDialog(hWnd
, MAKELONG(ID_NEWFILE_ABORT
,0));
2186 static INT_PTR CALLBACK
paraformat_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2192 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hMainWnd
,
2194 WCHAR buffer
[MAX_STRING_LEN
];
2195 HWND hListWnd
= GetDlgItem(hWnd
, IDC_PARA_ALIGN
);
2196 HWND hLeftWnd
= GetDlgItem(hWnd
, IDC_PARA_LEFT
);
2197 HWND hRightWnd
= GetDlgItem(hWnd
, IDC_PARA_RIGHT
);
2198 HWND hFirstWnd
= GetDlgItem(hWnd
, IDC_PARA_FIRST
);
2202 LoadStringW(hInstance
, STRING_ALIGN_LEFT
, buffer
,
2204 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
2205 LoadStringW(hInstance
, STRING_ALIGN_RIGHT
, buffer
,
2207 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
2208 LoadStringW(hInstance
, STRING_ALIGN_CENTER
, buffer
,
2210 SendMessageW(hListWnd
, CB_ADDSTRING
, 0, (LPARAM
)buffer
);
2212 pf
.cbSize
= sizeof(pf
);
2213 pf
.dwMask
= PFM_ALIGNMENT
| PFM_OFFSET
| PFM_RIGHTINDENT
|
2215 SendMessageW(hEditorWnd
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2217 if(pf
.wAlignment
== PFA_RIGHT
)
2219 else if(pf
.wAlignment
== PFA_CENTER
)
2222 SendMessageW(hListWnd
, CB_SETCURSEL
, index
, 0);
2224 number_with_units(buffer
, pf
.dxOffset
);
2225 SetWindowTextW(hLeftWnd
, buffer
);
2226 number_with_units(buffer
, pf
.dxRightIndent
);
2227 SetWindowTextW(hRightWnd
, buffer
);
2228 number_with_units(buffer
, pf
.dxStartIndent
- pf
.dxOffset
);
2229 SetWindowTextW(hFirstWnd
, buffer
);
2234 switch(LOWORD(wParam
))
2238 HWND hLeftWnd
= GetDlgItem(hWnd
, IDC_PARA_LEFT
);
2239 HWND hRightWnd
= GetDlgItem(hWnd
, IDC_PARA_RIGHT
);
2240 HWND hFirstWnd
= GetDlgItem(hWnd
, IDC_PARA_FIRST
);
2241 WCHAR buffer
[MAX_STRING_LEN
];
2246 GetWindowTextW(hLeftWnd
, buffer
, MAX_STRING_LEN
);
2247 if(number_from_string(buffer
, &num
, TRUE
))
2249 pf
.dxOffset
= current_units_to_twips(num
);
2250 GetWindowTextW(hRightWnd
, buffer
, MAX_STRING_LEN
);
2251 if(number_from_string(buffer
, &num
, TRUE
))
2253 pf
.dxRightIndent
= current_units_to_twips(num
);
2254 GetWindowTextW(hFirstWnd
, buffer
, MAX_STRING_LEN
);
2255 if(number_from_string(buffer
, &num
, TRUE
))
2257 pf
.dxStartIndent
= current_units_to_twips(num
);
2261 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
2262 wszAppTitle
, MB_OK
| MB_ICONASTERISK
);
2266 pf
.dxStartIndent
= pf
.dxStartIndent
+ pf
.dxOffset
;
2267 pf
.cbSize
= sizeof(pf
);
2268 pf
.dwMask
= PFM_OFFSET
| PFM_OFFSETINDENT
| PFM_RIGHTINDENT
;
2269 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2275 EndDialog(hWnd
, wParam
);
2282 static INT_PTR CALLBACK
tabstops_proc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2288 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
2290 WCHAR buffer
[MAX_STRING_LEN
];
2293 pf
.cbSize
= sizeof(pf
);
2294 pf
.dwMask
= PFM_TABSTOPS
;
2295 SendMessageW(hEditorWnd
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2296 SendMessageW(hTabWnd
, CB_LIMITTEXT
, MAX_STRING_LEN
-1, 0);
2298 for(i
= 0; i
< pf
.cTabCount
; i
++)
2300 number_with_units(buffer
, pf
.rgxTabs
[i
]);
2301 SendMessageW(hTabWnd
, CB_ADDSTRING
, 0, (LPARAM
)&buffer
);
2308 switch(LOWORD(wParam
))
2312 HWND hTabWnd
= (HWND
)lParam
;
2313 HWND hAddWnd
= GetDlgItem(hWnd
, ID_TAB_ADD
);
2314 HWND hDelWnd
= GetDlgItem(hWnd
, ID_TAB_DEL
);
2315 HWND hEmptyWnd
= GetDlgItem(hWnd
, ID_TAB_EMPTY
);
2317 if(GetWindowTextLengthW(hTabWnd
))
2318 EnableWindow(hAddWnd
, TRUE
);
2320 EnableWindow(hAddWnd
, FALSE
);
2322 if(SendMessageW(hTabWnd
, CB_GETCOUNT
, 0, 0))
2324 EnableWindow(hEmptyWnd
, TRUE
);
2326 if(SendMessageW(hTabWnd
, CB_GETCURSEL
, 0, 0) == CB_ERR
)
2327 EnableWindow(hDelWnd
, FALSE
);
2329 EnableWindow(hDelWnd
, TRUE
);
2332 EnableWindow(hEmptyWnd
, FALSE
);
2339 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
2340 WCHAR buffer
[MAX_STRING_LEN
];
2342 GetWindowTextW(hTabWnd
, buffer
, MAX_STRING_LEN
);
2343 append_current_units(buffer
);
2345 if(SendMessageW(hTabWnd
, CB_FINDSTRINGEXACT
, -1, (LPARAM
)&buffer
) == CB_ERR
)
2349 if(!number_from_string(buffer
, &number
, TRUE
))
2351 MessageBoxW(hWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
),
2352 wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
2355 SendMessageW(hTabWnd
, CB_ADDSTRING
, 0, (LPARAM
)&buffer
);
2356 SetWindowTextW(hTabWnd
, 0);
2365 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
2367 ret
= SendMessageW(hTabWnd
, CB_GETCURSEL
, 0, 0);
2369 SendMessageW(hTabWnd
, CB_DELETESTRING
, ret
, 0);
2375 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
2376 SendMessageW(hTabWnd
, CB_RESETCONTENT
, 0, 0);
2383 HWND hTabWnd
= GetDlgItem(hWnd
, IDC_TABSTOPS
);
2385 WCHAR buffer
[MAX_STRING_LEN
];
2389 pf
.cbSize
= sizeof(pf
);
2390 pf
.dwMask
= PFM_TABSTOPS
;
2392 for(i
= 0; SendMessageW(hTabWnd
, CB_GETLBTEXT
, i
,
2393 (LPARAM
)&buffer
) != CB_ERR
&&
2394 i
< MAX_TAB_STOPS
; i
++)
2396 number_from_string(buffer
, &number
, TRUE
);
2397 pf
.rgxTabs
[i
] = current_units_to_twips(number
);
2400 SendMessageW(hEditorWnd
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2404 EndDialog(hWnd
, wParam
);
2411 static int context_menu(LPARAM lParam
)
2413 int x
= (int)(short)LOWORD(lParam
);
2414 int y
= (int)(short)HIWORD(lParam
);
2415 HMENU hPop
= GetSubMenu(hPopupMenu
, 0);
2419 int from
= 0, to
= 0;
2421 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
2422 SendMessageW(hEditorWnd
, EM_POSFROMCHAR
, (WPARAM
)&pt
, (LPARAM
)to
);
2423 ClientToScreen(hEditorWnd
, (POINT
*)&pt
);
2428 TrackPopupMenu(hPop
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_RIGHTBUTTON
,
2429 x
, y
, 0, hMainWnd
, 0);
2434 static LRESULT
OnCreate( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2436 HWND hToolBarWnd
, hFormatBarWnd
, hReBarWnd
, hFontListWnd
, hSizeListWnd
;
2437 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2440 int nStdBitmaps
= 0;
2443 static const WCHAR wszRichEditDll
[] = {'R','I','C','H','E','D','2','0','.','D','L','L','\0'};
2444 static const WCHAR wszRichEditText
[] = {'R','i','c','h','E','d','i','t',' ','t','e','x','t','\0'};
2446 CreateStatusWindowW(CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
, wszRichEditText
, hWnd
, IDC_STATUSBAR
);
2448 hReBarWnd
= CreateWindowExW(WS_EX_TOOLWINDOW
, REBARCLASSNAMEW
, NULL
,
2449 CCS_NODIVIDER
|WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|WS_CLIPCHILDREN
|RBS_VARHEIGHT
|CCS_TOP
,
2450 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, hWnd
, (HMENU
)IDC_REBAR
, hInstance
, NULL
);
2452 rbi
.cbSize
= sizeof(rbi
);
2455 if(!SendMessageW(hReBarWnd
, RB_SETBARINFO
, 0, (LPARAM
)&rbi
))
2458 hToolBarWnd
= CreateToolbarEx(hReBarWnd
, CCS_NOPARENTALIGN
|CCS_NOMOVEY
|WS_VISIBLE
|WS_CHILD
|TBSTYLE_TOOLTIPS
|TBSTYLE_BUTTON
,
2460 1, hInstance
, IDB_TOOLBAR
,
2462 24, 24, 16, 16, sizeof(TBBUTTON
));
2464 ab
.hInst
= HINST_COMMCTRL
;
2465 ab
.nID
= IDB_STD_SMALL_COLOR
;
2466 nStdBitmaps
= SendMessageW(hToolBarWnd
, TB_ADDBITMAP
, 0, (LPARAM
)&ab
);
2468 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILENEW
, ID_FILE_NEW
);
2469 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILEOPEN
, ID_FILE_OPEN
);
2470 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FILESAVE
, ID_FILE_SAVE
);
2471 AddSeparator(hToolBarWnd
);
2472 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINT
, ID_PRINT_QUICK
);
2473 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PRINTPRE
, ID_PREVIEW
);
2474 AddSeparator(hToolBarWnd
);
2475 AddButton(hToolBarWnd
, nStdBitmaps
+STD_FIND
, ID_FIND
);
2476 AddSeparator(hToolBarWnd
);
2477 AddButton(hToolBarWnd
, nStdBitmaps
+STD_CUT
, ID_EDIT_CUT
);
2478 AddButton(hToolBarWnd
, nStdBitmaps
+STD_COPY
, ID_EDIT_COPY
);
2479 AddButton(hToolBarWnd
, nStdBitmaps
+STD_PASTE
, ID_EDIT_PASTE
);
2480 AddButton(hToolBarWnd
, nStdBitmaps
+STD_UNDO
, ID_EDIT_UNDO
);
2481 AddButton(hToolBarWnd
, nStdBitmaps
+STD_REDOW
, ID_EDIT_REDO
);
2482 AddSeparator(hToolBarWnd
);
2483 AddButton(hToolBarWnd
, 0, ID_DATETIME
);
2485 SendMessageW(hToolBarWnd
, TB_AUTOSIZE
, 0, 0);
2487 rbb
.cbSize
= sizeof(rbb
);
2488 rbb
.fMask
= RBBIM_SIZE
| RBBIM_CHILDSIZE
| RBBIM_CHILD
| RBBIM_STYLE
| RBBIM_ID
;
2489 rbb
.fStyle
= RBBS_CHILDEDGE
| RBBS_BREAK
| RBBS_NOGRIPPER
;
2491 rbb
.hwndChild
= hToolBarWnd
;
2493 rbb
.cyChild
= rbb
.cyMinChild
= HIWORD(SendMessageW(hToolBarWnd
, TB_GETBUTTONSIZE
, 0, 0));
2494 rbb
.wID
= BANDID_TOOLBAR
;
2496 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
2498 hFontListWnd
= CreateWindowExW(0, WC_COMBOBOXEXW
, NULL
,
2499 WS_BORDER
| WS_VISIBLE
| WS_CHILD
| CBS_DROPDOWN
| CBS_SORT
,
2500 0, 0, 200, 150, hReBarWnd
, (HMENU
)IDC_FONTLIST
, hInstance
, NULL
);
2502 rbb
.hwndChild
= hFontListWnd
;
2504 rbb
.wID
= BANDID_FONTLIST
;
2506 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
2508 hSizeListWnd
= CreateWindowExW(0, WC_COMBOBOXEXW
, NULL
,
2509 WS_BORDER
| WS_VISIBLE
| WS_CHILD
| CBS_DROPDOWN
,
2510 0, 0, 50, 150, hReBarWnd
, (HMENU
)IDC_SIZELIST
, hInstance
, NULL
);
2512 rbb
.hwndChild
= hSizeListWnd
;
2514 rbb
.fStyle
^= RBBS_BREAK
;
2515 rbb
.wID
= BANDID_SIZELIST
;
2517 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
2519 hFormatBarWnd
= CreateToolbarEx(hReBarWnd
,
2520 CCS_NOPARENTALIGN
| CCS_NOMOVEY
| WS_VISIBLE
| TBSTYLE_TOOLTIPS
| TBSTYLE_BUTTON
,
2521 IDC_FORMATBAR
, 7, hInstance
, IDB_FORMATBAR
, NULL
, 0, 16, 16, 16, 16, sizeof(TBBUTTON
));
2523 AddButton(hFormatBarWnd
, 0, ID_FORMAT_BOLD
);
2524 AddButton(hFormatBarWnd
, 1, ID_FORMAT_ITALIC
);
2525 AddButton(hFormatBarWnd
, 2, ID_FORMAT_UNDERLINE
);
2526 AddSeparator(hFormatBarWnd
);
2527 AddButton(hFormatBarWnd
, 3, ID_ALIGN_LEFT
);
2528 AddButton(hFormatBarWnd
, 4, ID_ALIGN_CENTER
);
2529 AddButton(hFormatBarWnd
, 5, ID_ALIGN_RIGHT
);
2530 AddSeparator(hFormatBarWnd
);
2531 AddButton(hFormatBarWnd
, 6, ID_BULLET
);
2533 SendMessageW(hFormatBarWnd
, TB_AUTOSIZE
, 0, 0);
2535 rbb
.hwndChild
= hFormatBarWnd
;
2536 rbb
.wID
= BANDID_FORMATBAR
;
2538 SendMessageW(hReBarWnd
, RB_INSERTBAND
, -1, (LPARAM
)&rbb
);
2540 hDLL
= LoadLibraryW(wszRichEditDll
);
2543 MessageBoxW(hWnd
, MAKEINTRESOURCEW(STRING_LOAD_RICHED_FAILED
), wszAppTitle
,
2544 MB_OK
| MB_ICONEXCLAMATION
);
2548 hEditorWnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, wszRichEditClass
, NULL
,
2549 WS_CHILD
|WS_VISIBLE
|ECO_SELECTIONBAR
|ES_MULTILINE
|ES_AUTOVSCROLL
|ES_WANTRETURN
|WS_VSCROLL
,
2550 0, 0, 1000, 100, hWnd
, (HMENU
)IDC_EDITOR
, hInstance
, NULL
);
2554 fprintf(stderr
, "Error code %u\n", GetLastError());
2559 SetFocus(hEditorWnd
);
2560 SendMessageW(hEditorWnd
, EM_SETEVENTMASK
, 0, ENM_SELCHANGE
);
2564 populate_font_list(hFontListWnd
);
2565 populate_size_list(hSizeListWnd
);
2567 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
2569 ID_FINDMSGSTRING
= RegisterWindowMessageW(FINDMSGSTRINGW
);
2571 registry_read_filelist(hWnd
);
2572 registry_read_formatopts_all();
2573 registry_read_options();
2574 DragAcceptFiles(hWnd
, TRUE
);
2579 static LRESULT
OnUser( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2581 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2582 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
2583 HWND hwndToolBar
= GetDlgItem(hwndReBar
, IDC_TOOLBAR
);
2584 HWND hwndFormatBar
= GetDlgItem(hwndReBar
, IDC_FORMATBAR
);
2590 ZeroMemory(&fmt
, sizeof(fmt
));
2591 fmt
.cbSize
= sizeof(fmt
);
2593 ZeroMemory(&pf
, sizeof(pf
));
2594 pf
.cbSize
= sizeof(pf
);
2596 gt
.flags
= GTL_NUMCHARS
;
2599 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_FIND
,
2600 SendMessageW(hwndEditor
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0) ? 1 : 0);
2602 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, TRUE
, (LPARAM
)&fmt
);
2604 SendMessageW(hwndEditor
, EM_GETSEL
, (WPARAM
)&from
, (LPARAM
)&to
);
2605 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_UNDO
,
2606 SendMessageW(hwndEditor
, EM_CANUNDO
, 0, 0));
2607 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_REDO
,
2608 SendMessageW(hwndEditor
, EM_CANREDO
, 0, 0));
2609 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_CUT
, from
== to
? 0 : 1);
2610 SendMessageW(hwndToolBar
, TB_ENABLEBUTTON
, ID_EDIT_COPY
, from
== to
? 0 : 1);
2612 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_BOLD
, (fmt
.dwMask
& CFM_BOLD
) &&
2613 (fmt
.dwEffects
& CFE_BOLD
));
2614 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_BOLD
, !(fmt
.dwMask
& CFM_BOLD
));
2615 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_ITALIC
, (fmt
.dwMask
& CFM_ITALIC
) &&
2616 (fmt
.dwEffects
& CFE_ITALIC
));
2617 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_ITALIC
, !(fmt
.dwMask
& CFM_ITALIC
));
2618 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_FORMAT_UNDERLINE
, (fmt
.dwMask
& CFM_UNDERLINE
) &&
2619 (fmt
.dwEffects
& CFE_UNDERLINE
));
2620 SendMessageW(hwndFormatBar
, TB_INDETERMINATE
, ID_FORMAT_UNDERLINE
, !(fmt
.dwMask
& CFM_UNDERLINE
));
2622 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2623 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_LEFT
, (pf
.wAlignment
== PFA_LEFT
));
2624 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_CENTER
, (pf
.wAlignment
== PFA_CENTER
));
2625 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_ALIGN_RIGHT
, (pf
.wAlignment
== PFA_RIGHT
));
2627 SendMessageW(hwndFormatBar
, TB_CHECKBUTTON
, ID_BULLET
, (pf
.wNumbering
& PFN_BULLET
));
2631 static LRESULT
OnNotify( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2633 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2634 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
2635 NMHDR
*pHdr
= (NMHDR
*)lParam
;
2636 HWND hwndFontList
= GetDlgItem(hwndReBar
, IDC_FONTLIST
);
2637 HWND hwndSizeList
= GetDlgItem(hwndReBar
, IDC_SIZELIST
);
2638 WCHAR sizeBuffer
[MAX_PATH
];
2640 if (pHdr
->hwndFrom
== hwndFontList
|| pHdr
->hwndFrom
== hwndSizeList
)
2642 if (pHdr
->code
== CBEN_ENDEDITW
)
2644 CHARFORMAT2W format
;
2645 NMCBEENDEDIT
*endEdit
= (NMCBEENDEDIT
*)lParam
;
2647 ZeroMemory(&format
, sizeof(format
));
2648 format
.cbSize
= sizeof(format
);
2649 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&format
);
2651 if(pHdr
->hwndFrom
== hwndFontList
)
2653 if(lstrcmpW(format
.szFaceName
, (LPWSTR
)endEdit
->szText
))
2654 set_font((LPCWSTR
) endEdit
->szText
);
2655 } else if (pHdr
->hwndFrom
== hwndSizeList
)
2657 wsprintfW(sizeBuffer
, stringFormat
, format
.yHeight
/ 20);
2658 if(lstrcmpW(sizeBuffer
, (LPWSTR
)endEdit
->szText
))
2661 if(number_from_string((LPWSTR
)endEdit
->szText
, &size
, FALSE
))
2666 SetWindowTextW(hwndSizeList
, sizeBuffer
);
2667 MessageBoxW(hMainWnd
, MAKEINTRESOURCEW(STRING_INVALID_NUMBER
), wszAppTitle
, MB_OK
| MB_ICONINFORMATION
);
2675 if (pHdr
->hwndFrom
!= hwndEditor
)
2678 if (pHdr
->code
== EN_SELCHANGE
)
2680 SELCHANGE
*pSC
= (SELCHANGE
*)lParam
;
2685 sprintf( buf
,"selection = %d..%d, line count=%ld",
2686 pSC
->chrg
.cpMin
, pSC
->chrg
.cpMax
,
2687 SendMessage(hwndEditor
, EM_GETLINECOUNT
, 0, 0));
2688 SetWindowText(GetDlgItem(hWnd
, IDC_STATUSBAR
), buf
);
2689 SendMessage(hWnd
, WM_USER
, 0, 0);
2695 static LRESULT
OnCommand( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
2697 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
2698 static FINDREPLACEW findreplace
;
2700 if ((HWND
)lParam
== hwndEditor
)
2703 switch(LOWORD(wParam
))
2707 PostMessageW(hWnd
, WM_CLOSE
, 0, 0);
2712 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
2713 int ret
= DialogBox(hInstance
, MAKEINTRESOURCE(IDD_NEWFILE
), hWnd
,
2714 (DLGPROC
)newfile_proc
);
2716 if(ret
!= ID_NEWFILE_ABORT
)
2718 if(prompt_save_changes())
2723 wszFileName
[0] = '\0';
2727 st
.flags
= ST_DEFAULT
;
2729 SendMessageW(hEditorWnd
, EM_SETTEXTEX
, (WPARAM
)&st
, 0);
2731 SendMessageW(hEditorWnd
, EM_SETMODIFY
, FALSE
, 0);
2732 set_fileformat(ret
);
2746 DoSaveFile(wszFileName
, fileFormat
);
2751 case ID_FILE_SAVEAS
:
2755 case ID_FILE_RECENT1
:
2756 case ID_FILE_RECENT2
:
2757 case ID_FILE_RECENT3
:
2758 case ID_FILE_RECENT4
:
2760 HMENU hMenu
= GetMenu(hWnd
);
2763 mi
.cbSize
= sizeof(MENUITEMINFOW
);
2764 mi
.fMask
= MIIM_DATA
;
2765 if(GetMenuItemInfoW(hMenu
, LOWORD(wParam
), FALSE
, &mi
))
2766 DoOpenFile((LPWSTR
)mi
.dwItemData
);
2771 dialog_find(&findreplace
, FALSE
);
2775 handle_findmsg(&findreplace
);
2779 dialog_find(&findreplace
, TRUE
);
2782 case ID_FONTSETTINGS
:
2783 dialog_choose_font();
2790 case ID_PRINT_QUICK
:
2796 int index
= reg_formatindex(fileFormat
);
2797 DWORD tmp
= barState
[index
];
2798 barState
[index
] = 0;
2800 barState
[index
] = tmp
;
2801 ShowWindow(hEditorWnd
, FALSE
);
2802 preview_bar_show(TRUE
);
2806 SetMenu(hWnd
, NULL
);
2807 InvalidateRect(0, 0, TRUE
);
2812 dialog_printsetup();
2815 case ID_FORMAT_BOLD
:
2816 case ID_FORMAT_ITALIC
:
2817 case ID_FORMAT_UNDERLINE
:
2820 int effects
= CFE_BOLD
;
2822 ZeroMemory(&fmt
, sizeof(fmt
));
2823 fmt
.cbSize
= sizeof(fmt
);
2824 SendMessageW(hwndEditor
, EM_GETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2826 fmt
.dwMask
= CFM_BOLD
;
2828 if (LOWORD(wParam
) == ID_FORMAT_ITALIC
)
2830 effects
= CFE_ITALIC
;
2831 fmt
.dwMask
= CFM_ITALIC
;
2832 } else if (LOWORD(wParam
) == ID_FORMAT_UNDERLINE
)
2834 effects
= CFE_UNDERLINE
;
2835 fmt
.dwMask
= CFM_UNDERLINE
;
2838 fmt
.dwEffects
^= effects
;
2840 SendMessageW(hwndEditor
, EM_SETCHARFORMAT
, SCF_SELECTION
, (LPARAM
)&fmt
);
2845 PostMessageW(hwndEditor
, WM_CUT
, 0, 0);
2849 PostMessageW(hwndEditor
, WM_COPY
, 0, 0);
2853 PostMessageW(hwndEditor
, WM_PASTE
, 0, 0);
2857 PostMessageW(hwndEditor
, WM_CLEAR
, 0, 0);
2860 case ID_EDIT_SELECTALL
:
2862 CHARRANGE range
= {0, -1};
2863 SendMessageW(hwndEditor
, EM_EXSETSEL
, 0, (LPARAM
)&range
);
2864 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2868 case ID_EDIT_GETTEXT
:
2870 int nLen
= GetWindowTextLengthW(hwndEditor
);
2871 LPWSTR data
= HeapAlloc( GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
) );
2874 GetWindowTextW(hwndEditor
, data
, nLen
+1);
2875 MessageBoxW(NULL
, data
, xszAppTitle
, MB_OK
);
2877 HeapFree( GetProcessHeap(), 0, data
);
2878 data
= HeapAlloc(GetProcessHeap(), 0, (nLen
+1)*sizeof(WCHAR
));
2880 tr
.chrg
.cpMax
= nLen
;
2881 tr
.lpstrText
= data
;
2882 SendMessage (hwndEditor
, EM_GETTEXTRANGE
, 0, (LPARAM
)&tr
);
2883 MessageBoxW(NULL
, data
, xszAppTitle
, MB_OK
);
2884 HeapFree( GetProcessHeap(), 0, data
);
2886 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2890 case ID_EDIT_CHARFORMAT
:
2891 case ID_EDIT_DEFCHARFORMAT
:
2895 ZeroMemory(&cf
, sizeof(cf
));
2896 cf
.cbSize
= sizeof(cf
);
2898 i
= SendMessageW(hwndEditor
, EM_GETCHARFORMAT
,
2899 LOWORD(wParam
) == ID_EDIT_CHARFORMAT
, (LPARAM
)&cf
);
2903 case ID_EDIT_PARAFORMAT
:
2906 ZeroMemory(&pf
, sizeof(pf
));
2907 pf
.cbSize
= sizeof(pf
);
2908 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2912 case ID_EDIT_SELECTIONINFO
:
2914 CHARRANGE range
= {0, -1};
2918 SendMessage(hwndEditor
, EM_EXGETSEL
, 0, (LPARAM
)&range
);
2919 data
= HeapAlloc(GetProcessHeap(), 0, sizeof(*data
) * (range
.cpMax
-range
.cpMin
+1));
2920 SendMessage(hwndEditor
, EM_GETSELTEXT
, 0, (LPARAM
)data
);
2921 sprintf(buf
, "Start = %d, End = %d", range
.cpMin
, range
.cpMax
);
2922 MessageBoxA(hWnd
, buf
, "Editor", MB_OK
);
2923 MessageBoxW(hWnd
, data
, xszAppTitle
, MB_OK
);
2924 HeapFree( GetProcessHeap(), 0, data
);
2925 /* SendMessage(hwndEditor, EM_SETSEL, 0, -1); */
2929 case ID_EDIT_READONLY
:
2931 long nStyle
= GetWindowLong(hwndEditor
, GWL_STYLE
);
2932 if (nStyle
& ES_READONLY
)
2933 SendMessageW(hwndEditor
, EM_SETREADONLY
, 0, 0);
2935 SendMessageW(hwndEditor
, EM_SETREADONLY
, 1, 0);
2939 case ID_EDIT_MODIFIED
:
2940 if (SendMessageW(hwndEditor
, EM_GETMODIFY
, 0, 0))
2941 SendMessageW(hwndEditor
, EM_SETMODIFY
, 0, 0);
2943 SendMessageW(hwndEditor
, EM_SETMODIFY
, 1, 0);
2947 SendMessageW(hwndEditor
, EM_UNDO
, 0, 0);
2951 SendMessageW(hwndEditor
, EM_REDO
, 0, 0);
2958 pf
.cbSize
= sizeof(pf
);
2959 pf
.dwMask
= PFM_NUMBERING
;
2960 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
2962 pf
.dwMask
|= PFM_OFFSET
;
2964 if(pf
.wNumbering
== PFN_BULLET
)
2970 pf
.wNumbering
= PFN_BULLET
;
2974 SendMessageW(hwndEditor
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2979 case ID_ALIGN_CENTER
:
2980 case ID_ALIGN_RIGHT
:
2984 pf
.cbSize
= sizeof(pf
);
2985 pf
.dwMask
= PFM_ALIGNMENT
;
2986 switch(LOWORD(wParam
)) {
2987 case ID_ALIGN_LEFT
: pf
.wAlignment
= PFA_LEFT
; break;
2988 case ID_ALIGN_CENTER
: pf
.wAlignment
= PFA_CENTER
; break;
2989 case ID_ALIGN_RIGHT
: pf
.wAlignment
= PFA_RIGHT
; break;
2991 SendMessageW(hwndEditor
, EM_SETPARAFORMAT
, 0, (LPARAM
)&pf
);
2996 SendMessageW(hwndEditor
, EM_SETBKGNDCOLOR
, 1, 0);
3000 SendMessageW(hwndEditor
, EM_SETBKGNDCOLOR
, 0, RGB(255,255,192));
3003 case ID_TOGGLE_TOOLBAR
:
3004 set_toolbar_state(BANDID_TOOLBAR
, !is_bar_visible(BANDID_TOOLBAR
));
3008 case ID_TOGGLE_FORMATBAR
:
3009 set_toolbar_state(BANDID_FONTLIST
, !is_bar_visible(BANDID_FORMATBAR
));
3010 set_toolbar_state(BANDID_SIZELIST
, !is_bar_visible(BANDID_FORMATBAR
));
3011 set_toolbar_state(BANDID_FORMATBAR
, !is_bar_visible(BANDID_FORMATBAR
));
3015 case ID_TOGGLE_STATUSBAR
:
3016 set_statusbar_state(!is_bar_visible(BANDID_STATUSBAR
));
3022 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
3023 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_DATETIME
), hWnd
, (DLGPROC
)datetime_proc
);
3029 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
3030 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_PARAFORMAT
), hWnd
,
3037 HINSTANCE hInstance
= (HINSTANCE
)GetWindowLongPtr(hWnd
, GWLP_HINSTANCE
);
3038 DialogBoxW(hInstance
, MAKEINTRESOURCEW(IDD_TABSTOPS
), hWnd
, tabstops_proc
);
3046 case ID_VIEWPROPERTIES
:
3047 dialog_viewproperties();
3051 SendMessageW(hwndEditor
, WM_COMMAND
, wParam
, lParam
);
3057 static LRESULT
OnInitPopupMenu( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
3059 HMENU hMenu
= (HMENU
)wParam
;
3060 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
3061 HWND hwndStatus
= GetDlgItem(hWnd
, IDC_STATUSBAR
);
3063 int nAlignment
= -1;
3069 SendMessageW(hEditorWnd
, EM_GETSEL
, (WPARAM
)&selFrom
, (LPARAM
)&selTo
);
3070 EnableMenuItem(hMenu
, ID_EDIT_COPY
, MF_BYCOMMAND
|(selFrom
== selTo
) ? MF_GRAYED
: MF_ENABLED
);
3071 EnableMenuItem(hMenu
, ID_EDIT_CUT
, MF_BYCOMMAND
|(selFrom
== selTo
) ? MF_GRAYED
: MF_ENABLED
);
3073 pf
.cbSize
= sizeof(PARAFORMAT
);
3074 SendMessageW(hwndEditor
, EM_GETPARAFORMAT
, 0, (LPARAM
)&pf
);
3075 CheckMenuItem(hMenu
, ID_EDIT_READONLY
,
3076 MF_BYCOMMAND
|(GetWindowLong(hwndEditor
, GWL_STYLE
)&ES_READONLY
? MF_CHECKED
: MF_UNCHECKED
));
3077 CheckMenuItem(hMenu
, ID_EDIT_MODIFIED
,
3078 MF_BYCOMMAND
|(SendMessage(hwndEditor
, EM_GETMODIFY
, 0, 0) ? MF_CHECKED
: MF_UNCHECKED
));
3079 if (pf
.dwMask
& PFM_ALIGNMENT
)
3080 nAlignment
= pf
.wAlignment
;
3081 CheckMenuItem(hMenu
, ID_ALIGN_LEFT
, MF_BYCOMMAND
|(nAlignment
== PFA_LEFT
) ?
3082 MF_CHECKED
: MF_UNCHECKED
);
3083 CheckMenuItem(hMenu
, ID_ALIGN_CENTER
, MF_BYCOMMAND
|(nAlignment
== PFA_CENTER
) ?
3084 MF_CHECKED
: MF_UNCHECKED
);
3085 CheckMenuItem(hMenu
, ID_ALIGN_RIGHT
, MF_BYCOMMAND
|(nAlignment
== PFA_RIGHT
) ?
3086 MF_CHECKED
: MF_UNCHECKED
);
3087 CheckMenuItem(hMenu
, ID_BULLET
, MF_BYCOMMAND
| ((pf
.wNumbering
== PFN_BULLET
) ?
3088 MF_CHECKED
: MF_UNCHECKED
));
3089 EnableMenuItem(hMenu
, ID_EDIT_UNDO
, MF_BYCOMMAND
|(SendMessageW(hwndEditor
, EM_CANUNDO
, 0, 0)) ?
3090 MF_ENABLED
: MF_GRAYED
);
3091 EnableMenuItem(hMenu
, ID_EDIT_REDO
, MF_BYCOMMAND
|(SendMessageW(hwndEditor
, EM_CANREDO
, 0, 0)) ?
3092 MF_ENABLED
: MF_GRAYED
);
3094 CheckMenuItem(hMenu
, ID_TOGGLE_TOOLBAR
, MF_BYCOMMAND
|(is_bar_visible(BANDID_TOOLBAR
)) ?
3095 MF_CHECKED
: MF_UNCHECKED
);
3097 CheckMenuItem(hMenu
, ID_TOGGLE_FORMATBAR
, MF_BYCOMMAND
|(is_bar_visible(BANDID_FORMATBAR
)) ?
3098 MF_CHECKED
: MF_UNCHECKED
);
3100 CheckMenuItem(hMenu
, ID_TOGGLE_STATUSBAR
, MF_BYCOMMAND
|IsWindowVisible(hwndStatus
) ?
3101 MF_CHECKED
: MF_UNCHECKED
);
3103 gt
.flags
= GTL_NUMCHARS
;
3105 textLength
= SendMessageW(hEditorWnd
, EM_GETTEXTLENGTHEX
, (WPARAM
)>
, 0);
3106 EnableMenuItem(hMenu
, ID_FIND
, MF_BYCOMMAND
|(textLength
? MF_ENABLED
: MF_GRAYED
));
3108 mi
.cbSize
= sizeof(mi
);
3109 mi
.fMask
= MIIM_DATA
;
3111 GetMenuItemInfoW(hMenu
, ID_FIND_NEXT
, FALSE
, &mi
);
3113 EnableMenuItem(hMenu
, ID_FIND_NEXT
, MF_BYCOMMAND
|((textLength
&& mi
.dwItemData
) ?
3114 MF_ENABLED
: MF_GRAYED
));
3116 EnableMenuItem(hMenu
, ID_REPLACE
, MF_BYCOMMAND
|(textLength
? MF_ENABLED
: MF_GRAYED
));
3121 static LRESULT
OnSize( HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
3123 int nStatusSize
= 0;
3125 HWND hwndEditor
= GetDlgItem(hWnd
, IDC_EDITOR
);
3126 HWND hwndStatusBar
= GetDlgItem(hWnd
, IDC_STATUSBAR
);
3127 HWND hwndReBar
= GetDlgItem(hWnd
, IDC_REBAR
);
3128 int rebarHeight
= 0;
3133 SendMessageW(hwndStatusBar
, WM_SIZE
, 0, 0);
3134 if (IsWindowVisible(hwndStatusBar
))
3136 GetClientRect(hwndStatusBar
, &rc
);
3137 nStatusSize
= rc
.bottom
- rc
.top
;
3145 if(!is_bar_visible(BANDID_TOOLBAR
))
3148 if(!is_bar_visible(BANDID_FORMATBAR
))
3151 rebarHeight
= rebarRows
? SendMessageW(hwndReBar
, RB_GETBARHEIGHT
, 0, 0) : 0;
3153 MoveWindow(hwndReBar
, 0, 0, LOWORD(lParam
), rebarHeight
, TRUE
);
3157 GetClientRect(hWnd
, &rc
);
3158 MoveWindow(hwndEditor
, 0, rebarHeight
, rc
.right
, rc
.bottom
-nStatusSize
-rebarHeight
, TRUE
);
3161 return DefWindowProcW(hWnd
, WM_SIZE
, wParam
, lParam
);
3164 static LRESULT CALLBACK
WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3166 if(msg
== ID_FINDMSGSTRING
)
3167 return handle_findmsg((LPFINDREPLACEW
)lParam
);
3172 return OnCreate( hWnd
, wParam
, lParam
);
3175 return OnUser( hWnd
, wParam
, lParam
);
3178 return OnNotify( hWnd
, wParam
, lParam
);
3182 return preview_command( hWnd
, wParam
, lParam
);
3184 return OnCommand( hWnd
, wParam
, lParam
);
3194 } else if(prompt_save_changes())
3196 registry_set_options();
3197 registry_set_formatopts_all();
3204 SetFocus(GetDlgItem(hWnd
, IDC_EDITOR
));
3207 case WM_INITMENUPOPUP
:
3208 return OnInitPopupMenu( hWnd
, wParam
, lParam
);
3211 return OnSize( hWnd
, wParam
, lParam
);
3213 case WM_CONTEXTMENU
:
3214 if((HWND
)wParam
== hEditorWnd
)
3215 return context_menu(lParam
);
3217 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
3221 WCHAR file
[MAX_PATH
];
3222 DragQueryFileW((HDROP
)wParam
, 0, file
, MAX_PATH
);
3223 DragFinish((HDROP
)wParam
);
3225 if(prompt_save_changes())
3231 return print_preview();
3233 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
3236 return DefWindowProcW(hWnd
, msg
, wParam
, lParam
);
3242 int CALLBACK
WinMain(HINSTANCE hInstance
, HINSTANCE hOldInstance
, LPSTR szCmdParagraph
, int res
)
3244 INITCOMMONCONTROLSEX classes
= {8, ICC_BAR_CLASSES
|ICC_COOL_CLASSES
|ICC_USEREX_CLASSES
};
3249 static const WCHAR wszAccelTable
[] = {'M','A','I','N','A','C','C','E','L',
3250 'T','A','B','L','E','\0'};
3252 InitCommonControlsEx(&classes
);
3254 hAccel
= LoadAcceleratorsW(hInstance
, wszAccelTable
);
3256 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
3257 wc
.lpfnWndProc
= WndProc
;
3260 wc
.hInstance
= hInstance
;
3261 wc
.hIcon
= LoadIconW(hInstance
, MAKEINTRESOURCEW(IDI_WORDPAD
));
3262 wc
.hCursor
= LoadCursor(NULL
, IDC_IBEAM
);
3263 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
3264 wc
.lpszMenuName
= xszMainMenu
;
3265 wc
.lpszClassName
= wszMainWndClass
;
3266 RegisterClassW(&wc
);
3268 rc
= registry_read_winrect();
3269 hMainWnd
= CreateWindowExW(0, wszMainWndClass
, wszAppTitle
, WS_CLIPCHILDREN
|WS_OVERLAPPEDWINDOW
,
3270 rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, NULL
, NULL
, hInstance
, NULL
);
3271 ShowWindow(hMainWnd
, SW_SHOWDEFAULT
);
3275 set_fileformat(SF_RTF
);
3276 hPopupMenu
= LoadMenuW(hInstance
, MAKEINTRESOURCEW(IDM_POPUP
));
3277 get_default_printer_opts();
3280 HandleCommandLine(GetCommandLineW());
3282 while(GetMessageW(&msg
,0,0,0))
3284 if (IsDialogMessage(hFindWnd
, &msg
))
3287 if (TranslateAcceleratorW(hMainWnd
, hAccel
, &msg
))
3289 TranslateMessage(&msg
);
3290 DispatchMessageW(&msg
);
3291 if (!PeekMessageW(&msg
, 0, 0, 0, PM_NOREMOVE
))
3292 SendMessageW(hMainWnd
, WM_USER
, 0, 0);