Adapted to cursor/icon handling changes.
[wine/multimedia.git] / programs / cmdlgtst / cmdlgtst.c
blob0e228b2773d32dce2ad290f7295e48fd37082506
1 // (c) 1999 Eric Williams. Rights as specified under the WINE
2 // License. Don't hoard code; share it!
4 //
5 // One might call this a Commdlg test jig. Its sole function in life
6 // is to call the Commdlg Common Dialogs; at present it doesn't even
7 // do anything horribly interesting with the results.
9 // Ideally it would also do event logging and be a bit less stupid
10 // about displaying the results of the various requesters. But hey,
11 // it's only a first step. :-)
13 #include <windows.h>
14 #include <commdlg.h>
15 #include <stdio.h>
16 #include "cmdlgr.h"
18 // This structure is to set up flag / control associations for the custom
19 // requesters. The ft_id is the id for the control (usually generated
20 // by the system) and the ft_bit is the flag bit which goes into the
21 // settings longword for the various Commdlg structures. It is assumed
22 // that all flags fit in an unsigned long and that all bits are in fact
23 // one bit.
25 // The array of entries is terminated by {IDOK, 0}; the assumption is that
26 // IDOK would never be associated with a dialogbox control (since it's
27 // usually the ID of the OK button}.
29 struct FlagTableEntry {
30 int ft_id;
31 unsigned long ft_bit;
34 // #ifdef __WINE_WINDOWS_H
35 // #define EXPORT
36 // #define HWND HWND32
37 // int ctx_debug = 0;
38 // #else
39 // #define EXPORT _export
40 // #endif
42 //#define FAR
43 #define EXPORT
45 static char menuName[] = "TestCommdlgMenu";
46 static char className[] = "TestCommdlg";
47 static char windowName[] = "TestCommdlg Window";
49 // global hInstance variable. This makes the code non-threadable,
50 // but wotthehell; this is Win32 anyway! (Though it does work
51 // under Win16, if one doesn't run more than one copy at a time.)
53 static HINSTANCE g_hInstance;
55 // global CommDlg data structures for modals. These are placed here
56 // so that the custom dialog boxes can get at them.
58 static PRINTDLG pd;
59 static COLORREF cc_cr[16];
60 static CHOOSECOLOR cc;
61 static LOGFONT cf_lf;
62 static CHOOSEFONT cf;
63 static char ofn_filepat[] = "All Files (*.*)\0*.*\0Only Text Files (*.txt)\0*.txt\0";
64 static char ofn_result[1024];
65 static OPENFILENAME ofn;
67 // Stuff for find and replace. These are modeless, so I have to put them here.
69 static HWND findDialogBox = 0;
70 static UINT findMessageId = 0;
72 static int findDialogBoxInit = 0;
73 static int findDialogStructInit = 0;
74 static FINDREPLACE frS;
75 static char fromstring[1024], tostring[1024];
77 // Utility routines. Currently there is only one, and it's a nasty
78 // reminder that I'm not done yet.
80 void nyi(HWND hWnd)
82 MessageBox(hWnd, "Not yet implemented!", "NYI", MB_ICONEXCLAMATION | MB_OK);
86 // Initial initialization code. This code simply shoves in predefined
87 // data into the COMMDLG data structures; in the future, I might use
88 // a series of loadable resources, or static initializers; of course,
89 // if Microsoft decides to change the field ordering, I'd be screwed.
91 void mwi_Print(HWND hWnd)
93 pd.lStructSize = sizeof(PRINTDLG);
94 pd.hwndOwner = hWnd;
95 pd.hDevMode = 0;
96 pd.hDevNames = 0;
97 pd.hDC = 0;
98 pd.Flags = 0;
99 pd.nMinPage = 1;
100 pd.nMaxPage = 100;
101 pd.hInstance = 0;
102 pd.lCustData = 0;
103 pd.lpfnPrintHook = 0;
104 pd.lpfnSetupHook = 0;
105 pd.lpPrintTemplateName = 0;
106 pd.lpSetupTemplateName = 0;
107 pd.hPrintTemplate = 0;
108 pd.hSetupTemplate = 0;
112 void mwi_Color(HWND hWnd)
114 int i;
116 // there's probably an init call for this, somewhere.
118 for(i=0;i<16;i++)
119 cc_cr[i] = RGB(0,0,0);
121 cc.lStructSize = sizeof(CHOOSECOLOR);
122 cc.hwndOwner = hWnd;
123 cc.hInstance = 0;
124 cc.rgbResult = RGB(0,0,0);
125 cc.lpCustColors = cc_cr;
126 cc.Flags = 0;
127 cc.lCustData = 0;
128 cc.lpfnHook = 0;
129 cc.lpTemplateName = 0;
132 void mwi_Font(HWND hWnd)
134 cf.lStructSize = sizeof(CHOOSEFONT);
135 cf.hwndOwner = hWnd;
136 cf.hDC = 0;
137 cf.lpLogFont = &cf_lf;
138 cf.Flags = 0;
139 cf.rgbColors = RGB(0,0,0); // what is *this* doing here??
140 cf.lCustData = 0;
141 cf.lpfnHook = 0;
142 cf.lpTemplateName = 0;
143 cf.hInstance = 0;
144 cf.lpszStyle = 0;
145 cf.nFontType = 0;
146 cf.nSizeMin = 8;
147 cf.nSizeMax = 72;
150 void mwi_File(HWND hWnd)
152 ofn.lStructSize = sizeof(OPENFILENAME);
153 ofn.hwndOwner = hWnd;
154 ofn.hInstance = 0;
155 ofn.lpstrFilter = (LPSTR) ofn_filepat;
156 ofn.lpstrCustomFilter = 0;
157 ofn.nMaxCustFilter = 0;
158 ofn.nFilterIndex = 0;
159 ofn.lpstrFile = ofn_result;
160 ofn.nMaxFile = sizeof(ofn_result);
161 ofn.lpstrFileTitle = 0;
162 ofn.nMaxFileTitle = 0;
163 ofn.lpstrInitialDir = 0;
164 ofn.lpstrTitle = "Open File";
165 ofn.Flags = 0;
166 ofn.nFileOffset = 0;
167 ofn.nFileExtension = 0;
168 ofn.lpstrDefExt = "*";
169 ofn.lCustData = 0;
170 ofn.lpfnHook = 0;
171 ofn.lpTemplateName = 0;
173 ofn_result[0] = '\0';
176 void mwi_FindReplace(HWND hWnd)
178 frS.lStructSize = sizeof(FINDREPLACE);
179 frS.hwndOwner = hWnd;
180 frS.hInstance = 0;
181 frS.Flags = FR_DOWN;
182 frS.lpstrFindWhat = fromstring;
183 frS.lpstrReplaceWith = tostring;
184 frS.wFindWhatLen = sizeof(fromstring);
185 frS.wReplaceWithLen = sizeof(tostring);
186 frS.lCustData = 0;
187 frS.lpfnHook = 0;
188 frS.lpTemplateName = 0;
190 fromstring[0] = '\0';
191 tostring[0] = '\0';
192 findMessageId = RegisterWindowMessage(FINDMSGSTRING);
195 void mwi_InitAll(HWND hWnd)
197 mwi_Print(hWnd);
198 mwi_Font(hWnd);
199 mwi_Color(hWnd);
200 mwi_File(hWnd);
201 mwi_FindReplace(hWnd);
204 // Various configurations for the window. Ideally, this
205 // would be stored with the window itself, but then, this
206 // isn't the brightest of apps. Wouldn't be hard to set up,
207 // though -- one of the neater functions of Windows, but if
208 // someone decides to load the windows themselves from resources,
209 // there might be a problem.
211 void paintMainWindow(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
213 PAINTSTRUCT ps;
214 RECT rect;
216 // This is the Windows equivalent of one of my widgets,
217 // which basically just draws a large 'X'.
219 BeginPaint(hWnd, &ps);
220 GetClientRect(hWnd, (LPRECT) &rect);
221 MoveToEx(ps.hdc, rect.left, rect.top, (POINT FAR *) 0);
222 LineTo(ps.hdc, rect.right, rect.bottom);
223 MoveToEx(ps.hdc, rect.left, rect.bottom, (POINT FAR *) 0);
224 LineTo(ps.hdc, rect.right, rect.top);
226 EndPaint(hWnd, &ps);
229 // This function simply returns an error indication. Naturally,
230 // I do not (yet) see an elegant method by which one can convert
231 // the CDERR_xxx return values into something resembling usable text;
232 // consult cderr.h to see what was returned.
234 void mw_checkError(HWND hWnd)
236 DWORD errval = CommDlgExtendedError();
237 if(errval) {
238 char errbuf[80];
240 sprintf(errbuf, "CommDlgExtendedError(): error code %ld (0x%lx)", errval, errval);
241 MessageBox(hWnd, errbuf, "Error", MB_ICONEXCLAMATION | MB_OK);
243 else {
244 MessageBox(hWnd, "Nope, user canceled it.", "No", MB_OK);
248 // The actual dialog function calls. These merely wrap the Commdlg
249 // calls, and do something (not so) intelligent with the result.
250 // Ideally, the main window would refresh and take into account the
251 // various values specified in the dialog.
253 void mw_ColorSetup(HWND hWnd)
255 if(ChooseColor(&cc)) {
256 MessageBox(hWnd, "Success.", "Yes", MB_OK);
258 else mw_checkError(hWnd);
261 void mw_FontSetup(HWND hWnd)
263 if(ChooseFont(&cf)) {
264 MessageBox(hWnd, "Success.", "Yes", MB_OK);
266 else mw_checkError(hWnd);
269 void mw_FindSetup(HWND hWnd)
271 if(findDialogBox == 0) {
272 findDialogBox = FindText(&frS);
273 if(findDialogBox==0) mw_checkError(hWnd);
277 void mw_ReplaceSetup(HWND hWnd)
279 if(findDialogBox == 0) {
280 findDialogBox = ReplaceText(&frS);
281 if(findDialogBox==0) mw_checkError(hWnd);
285 void mw_OpenSetup(HWND hWnd)
287 if(GetOpenFileName(&ofn)) {
288 MessageBox(hWnd, "Success.", "Yes", MB_OK);
290 else mw_checkError(hWnd);
293 void mw_SaveSetup(HWND hWnd)
295 if(GetSaveFileName(&ofn)) {
296 MessageBox(hWnd, "Success.", "Yes", MB_OK);
298 else mw_checkError(hWnd);
301 // Can't find documentation in Borland for this one. Does it
302 // exist at all, or is it merely a subdialog of Print?
304 void mw_PSetupSetup(HWND hWnd)
306 nyi(hWnd);
309 void mw_PrintSetup(HWND hWnd)
311 if(PrintDlg(&pd)) {
312 // the following are suggested in the Borland documentation,
313 // but aren't that useful until WinE starts to actually
314 // function with respect to printing.
316 // Escape(tmp.hDC, STARTDOC, 8, "Test-Doc", NULL);
318 /* Print text and rectangle */
320 // TextOut(tmp.hDC, 50, 50, "Common Dialog Test Page", 23);
322 // Rectangle(tmp.hDC, 50, 90, 625, 105);
323 // Escape(tmp.hDC, NEWFRAME, 0, NULL, NULL);
324 // Escape(tmp.hDC, ENDDOC, 0, NULL, NULL);
325 // DeleteDC(tmp.hDC);
326 if (pd.hDevMode != NULL)
327 GlobalFree(pd.hDevMode);
328 if (pd.hDevNames != NULL)
329 GlobalFree(pd.hDevNames);
331 pd.hDevMode = 0;
332 pd.hDevNames = 0;
334 MessageBox(hWnd, "Success.", "Yes", MB_OK);
336 else mw_checkError(hWnd);
339 // Some support functions for the custom dialog box handlers.
340 // In particular, we have to set things properly, and get the flags back.
342 void mwcd_SetFlags(HWND hWnd, struct FlagTableEntry *table, unsigned long flags)
344 int i;
346 for(i=0; table[i].ft_id != IDOK; i++)
348 CheckDlgButton(hWnd, table[i].ft_id,(table[i].ft_bit & flags) ? 1 : 0);
352 unsigned long mwcd_GetFlags(HWND hWnd, struct FlagTableEntry * table)
354 int i;
355 unsigned long l = 0;
357 for(i=0; table[i].ft_id != IDOK; i++)
359 if(IsDlgButtonChecked(hWnd, table[i].ft_id) == 1)
360 l |= table[i].ft_bit;
363 return l;
366 // These functions are the custom dialog box handlers.
367 // The division of labor may be a tad peculiar; in particular,
368 // the flag tables should probably be in the main functions,
369 // not the handlers. I'll fix that later; this works as of right now.
371 BOOL mwcd_Setup(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
372 struct FlagTableEntry * table, unsigned long * flags)
374 switch(uMsg)
376 case WM_INITDIALOG:
377 // Set the controls properly.
379 mwcd_SetFlags(hWnd, table, *flags);
381 return TRUE; // I would return FALSE if I explicitly called SetFocus().
382 // As usual, Windows is weird.
384 case WM_COMMAND:
385 switch(wParam) {
386 case IDOK:
387 *flags = mwcd_GetFlags(hWnd, table);
388 EndDialog(hWnd,1);
389 break;
391 case IDCANCEL:
392 EndDialog(hWnd,0);
393 break;
395 case CM_R_HELP:
396 break; // help? We don't need no steenkin help!
398 default:
399 break; // eat the message
401 return TRUE;
403 default:
404 return FALSE; // since I don't process this particular message
408 BOOL CALLBACK mwcd_ColorSetup(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
410 static struct FlagTableEntry flagTable[] = {
411 {I_CC_RGBINIT, CC_RGBINIT},
412 {I_CC_SHOWHELP, CC_SHOWHELP},
413 {I_CC_PREVENTFULLOPEN, CC_PREVENTFULLOPEN},
414 {I_CC_FULLOPEN, CC_FULLOPEN},
415 {I_CC_ENABLETEMPLATEHANDLE, CC_ENABLETEMPLATEHANDLE},
416 {I_CC_ENABLETEMPLATE, CC_ENABLETEMPLATE},
417 {I_CC_ENABLEHOOK, CC_ENABLEHOOK},
418 {IDOK, 0},
421 return mwcd_Setup(hWnd, uMsg, wParam, lParam, flagTable, &cc.Flags);
424 BOOL CALLBACK mwcd_FontSetup(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
426 static struct FlagTableEntry flagTable[] = {
427 {I_CF_APPLY, CF_APPLY},
428 {I_CF_ANSIONLY, CF_ANSIONLY},
429 {I_CF_BOTH, CF_BOTH},
430 {I_CF_TTONLY, CF_TTONLY},
431 {I_CF_EFFECTS, CF_EFFECTS},
432 {I_CF_ENABLEHOOK, CF_ENABLEHOOK},
433 {I_CF_ENABLETEMPLATE, CF_ENABLETEMPLATE},
434 {I_CF_ENABLETEMPLATEHANDLE, CF_ENABLETEMPLATEHANDLE},
435 {I_CF_FIXEDPITCHONLY, CF_FIXEDPITCHONLY},
436 {I_CF_INITTOLOGFONTSTRUCT, CF_INITTOLOGFONTSTRUCT},
437 {I_CF_LIMITSIZE, CF_LIMITSIZE},
438 {I_CF_NOFACESEL, CF_NOFACESEL},
439 {I_CF_USESTYLE, CF_USESTYLE},
440 {I_CF_WYSIWYG, CF_WYSIWYG},
441 {I_CF_SHOWHELP, CF_SHOWHELP},
442 {I_CF_SCREENFONTS, CF_SCREENFONTS},
443 {I_CF_SCALABLEONLY, CF_SCALABLEONLY},
444 {I_CF_PRINTERFONTS, CF_PRINTERFONTS},
445 {I_CF_NOVECTORFONTS, CF_NOVECTORFONTS},
446 {I_CF_NOSTYLESEL, CF_NOSTYLESEL},
447 {I_CF_NOSIZESEL, CF_NOSIZESEL},
448 {I_CF_NOOEMFONTS, CF_NOOEMFONTS},
449 {IDOK, 0},
452 return mwcd_Setup(hWnd, uMsg, wParam, lParam, flagTable, &cf.Flags);
455 BOOL CALLBACK mwcd_FindSetup(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
458 static struct FlagTableEntry flagTable[] = {
459 {I_FR_DIALOGTERM, FR_DIALOGTERM},
460 {I_FR_DOWN, FR_DOWN},
461 {I_FR_ENABLEHOOK, FR_ENABLEHOOK},
462 {I_FR_ENABLETEMPLATE, FR_ENABLETEMPLATE},
463 {I_FR_ENABLETEMPLATEHANDLE, FR_ENABLETEMPLATEHANDLE},
464 {I_FR_FINDNEXT, FR_FINDNEXT},
465 {I_FR_HIDEMATCHCASE, FR_HIDEMATCHCASE},
466 {I_FR_HIDEWHOLEWORD, FR_HIDEWHOLEWORD},
467 {I_FR_HIDEUPDOWN, FR_HIDEUPDOWN},
468 {I_FR_MATCHCASE, FR_MATCHCASE},
469 {I_FR_NOMATCHCASE, FR_NOMATCHCASE},
470 {I_FR_NOUPDOWN, FR_NOUPDOWN},
471 {I_FR_NOWHOLEWORD, FR_NOWHOLEWORD},
472 {I_FR_REPLACE, FR_REPLACE},
473 {I_FR_REPLACEALL, FR_REPLACEALL},
474 {I_FR_SHOWHELP, FR_SHOWHELP},
475 {I_FR_WHOLEWORD, FR_WHOLEWORD},
476 {IDOK, 0},
479 return mwcd_Setup(hWnd, uMsg, wParam, lParam, flagTable, &frS.Flags);
482 BOOL CALLBACK mwcd_PrintSetup(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
484 static struct FlagTableEntry flagTable[] = {
485 {I_PD_ALLPAGES, PD_ALLPAGES},
486 {I_PD_COLLATE, PD_COLLATE},
487 {I_PD_DISABLEPRINTTOFILE, PD_DISABLEPRINTTOFILE},
488 {I_PD_ENABLEPRINTHOOK, PD_ENABLEPRINTHOOK},
489 {I_PD_ENABLEPRINTTEMPLATE, PD_ENABLEPRINTTEMPLATE},
490 {I_PD_ENABLEPRINTTEMPLATEHANDLE, PD_ENABLEPRINTTEMPLATEHANDLE},
491 {I_PD_ENABLESETUPHOOK, PD_ENABLESETUPHOOK},
492 {I_PD_ENABLESETUPTEMPLATE, PD_ENABLESETUPTEMPLATE},
493 {I_PD_ENABLESETUPTEMPLATEHANDLE, PD_ENABLESETUPTEMPLATEHANDLE},
494 {I_PD_HIDEPRINTTOFILE, PD_HIDEPRINTTOFILE},
495 {I_PD_NOPAGENUMS, PD_NOPAGENUMS},
496 {I_PD_NOSELECTION, PD_NOSELECTION},
497 {I_PD_NOWARNING, PD_NOWARNING},
498 {I_PD_PAGENUMS, PD_PAGENUMS},
499 {I_PD_PRINTSETUP, PD_PRINTSETUP},
500 {I_PD_PRINTTOFILE, PD_PRINTTOFILE},
501 {I_PD_RETURNDC, PD_RETURNDC},
502 {I_PD_RETURNDEFAULT, PD_RETURNDEFAULT},
503 {I_PD_RETURNIC, PD_RETURNIC},
504 {I_PD_SELECTION, PD_SELECTION},
505 {I_PD_SHOWHELP, PD_SHOWHELP},
506 {I_PD_USEDEVMODECOPIES, PD_USEDEVMODECOPIES},
507 {IDOK, 0},
510 return mwcd_Setup(hWnd, uMsg, wParam, lParam, flagTable, &pd.Flags);
513 BOOL CALLBACK mwcd_FileSetup(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
515 static struct FlagTableEntry flagTable[] = {
516 {I_OFN_ALLOWMULTISELECT, OFN_ALLOWMULTISELECT},
517 {I_OFN_CREATEPROMPT, OFN_CREATEPROMPT},
518 {I_OFN_ENABLEHOOK, OFN_ENABLEHOOK},
519 {I_OFN_ENABLETEMPLATE, OFN_ENABLETEMPLATE},
520 {I_OFN_ENABLETEMPLATEHANDLE, OFN_ENABLETEMPLATEHANDLE},
521 {I_OFN_EXTENSIONDIFFERENT, OFN_EXTENSIONDIFFERENT},
522 {I_OFN_FILEMUSTEXIST, OFN_FILEMUSTEXIST},
523 {I_OFN_HIDEREADONLY, OFN_HIDEREADONLY},
524 {I_OFN_NOCHANGEDIR, OFN_NOCHANGEDIR},
525 {I_OFN_NOREADONLYRETURN, OFN_NOREADONLYRETURN},
526 {I_OFN_NOTESTFILECREATE, OFN_NOTESTFILECREATE},
527 {I_OFN_NOVALIDATE, OFN_NOVALIDATE},
528 {I_OFN_OVERWRITEPROMPT, OFN_OVERWRITEPROMPT},
529 {I_OFN_PATHMUSTEXIST, OFN_PATHMUSTEXIST},
530 {I_OFN_READONLY, OFN_READONLY},
531 {I_OFN_SHAREAWARE, OFN_SHAREAWARE},
532 {I_OFN_SHOWHELP, OFN_SHOWHELP},
533 {IDOK, 0},
536 return mwcd_Setup(hWnd, uMsg, wParam, lParam, flagTable, &pd.Flags);
539 BOOL CALLBACK mwcd_About(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
541 switch(uMsg) {
542 case WM_INITDIALOG: return TRUE; // let WINDOWS set the focus.
543 case WM_COMMAND: EndDialog(hWnd, 0); return TRUE; // it's our OK button.
544 default: return FALSE; // it's something else, let Windows worry about it
549 // These functions call custom dialog boxes (resource-loaded, if I do this right).
550 // Right now they don't do a heck of a lot, but at some future time
551 // they will muck about with the flags (and be loaded from the flags) of
552 // the CommDlg structures initialized by the mwi_xxx() routines.
554 void mwc_ColorSetup(HWND hWnd)
556 int r = DialogBox(g_hInstance, "Color_Flags_Dialog", hWnd, (DLGPROC) mwcd_ColorSetup);
557 if(r < 0) { MessageBox(hWnd, "Failure opening Color_Flags_Dialog box", "Error", MB_ICONASTERISK|MB_OK); }
560 void mwc_FontSetup(HWND hWnd)
562 int r = DialogBox(g_hInstance, "Font_Flags_Dialog", hWnd, (DLGPROC) mwcd_FontSetup);
563 if(r < 0) { MessageBox(hWnd, "Failure opening Font_Flags_Dialog box", "Error", MB_ICONASTERISK|MB_OK); }
566 void mwc_FindReplaceSetup(HWND hWnd)
568 int r = DialogBox(g_hInstance, "Find_Flags_Dialog", hWnd, (DLGPROC) mwcd_FindSetup);
569 if(r < 0) { MessageBox(hWnd, "Failure opening Find_Flags_Dialog box", "Error", MB_ICONASTERISK|MB_OK); }
572 void mwc_PrintSetup(HWND hWnd)
574 int r = DialogBox(g_hInstance, "Print_Flags_Dialog", hWnd, (DLGPROC) mwcd_PrintSetup);
575 if(r < 0) { MessageBox(hWnd, "Failure opening Print_Flags_Dialog box", "Error", MB_ICONASTERISK|MB_OK); }
578 void mwc_FileSetup(HWND hWnd)
580 int r = DialogBox(g_hInstance, "File_Flags_Dialog", hWnd, (DLGPROC) mwcd_PrintSetup);
581 if(r < 0) { MessageBox(hWnd, "Failure opening File_Flags_Dialog box", "Error", MB_ICONASTERISK|MB_OK); }
584 // Main window message dispatcher. Here the messages get chewed up
585 // and spit out. Note the ugly hack for the modeless Find/Replace box;
586 // this looks like it was bolted on with hexhead screws and is now
587 // dangling from Windows like a loose muffler. Sigh.
589 LRESULT CALLBACK EXPORT mainWindowDispatcher(
590 HWND hWnd,
591 UINT uMsg,
592 WPARAM wParam,
593 LPARAM lParam
597 if(uMsg == findMessageId) {
598 FINDREPLACE FAR* lpfr = (FINDREPLACE FAR*) lParam;
599 if(lpfr->Flags & FR_DIALOGTERM) {
600 MessageBox(hWnd, "User closing us down.", "Down", MB_OK);
601 findDialogBox = 0;
603 else if (lpfr->Flags & FR_FINDNEXT) {
604 MessageBox(hWnd, "Finding next occurrence.", "Findnext", MB_OK);
606 else if (lpfr->Flags & FR_REPLACE) {
607 MessageBox(hWnd, "Replacing next occurence.", "Replace", MB_OK);
609 else if (lpfr->Flags & FR_REPLACEALL) {
610 MessageBox(hWnd, "Replacing all occurrences.", "Replace All", MB_OK);
612 else {
613 MessageBox(hWnd, "Eh?", "Eh?", MB_OK);
615 return 1;
617 else switch(uMsg) {
618 case WM_CREATE:
619 // this is always the first message...at least as far as
620 // we are concerned.
621 mwi_InitAll(hWnd);
622 break;
624 case WM_PAINT:
625 // Well, draw something!
626 paintMainWindow(hWnd, uMsg, wParam, lParam);
627 break;
629 case WM_DESTROY:
630 // Uh oh. Eject! Eject! Eject!
631 PostQuitMessage(0);
632 break;
634 case WM_COMMAND:
635 // menu or accelerator pressed; do something.
637 switch(wParam) {
638 case CM_U_EXIT:
639 // Uh oh. Eject! Eject! Eject!
640 PostQuitMessage(0);
641 break;
643 // these actually call the Common Dialogs.
645 case CM_U_COLOR:
646 mw_ColorSetup(hWnd); return 1;
648 case CM_U_FONT:
649 mw_FontSetup(hWnd); return 1;
651 case CM_U_FIND:
652 mw_FindSetup(hWnd); return 1;
654 case CM_U_REPLACE:
655 mw_ReplaceSetup(hWnd); return 1;
657 case CM_U_OPEN:
658 mw_OpenSetup(hWnd); return 1;
660 case CM_U_SAVE:
661 mw_SaveSetup(hWnd); return 1;
663 case CM_U_PSETUP:
664 mw_PSetupSetup(hWnd); return 1;
666 case CM_U_PRINT:
667 mw_PrintSetup(hWnd); return 1;
669 // these set up various flags and values in the Common Dialog
670 // data structures, which are currently stored in static memory.
671 // The control dialogs themselves are resources as well.
673 case CM_F_FILE:
674 mwc_FileSetup(hWnd); return 1;
676 case CM_F_COLOR:
677 mwc_ColorSetup(hWnd); return 1;
679 case CM_F_FONT:
680 mwc_FontSetup(hWnd); return 1;
682 case CM_F_FINDREPLACE:
683 mwc_FindReplaceSetup(hWnd); return 1;
685 case CM_F_PRINT:
686 mwc_PrintSetup(hWnd); return 1;
688 case CM_H_ABOUT:
689 DialogBox(g_hInstance, "AboutDialog", hWnd, (DLGPROC) mwcd_About);
690 // return value? *What* return value?
691 return 1;
693 default:
694 nyi(hWnd); return 1;
696 break;
698 default:
699 return DefWindowProc(hWnd, uMsg, wParam, lParam);
701 return 0;
704 // Class registration. One might call this a Windowsism.
706 int registerMainWindowClass(HINSTANCE hInstance)
708 WNDCLASS wndClass;
710 wndClass.style = CS_HREDRAW|CS_VREDRAW;
711 wndClass.lpfnWndProc = mainWindowDispatcher;
712 wndClass.cbClsExtra = 0;
713 wndClass.cbWndExtra = 0;
714 wndClass.hInstance = hInstance;
715 //wndClass.hIcon = LoadIcon(hInstance, "whello");
716 //wndClass.hCursor = LoadCursor(hInstance, IDC_ARROW);
717 wndClass.hIcon = 0;
718 wndClass.hCursor = 0;
719 wndClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
720 wndClass.lpszMenuName = menuName;
721 wndClass.lpszClassName = className;
723 return RegisterClass(&wndClass);
726 // Another Windowsism; this one's not too bad, as it compares
727 // favorably with CreateWindow() in X (mucking about with X Visuals
728 // can get messy; at least here we don't have to worry about that).
730 HWND createMainWindow(HINSTANCE hInstance, int show)
732 HWND hWnd;
734 hWnd = CreateWindow(
735 className, // classname
736 windowName, // windowname/title
737 WS_OVERLAPPEDWINDOW, // dwStyle
738 0, //x
739 0, //y
740 CW_USEDEFAULT, //width
741 CW_USEDEFAULT, //height
742 0, // parent window
743 0, // menu
744 hInstance, // instance
745 0 // passthrough for MDI
748 if(hWnd==0) return 0;
750 ShowWindow(hWnd, show);
751 UpdateWindow(hWnd);
753 return hWnd;
756 int messageLoop(HINSTANCE hInstance, HWND hWnd)
759 MSG msg;
761 while(GetMessage(&msg, 0, 0, 0)) {
762 TranslateMessage(&msg);
763 DispatchMessage(&msg);
766 return msg.wParam;
769 // Oh, did we tell you that main() isn't the name of the
770 // thing called in a Win16/Win32 app? And then there are
771 // the lack of argument lists, the necessity (at least in Win16)
772 // of having to deal with class registration exactly once (as the
773 // app may be run again), and some other bizarre holdovers from
774 // Windows 3.x days. But hey, Solitaire still works.
776 int PASCAL WinMain(
777 HINSTANCE hInstance, HINSTANCE hPrevInstance,
778 LPSTR lpszCmdLine, int nCmdShow
781 HWND hWnd;
783 if(hPrevInstance==0) {
784 if(!registerMainWindowClass(hInstance))
785 return -1;
788 g_hInstance = hInstance;
790 hWnd = createMainWindow(hInstance,nCmdShow);
791 if(hWnd == 0)
792 return -1;
795 return messageLoop(hInstance, hWnd);
798 // And now the end of the program. Enjoy.
800 // (c) 1999 Eric Williams. Rights as specified under the WINE
801 // License. Don't hoard code; share it!