4 * Copyright 1994 Martin Ayotte
16 #include "selectors.h"
17 #include "../rc/sysres.h"
19 #define OPENFILEDLG2 11
20 #define SAVEFILEDLG2 12
22 static DWORD CommDlgLastError
= 0;
24 static HBITMAP hFolder
= 0;
25 static HBITMAP hFolder2
= 0;
26 static HBITMAP hFloppy
= 0;
27 static HBITMAP hHDisk
= 0;
28 static HBITMAP hCDRom
= 0;
30 int DOS_GetDefaultDrive(void);
31 void DOS_SetDefaultDrive(int drive
);
32 char *DOS_GetCurrentDir(int drive
);
33 int DOS_ChangeDir(int drive
, char *dirname
);
35 BOOL
FileOpenDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
);
36 BOOL
FileSaveDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
);
37 BOOL
ColorDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
);
38 BOOL
PrintDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
);
39 BOOL
PrintSetupDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
);
40 BOOL
ReplaceTextDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
);
41 BOOL
FindTextDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
);
43 /***********************************************************************
44 * COMMDLG_IsPathName [internal]
47 static BOOL
COMMDLG_IsPathName(LPSTR str
)
49 if (str
[strlen(str
)-1] == ':' && strlen(str
) == 2) return TRUE
;
50 if (str
[strlen(str
)-1] == '\\') return TRUE
;
51 if (strchr(str
,'*') != NULL
) return TRUE
;
55 /***********************************************************************
56 * FileDlg_Init [internal]
58 static BOOL
FileDlg_Init()
60 if (!hFolder
) hFolder
= LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER
));
61 if (!hFolder2
) hFolder2
= LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER2
));
62 if (!hFloppy
) hFloppy
= LoadBitmap(0, MAKEINTRESOURCE(OBM_FLOPPY
));
63 if (!hHDisk
) hHDisk
= LoadBitmap(0, MAKEINTRESOURCE(OBM_HDISK
));
64 if (!hCDRom
) hCDRom
= LoadBitmap(0, MAKEINTRESOURCE(OBM_CDROM
));
65 if (hFolder
== 0 || hFolder2
== 0 || hFloppy
== 0 ||
66 hHDisk
== 0 || hCDRom
== 0)
67 fprintf(stderr
, "FileDlg_Init // Error loading bitmaps !");
71 /***********************************************************************
72 * OpenDlg_FixDirName [internal]
74 void OpenDlg_FixDirName(LPSTR dirname
)
81 if( dirname
[1] != ':'){
82 temp
[0]=(char)((char)DOS_GetDefaultDrive()+'A');
86 strcat(temp
, DOS_GetCurrentDir(DOS_GetDefaultDrive()));
87 if(dirname
[0]=='.' && dirname
[1]=='.') {
88 strp2
= strrchr(temp
, '\\');
96 strcpy(dirname
, temp
);
101 /***********************************************************************
102 * OpenDlg_ScanDir [internal]
104 static BOOL
OpenDlg_ScanDir(HWND hWnd
, LPSTR newPath
)
106 static HANDLE hStr
= 0;
107 static LPSTR str
= NULL
;
108 static SEGPTR str16
= 0;
111 OpenDlg_FixDirName(newPath
);
113 hStr
= GlobalAlloc(0,512);
114 str
= GlobalLock(hStr
);
115 str16
= WIN16_GlobalLock(hStr
);
119 DlgDirList(hWnd
, str
, lst1
, 0, 0x0000);
120 strp
= strrchr(str
,'\\');
129 SendDlgItemMessage(hWnd
,edt1
,WM_SETTEXT
, 0, str16
);
131 DlgDirList(hWnd
, str
, lst2
, stc1
, 0x8010);
136 /***********************************************************************
137 * OpenDlg_GetFileType [internal]
139 static LPSTR
OpenDlg_GetFileType(LPCSTR types
, WORD index
)
143 LPSTR ptr
= (LPSTR
) types
;
144 if (ptr
== NULL
) return NULL
;
145 while((n
= strlen(ptr
)) != 0) {
147 if (i
++ == index
) return ptr
;
154 /***********************************************************************
155 * GetOpenFileName [COMMDLG.1]
157 BOOL
GetOpenFileName(LPOPENFILENAME lpofn
)
165 if (lpofn
== NULL
) return FALSE
;
166 if (lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
) {
167 dlgTemplate
= GlobalLock(lpofn
->hInstance
);
169 CommDlgLastError
= CDERR_LOADRESFAILURE
;
173 if (lpofn
->Flags
& OFN_ENABLETEMPLATE
) {
174 hInst
= lpofn
->hInstance
;
175 hResInfo
= FindResource(hInst
, lpofn
->lpTemplateName
, RT_DIALOG
);
177 CommDlgLastError
= CDERR_FINDRESFAILURE
;
180 hDlgTmpl
= LoadResource(hInst
, hResInfo
);
182 CommDlgLastError
= CDERR_LOADRESFAILURE
;
185 dlgTemplate
= GlobalLock(hDlgTmpl
);
187 dlgTemplate
= sysres_DIALOG_3
;
190 hInst
= GetWindowWord(lpofn
->hwndOwner
, GWW_HINSTANCE
);
191 bRet
= DialogBoxIndirectParamPtr(hInst
, dlgTemplate
, lpofn
->hwndOwner
,
192 GetWndProcEntry16("FileOpenDlgProc"),
195 printf("GetOpenFileName // return lpstrFile='%s' !\n",
196 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
201 /***********************************************************************
202 * GetSaveFileName [COMMDLG.2]
204 BOOL
GetSaveFileName(LPOPENFILENAME lpofn
)
212 if (lpofn
== NULL
) return FALSE
;
213 if (lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
) {
214 dlgTemplate
= GlobalLock(lpofn
->hInstance
);
216 CommDlgLastError
= CDERR_LOADRESFAILURE
;
220 if (lpofn
->Flags
& OFN_ENABLETEMPLATE
) {
221 hInst
= lpofn
->hInstance
;
222 hResInfo
= FindResource(hInst
, lpofn
->lpTemplateName
, RT_DIALOG
);
224 CommDlgLastError
= CDERR_FINDRESFAILURE
;
227 hDlgTmpl
= LoadResource(hInst
, hResInfo
);
229 CommDlgLastError
= CDERR_LOADRESFAILURE
;
232 dlgTemplate
= GlobalLock(hDlgTmpl
);
234 dlgTemplate
= sysres_DIALOG_4
; /* SAVEFILEDIALOG */
237 hInst
= GetWindowWord(lpofn
->hwndOwner
, GWW_HINSTANCE
);
238 bRet
= DialogBoxIndirectParamPtr(hInst
, dlgTemplate
, lpofn
->hwndOwner
,
239 GetWndProcEntry16("FileSaveDlgProc"),
241 printf("GetSaveFileName // return lpstrFile='%s' !\n",
242 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
247 /***********************************************************************
248 * ChooseColor [COMMDLG.5]
250 BOOL
ChooseColor(LPCHOOSECOLOR lpChCol
)
254 wndPtr
= WIN_FindWndPtr(lpChCol
->hwndOwner
);
255 bRet
= DialogBoxIndirectParamPtr(wndPtr
->hInstance
, sysres_DIALOG_8
,
256 lpChCol
->hwndOwner
, GetWndProcEntry16("ColorDlgProc"),
262 /***********************************************************************
263 * FileOpenDlgProc [COMMDLG.6]
265 BOOL
FileOpenDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
)
276 LPMEASUREITEMSTRUCT lpmeasure
;
277 LPDRAWITEMSTRUCT lpdis
;
279 static LPOPENFILENAME lpofn
;/* FIXME - this won't multitask */
283 static HANDLE hStr
= 0;
284 static LPSTR str
= NULL
;
285 static SEGPTR str16
= 0;
288 hStr
= GlobalAlloc(0,512);
289 str
= GlobalLock(hStr
);
290 str16
= WIN16_GlobalLock(hStr
);
295 printf("FileOpenDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
296 if (!FileDlg_Init()) return TRUE
;
297 SendDlgItemMessage(hWnd
, cmb1
, CB_RESETCONTENT
, 0, 0);
298 lpofn
= (LPOPENFILENAME
)lParam
;
299 ptr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFilter
);
300 tempsegp
= lpofn
->lpstrFilter
;
303 SendDlgItemMessage(hWnd
, cmb1
, CB_ADDSTRING
, 0, tempsegp
);
304 ptr
+= n
+ 1; tempsegp
+= n
+ 1;
306 ptr
+= n
+ 1; tempsegp
+= n
+ 1;
308 /* set default filter */
309 SendDlgItemMessage(hWnd
, cmb1
, CB_SETCURSEL
,
310 lpofn
->nFilterIndex
- 1, 0L);
311 /* get drive information into combo 2 */
313 DlgDirListComboBox(hWnd
, str16
, cmb2
, 0, 0xC000);
315 if (PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
) != NULL
) {
316 strcpy(str
, PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
));
317 if (str
[strlen(str
)-1] != '\\' && str
[strlen(str
)-1] != ':') {
323 lRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
324 if (lRet
== LB_ERR
) return FALSE
;
325 fspec
= OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lRet
+ 1);
328 if (!OpenDlg_ScanDir(hWnd
, str
)) {
329 printf("OpenDlg_ScanDir // ChangeDir Error !\n");
331 /* select current drive in combo */
332 nDrive
= DOS_GetDefaultDrive();
333 SendDlgItemMessage(hWnd
, cmb2
, CB_SETCURSEL
, nDrive
, 0L);
335 ShowWindow(hWnd
, SW_SHOWNORMAL
);
339 if (wParam
== 0) break;
340 if (!(lpofn
->Flags
& OFN_SHOWHELP
)) {
341 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
343 if (lpofn
->Flags
& OFN_HIDEREADONLY
) {
344 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
349 GetObject(hFolder2
, sizeof(BITMAP
), (LPSTR
)&bm
);
350 lpmeasure
= (LPMEASUREITEMSTRUCT
)PTR_SEG_TO_LIN(lParam
);
351 lpmeasure
->itemHeight
= bm
.bmHeight
;
355 if (lParam
== 0L) break;
356 lpdis
= (LPDRAWITEMSTRUCT
)PTR_SEG_TO_LIN(lParam
);
357 if ((lpdis
->CtlType
== ODT_LISTBOX
) && (lpdis
->CtlID
== lst1
)) {
358 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
359 SelectObject(lpdis
->hDC
, hBrush
);
360 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
361 ptr
= (LPSTR
) PTR_SEG_TO_LIN(lpdis
->itemData
);
362 if (ptr
== NULL
) break;
363 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
365 if (lpdis
->itemState
!= 0) {
366 InvertRect(lpdis
->hDC
, &lpdis
->rcItem
);
370 if ((lpdis
->CtlType
== ODT_LISTBOX
) && (lpdis
->CtlID
== lst2
)) {
371 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
372 SelectObject(lpdis
->hDC
, hBrush
);
373 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
374 ptr
= (LPSTR
) PTR_SEG_TO_LIN(lpdis
->itemData
);
375 if (ptr
== NULL
) break;
377 GetObject(hBitmap
, sizeof(BITMAP
), (LPSTR
)&bm
);
378 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
379 lpdis
->rcItem
.top
, ptr
, strlen(ptr
));
380 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
381 SelectObject(hMemDC
, hBitmap
);
382 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
383 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
385 if (lpdis
->itemState
!= 0) {
386 InvertRect(lpdis
->hDC
, &lpdis
->rcItem
);
390 if ((lpdis
->CtlType
== ODT_COMBOBOX
) && (lpdis
->CtlID
== cmb2
)) {
391 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
392 SelectObject(lpdis
->hDC
, hBrush
);
393 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
394 ptr
= (LPSTR
) PTR_SEG_TO_LIN(lpdis
->itemData
);
395 if (ptr
== NULL
) break;
404 GetObject(hBitmap
, sizeof(BITMAP
), (LPSTR
)&bm
);
405 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
406 lpdis
->rcItem
.top
, ptr
, strlen(ptr
));
407 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
408 SelectObject(hMemDC
, hBitmap
);
409 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
410 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
412 if (lpdis
->itemState
!= 0) {
413 InvertRect(lpdis
->hDC
, &lpdis
->rcItem
);
422 if (HIWORD(lParam
) == LBN_DBLCLK
) {
423 lRet
= SendDlgItemMessage(hWnd
, lst1
, LB_GETCURSEL
, 0, 0L);
424 if (lRet
== LB_ERR
) return 0;
425 SendDlgItemMessage(hWnd
, lst1
, LB_GETTEXT
, lRet
, str16
);
426 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, str16
);
427 return SendMessage(hWnd
, WM_COMMAND
, IDOK
, 0);
431 if (HIWORD(lParam
) == LBN_DBLCLK
) {
432 lRet
= SendDlgItemMessage(hWnd
, lst2
, LB_GETCURSEL
, 0, 0L);
433 if (lRet
== LB_ERR
) return 0;
434 SendDlgItemMessage(hWnd
, lst2
, LB_GETTEXT
, lRet
, str16
);
437 str
[strlen(str
) - 1] = 0;
441 lRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
442 if (lRet
== LB_ERR
) return FALSE
;
443 fspec
= OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lRet
+ 1);
444 strcat(str
,"\\"); strcat(str
,fspec
);
445 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, str16
);
446 return SendMessage(hWnd
, WM_COMMAND
, IDOK
, 0);
450 if (HIWORD(lParam
) == CBN_SELCHANGE
) {
451 lRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0L);
452 if (lRet
== LB_ERR
) return FALSE
;
453 fspec
= OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lRet
+ 1);
455 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, str16
);
456 return SendMessage(hWnd
, WM_COMMAND
, IDOK
, 0);
460 wRet
= SendDlgItemMessage(hWnd
, cmb2
, CB_GETCURSEL
, 0, 0L);
461 if (wRet
== (WORD
)LB_ERR
) return 0;
462 SendDlgItemMessage(hWnd
, cmb2
, CB_GETLBTEXT
, wRet
, str16
);
463 str
[0] = str
[2]; str
[1] = ':'; str
[2] = 0;
464 lRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0L);
465 if (lRet
== LB_ERR
) return FALSE
;
466 fspec
= OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lRet
+ 1);
468 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, str16
);
469 return SendMessage(hWnd
, WM_COMMAND
, IDOK
, 0);
473 printf("FileOpenDlgProc // read-only toggled !\n");
478 printf("FileOpenDlgProc // pshHelp pressed !\n");
482 SendDlgItemMessage(hWnd
, edt1
, WM_GETTEXT
, 511, str16
);
483 if (COMMDLG_IsPathName(str
)) {
484 OpenDlg_ScanDir(hWnd
, str
);
486 ShowWindow(hWnd
, SW_HIDE
);
487 strcpy(PTR_SEG_TO_LIN(lpofn
->lpstrFile
), str
);
488 lpofn
->nFileOffset
= 0;
489 lpofn
->nFileExtension
= strlen(PTR_SEG_TO_LIN(lpofn
->lpstrFile
)) - 3;
490 if (PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
) != NULL
) {
491 wRet
= SendDlgItemMessage(hWnd
, lst1
, LB_GETCURSEL
, 0, 0L);
492 SendDlgItemMessage(hWnd
, lst1
, LB_GETTEXT
, wRet
, str16
);
493 strcpy(PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
), str
);
495 EndDialog(hWnd
, TRUE
);
499 EndDialog(hWnd
, FALSE
);
507 SetBkColor((HDC)wParam, 0x00C0C0C0);
508 switch (HIWORD(lParam))
511 SetTextColor((HDC)wParam, 0x00000000);
513 case CTLCOLOR_STATIC:
514 SetTextColor((HDC)wParam, 0x00000000);
524 /***********************************************************************
525 * FileSaveDlgProc [COMMDLG.7]
527 BOOL
FileSaveDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
)
538 LPMEASUREITEMSTRUCT lpmeasure
;
539 LPDRAWITEMSTRUCT lpdis
;
541 static LPOPENFILENAME lpofn
;/* FIXME - this won't multitask */
545 static HANDLE hStr
= 0;
546 static LPSTR str
= NULL
;
547 static SEGPTR str16
= 0;
550 hStr
= GlobalAlloc(0,512);
551 str
= GlobalLock(hStr
);
552 str16
= WIN16_GlobalLock(hStr
);
557 printf("FileSaveDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
558 if (!FileDlg_Init()) return TRUE
;
559 SendDlgItemMessage(hWnd
, cmb1
, CB_RESETCONTENT
, 0, 0);
560 lpofn
= (LPOPENFILENAME
)lParam
;
561 ptr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFilter
);
562 tempsegp
= lpofn
->lpstrFilter
;
565 SendDlgItemMessage(hWnd
, cmb1
, CB_ADDSTRING
, 0, tempsegp
);
566 ptr
+= n
+ 1; tempsegp
+= n
+ 1;
568 ptr
+= n
+ 1; tempsegp
+= n
+ 1;
570 /* set default filter */
571 SendDlgItemMessage(hWnd
, cmb1
, CB_SETCURSEL
,
572 lpofn
->nFilterIndex
- 1, 0L);
573 /* get drive information into combo 2 */
575 DlgDirListComboBox(hWnd
, str16
, cmb2
, 0, 0xC000);
577 if (PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
) != NULL
) {
578 strcpy(str
, PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
));
579 if (str
[strlen(str
)-1] != '\\' && str
[strlen(str
)-1] != ':') {
585 lRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
586 if (lRet
== LB_ERR
) return FALSE
;
587 fspec
= OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lRet
+ 1);
590 if (!OpenDlg_ScanDir(hWnd
, str
)) {
591 printf("SaveDlg_ScanDir // ChangeDir Error !\n");
593 /* select current drive in combo */
594 nDrive
= DOS_GetDefaultDrive();
595 SendDlgItemMessage(hWnd
, cmb2
, CB_SETCURSEL
, nDrive
, 0L);
597 ShowWindow(hWnd
, SW_SHOWNORMAL
);
601 if (wParam
== 0) break;
602 if (!(lpofn
->Flags
& OFN_SHOWHELP
)) {
603 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
605 if (lpofn
->Flags
& OFN_HIDEREADONLY
) {
606 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
611 GetObject(hFolder2
, sizeof(BITMAP
), (LPSTR
)&bm
);
612 lpmeasure
= (LPMEASUREITEMSTRUCT
)PTR_SEG_TO_LIN(lParam
);
613 lpmeasure
->itemHeight
= bm
.bmHeight
;
617 if (lParam
== 0L) break;
618 lpdis
= (LPDRAWITEMSTRUCT
)PTR_SEG_TO_LIN(lParam
);
619 if ((lpdis
->CtlType
== ODT_LISTBOX
) && (lpdis
->CtlID
== lst1
)) {
620 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
621 SelectObject(lpdis
->hDC
, hBrush
);
622 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
623 ptr
= (LPSTR
) PTR_SEG_TO_LIN(lpdis
->itemData
);
624 if (ptr
== NULL
) break;
625 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
627 if (lpdis
->itemState
!= 0) {
628 InvertRect(lpdis
->hDC
, &lpdis
->rcItem
);
632 if ((lpdis
->CtlType
== ODT_LISTBOX
) && (lpdis
->CtlID
== lst2
)) {
633 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
634 SelectObject(lpdis
->hDC
, hBrush
);
635 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
636 ptr
= (LPSTR
) PTR_SEG_TO_LIN(lpdis
->itemData
);
637 if (ptr
== NULL
) break;
639 GetObject(hBitmap
, sizeof(BITMAP
), (LPSTR
)&bm
);
640 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
641 lpdis
->rcItem
.top
, ptr
, strlen(ptr
));
642 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
643 SelectObject(hMemDC
, hBitmap
);
644 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
645 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
647 if (lpdis
->itemState
!= 0) {
648 InvertRect(lpdis
->hDC
, &lpdis
->rcItem
);
652 if ((lpdis
->CtlType
== ODT_COMBOBOX
) && (lpdis
->CtlID
== cmb2
)) {
653 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
654 SelectObject(lpdis
->hDC
, hBrush
);
655 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
656 ptr
= (LPSTR
) PTR_SEG_TO_LIN(lpdis
->itemData
);
657 if (ptr
== NULL
) break;
666 GetObject(hBitmap
, sizeof(BITMAP
), (LPSTR
)&bm
);
667 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
668 lpdis
->rcItem
.top
, ptr
, strlen(ptr
));
669 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
670 SelectObject(hMemDC
, hBitmap
);
671 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
672 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
674 if (lpdis
->itemState
!= 0) {
675 InvertRect(lpdis
->hDC
, &lpdis
->rcItem
);
684 if (HIWORD(lParam
) == LBN_DBLCLK
) {
685 lRet
= SendDlgItemMessage(hWnd
, lst1
, LB_GETCURSEL
, 0, 0L);
686 if (lRet
== LB_ERR
) return 0;
687 SendDlgItemMessage(hWnd
, lst1
, LB_GETTEXT
, lRet
, str16
);
688 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, str16
);
689 return SendMessage(hWnd
, WM_COMMAND
, IDOK
, 0);
693 if (HIWORD(lParam
) == LBN_DBLCLK
) {
694 lRet
= SendDlgItemMessage(hWnd
, lst2
, LB_GETCURSEL
, 0, 0L);
695 if (lRet
== LB_ERR
) return 0;
696 SendDlgItemMessage(hWnd
, lst2
, LB_GETTEXT
, lRet
, str16
);
699 str
[strlen(str
) - 1] = 0;
703 lRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
704 if (lRet
== LB_ERR
) return FALSE
;
705 fspec
= OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lRet
+ 1);
706 strcat(str
,"\\"); strcat(str
,fspec
);
707 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, str16
);
708 return SendMessage(hWnd
, WM_COMMAND
, IDOK
, 0);
712 if (HIWORD(lParam
) == CBN_SELCHANGE
) {
713 lRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0L);
714 if (lRet
== LB_ERR
) return FALSE
;
715 fspec
= OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lRet
+ 1);
717 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, str16
);
718 return SendMessage(hWnd
, WM_COMMAND
, IDOK
, 0);
722 wRet
= SendDlgItemMessage(hWnd
, cmb2
, CB_GETCURSEL
, 0, 0L);
723 if (wRet
== (WORD
)LB_ERR
) return 0;
724 SendDlgItemMessage(hWnd
, cmb2
, CB_GETLBTEXT
, wRet
, str16
);
725 str
[0] = str
[2]; str
[1] = ':'; str
[2] = 0;
726 lRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0L);
727 if (lRet
== LB_ERR
) return FALSE
;
728 fspec
= OpenDlg_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lRet
+ 1);
730 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, str16
);
731 return SendMessage(hWnd
, WM_COMMAND
, IDOK
, 0);
735 printf("FileSaveDlgProc // read-only toggled !\n");
740 printf("FileSaveDlgProc // pshHelp pressed !\n");
744 SendDlgItemMessage(hWnd
, edt1
, WM_GETTEXT
, 511, str16
);
745 if (COMMDLG_IsPathName(str
)) {
746 OpenDlg_ScanDir(hWnd
, str
);
748 ShowWindow(hWnd
, SW_HIDE
);
749 strcpy(PTR_SEG_TO_LIN(lpofn
->lpstrFile
), str
);
750 lpofn
->nFileOffset
= 0;
751 lpofn
->nFileExtension
= strlen(PTR_SEG_TO_LIN(lpofn
->lpstrFile
)) - 3;
752 if (PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
) != NULL
) {
753 wRet
= SendDlgItemMessage(hWnd
, lst1
, LB_GETCURSEL
, 0, 0L);
754 SendDlgItemMessage(hWnd
, lst1
, LB_GETTEXT
, wRet
, str16
);
755 strcpy(PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
), str
);
757 EndDialog(hWnd
, TRUE
);
761 EndDialog(hWnd
, FALSE
);
770 SetBkColor((HDC)wParam, 0x00C0C0C0);
771 switch (HIWORD(lParam))
774 SetTextColor((HDC)wParam, 0x00000000);
776 case CTLCOLOR_STATIC:
777 SetTextColor((HDC)wParam, 0x00000000);
787 /***********************************************************************
788 * ColorDlgProc [COMMDLG.8]
790 BOOL
ColorDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
)
794 printf("ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
795 ShowWindow(hWnd
, SW_SHOWNORMAL
);
801 EndDialog(hWnd
, TRUE
);
804 EndDialog(hWnd
, FALSE
);
813 /***********************************************************************
814 * FindTextDlg [COMMDLG.11]
816 BOOL
FindText(LPFINDREPLACE lpFind
)
822 lpTemplate
= sysres_DIALOG_9
;
823 wndPtr
= WIN_FindWndPtr(lpFind
->hwndOwner
);
824 bRet
= DialogBoxIndirectParamPtr(wndPtr
->hInstance
, lpTemplate
,
825 lpFind
->hwndOwner
, GetWndProcEntry16("FindTextDlgProc"),
831 /***********************************************************************
832 * ReplaceTextDlg [COMMDLG.12]
834 BOOL
ReplaceText(LPFINDREPLACE lpFind
)
840 lpTemplate
= sysres_DIALOG_10
;
841 wndPtr
= WIN_FindWndPtr(lpFind
->hwndOwner
);
842 bRet
= DialogBoxIndirectParamPtr(wndPtr
->hInstance
, lpTemplate
,
843 lpFind
->hwndOwner
, GetWndProcEntry16("ReplaceTextDlgProc"),
849 /***********************************************************************
850 * FindTextDlgProc [COMMDLG.13]
852 BOOL
FindTextDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
)
856 printf("FindTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
857 ShowWindow(hWnd
, SW_SHOWNORMAL
);
863 EndDialog(hWnd
, TRUE
);
866 EndDialog(hWnd
, FALSE
);
875 /***********************************************************************
876 * ReplaceTextDlgProc [COMMDLG.14]
878 BOOL
ReplaceTextDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
)
882 printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
883 ShowWindow(hWnd
, SW_SHOWNORMAL
);
889 EndDialog(hWnd
, TRUE
);
892 EndDialog(hWnd
, FALSE
);
901 /***********************************************************************
902 * PrintDlg [COMMDLG.20]
904 BOOL
PrintDlg(LPPRINTDLG lpPrint
)
910 printf("PrintDlg(%p) // Flags=%08lX\n", lpPrint
, lpPrint
->Flags
);
911 if (lpPrint
->Flags
& PD_PRINTSETUP
) {
912 lpTemplate
= sysres_DIALOG_6
;
914 lpTemplate
= sysres_DIALOG_5
;
916 wndPtr
= WIN_FindWndPtr(lpPrint
->hwndOwner
);
917 if (lpPrint
->Flags
& PD_PRINTSETUP
)
918 bRet
= DialogBoxIndirectParamPtr(wndPtr
->hInstance
, lpTemplate
,
919 lpPrint
->hwndOwner
, GetWndProcEntry16("PrintSetupDlgProc"),
922 bRet
= DialogBoxIndirectParamPtr(wndPtr
->hInstance
, lpTemplate
,
923 lpPrint
->hwndOwner
, GetWndProcEntry16("PrintDlgProc"),
929 /***********************************************************************
930 * PrintDlgProc [COMMDLG.21]
932 BOOL
PrintDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
)
936 printf("PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
937 ShowWindow(hWnd
, SW_SHOWNORMAL
);
943 EndDialog(hWnd
, TRUE
);
946 EndDialog(hWnd
, FALSE
);
955 /***********************************************************************
956 * PrintSetupDlgProc [COMMDLG.22]
958 BOOL
PrintSetupDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
)
962 printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
963 ShowWindow(hWnd
, SW_SHOWNORMAL
);
969 EndDialog(hWnd
, TRUE
);
972 EndDialog(hWnd
, FALSE
);
981 /***********************************************************************
982 * CommDlgExtendError [COMMDLG.26]
984 DWORD
CommDlgExtendError(void)
986 return CommDlgLastError
;
990 /***********************************************************************
991 * GetFileTitle [COMMDLG.27]
993 int GetFileTitle(LPCSTR lpFile
, LPSTR lpTitle
, UINT cbBuf
)
996 printf("GetFileTitle(%p %p %d); \n", lpFile
, lpTitle
, cbBuf
);
997 if (lpFile
== NULL
|| lpTitle
== NULL
) return -1;
998 len
= strlen(lpFile
);
999 if (len
== 0) return -1;
1000 if (strchr(lpFile
, '*') != NULL
) return -1;
1001 if (strchr(lpFile
, '[') != NULL
) return -1;
1002 if (strchr(lpFile
, ']') != NULL
) return -1;
1004 if (lpFile
[len
] == '/' || lpFile
[len
] == '\\' || lpFile
[len
] == ':') return -1;
1005 for (i
= len
; i
>= 0; i
--) {
1006 if (lpFile
[i
] == '/' || lpFile
[i
] == '\\' || lpFile
[i
] == ':') {
1011 printf("\n---> '%s' ", &lpFile
[i
]);
1012 len
= min(cbBuf
, strlen(&lpFile
[i
]) + 1);
1013 strncpy(lpTitle
, &lpFile
[i
], len
+ 1);