4 * Copyright 1994 Martin Ayotte
6 static char Copyright
[] = "Copyright Martin Ayotte, 1994";
10 #define DEBUG_OPENDLG_DRAW
22 #define OPENFILEDLG2 11
23 #define SAVEFILEDLG2 12
26 extern HINSTANCE hSysRes
;
27 static DWORD CommDlgLastError
= 0;
29 static HBITMAP hFolder
= 0;
30 static HBITMAP hFolder2
= 0;
31 static HBITMAP hFloppy
= 0;
32 static HBITMAP hHDisk
= 0;
33 static HBITMAP hCDRom
= 0;
35 int DOS_GetDefaultDrive(void);
36 void DOS_SetDefaultDrive(int drive
);
37 char *DOS_GetCurrentDir(int drive
);
38 int DOS_ChangeDir(int drive
, char *dirname
);
40 BOOL
FileDlg_Init(HWND hWnd
, DWORD lParam
);
41 BOOL
OpenDlg_ScanFiles(HWND hWnd
, WORD nDrive
, LPSTR newPath
, LPSTR fileSpec
);
42 BOOL
OpenDlg_ScanDir(HWND hWnd
, WORD nDrive
, LPSTR newPath
, LPSTR fileSpec
);
43 LPSTR
OpenDlg_GetFileType(LPCSTR types
, WORD index
);
44 LPSTR
OpenDlg_ExtractCurDir(LPSTR FullPath
, short MaxLen
);
45 BOOL
FileOpenDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
);
46 BOOL
FileSaveDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
);
47 BOOL
ColorDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
);
48 BOOL
PrintDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
);
49 BOOL
PrintSetupDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
);
50 BOOL
ReplaceTextDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
);
51 BOOL
FindTextDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
);
53 /***********************************************************************
54 * GetOpenFileName [COMMDLG.1]
56 BOOL
GetOpenFileName(LPOPENFILENAME lpofn
)
63 printf("GetOpenFileName(%08X); !\n", lpofn
);
64 if (lpofn
== NULL
) return FALSE
;
65 printf("GetOpenFileName // Flags=%08X !\n", lpofn
->Flags
);
66 printf("GetOpenFileName // nMaxFile=%d lpstrFile='%s' !\n",
67 lpofn
->nMaxFile
, lpofn
->lpstrFile
);
68 printf("GetOpenFileName // lpstrInitialDir='%s' !\n", lpofn
->lpstrInitialDir
);
69 printf("GetOpenFileName // lpstrFilter=%08X !\n", lpofn
->lpstrFilter
);
70 printf("GetOpenFileName // nFilterIndex=%d !\n", lpofn
->nFilterIndex
);
71 if (lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
) {
72 hDlgTmpl
= lpofn
->hInstance
;
75 if (lpofn
->Flags
& OFN_ENABLETEMPLATE
) {
76 printf("GetOpenFileName // avant FindResource hInstance=%04X lpTemplateName='%s' !\n",
77 lpofn
->hInstance
, lpofn
->lpTemplateName
);
78 hInst
= lpofn
->hInstance
;
79 hResInfo
= FindResource(hInst
,
80 (LPSTR
)lpofn
->lpTemplateName
, RT_DIALOG
);
83 printf("GetOpenFileName // avant FindResource hSysRes=%04X !\n", hSysRes
);
85 hResInfo
= FindResource(hInst
, MAKEINTRESOURCE(OPENFILEDLG2
), RT_DIALOG
);
88 CommDlgLastError
= CDERR_FINDRESFAILURE
;
91 printf("GetOpenFileName // apres FindResource hResInfo=%04X!\n", hResInfo
);
92 hDlgTmpl
= LoadResource(hInst
, hResInfo
);
95 CommDlgLastError
= CDERR_LOADRESFAILURE
;
98 printf("GetOpenFileName // apres LoadResource hDlgTmpl=%04X!\n", hDlgTmpl
);
99 wndPtr
= WIN_FindWndPtr(lpofn
->hwndOwner
);
100 bRet
= DialogBoxIndirectParam(wndPtr
->hInstance
, hDlgTmpl
,
101 lpofn
->hwndOwner
, (WNDPROC
)FileOpenDlgProc
, (DWORD
)lpofn
);
103 /* strcpy(lpofn->lpstrFile, "SETUP.TXT"); */
104 /* strcpy(lpofn->lpstrFileTitle, "SETUP.TXT");*/
106 lpofn->nFileOffset = 0;
107 lpofn->nFileExtension = strlen(lpofn->lpstrFile) - 3;
110 printf("GetOpenFileName // return lpstrFile='%s' !\n", lpofn
->lpstrFile
);
115 /***********************************************************************
116 * GetSaveFileName [COMMDLG.2]
118 BOOL
GetSaveFileName(LPOPENFILENAME lpofn
)
125 printf("GetSaveFileName(%08X); !\n", lpofn
);
126 if (lpofn
== NULL
) return FALSE
;
127 printf("GetSaveFileName // Flags=%08X !\n", lpofn
->Flags
);
128 printf("GetSaveFileName // nMaxFile=%d lpstrFile='%s' !\n",
129 lpofn
->nMaxFile
, lpofn
->lpstrFile
);
130 printf("GetSaveFileName // lpstrInitialDir='%s' !\n", lpofn
->lpstrInitialDir
);
131 printf("GetSaveFileName // lpstrFilter=%08X !\n", lpofn
->lpstrFilter
);
132 if (lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
) {
133 hDlgTmpl
= lpofn
->hInstance
;
136 if (lpofn
->Flags
& OFN_ENABLETEMPLATE
) {
137 printf("GetSaveFileName // avant FindResource lpTemplateName='%s' !\n",
138 lpofn
->lpTemplateName
);
139 hInst
= lpofn
->hInstance
;
140 hResInfo
= FindResource(hInst
,
141 (LPSTR
)lpofn
->lpTemplateName
, RT_DIALOG
);
144 printf("GetSaveFileName // avant FindResource !\n");
146 hResInfo
= FindResource(hInst
, MAKEINTRESOURCE(SAVEFILEDLG2
), RT_DIALOG
);
149 CommDlgLastError
= CDERR_FINDRESFAILURE
;
152 hDlgTmpl
= LoadResource(hInst
, hResInfo
);
155 CommDlgLastError
= CDERR_LOADRESFAILURE
;
158 wndPtr
= WIN_FindWndPtr(lpofn
->hwndOwner
);
159 bRet
= DialogBoxIndirectParam(wndPtr
->hInstance
, hDlgTmpl
,
160 lpofn
->hwndOwner
, (WNDPROC
)FileSaveDlgProc
, (DWORD
)lpofn
);
161 printf("GetSaveFileName // return lpstrFile='%s' !\n", lpofn
->lpstrFile
);
166 /***********************************************************************
167 * ChooseColor [COMMDLG.5]
169 BOOL
ChooseColor(LPCHOOSECOLOR lpChCol
)
175 hResInfo
= FindResource(hSysRes
, MAKEINTRESOURCE(COLORDLG
), RT_DIALOG
);
176 hDlgTmpl
= LoadResource(hSysRes
, hResInfo
);
177 wndPtr
= WIN_FindWndPtr(lpChCol
->hwndOwner
);
178 bRet
= DialogBoxIndirectParam(wndPtr
->hInstance
, hDlgTmpl
,
179 lpChCol
->hwndOwner
, (WNDPROC
)ColorDlgProc
, (DWORD
)lpChCol
);
184 /***********************************************************************
185 * FileOpenDlgProc [COMMDLG.6]
187 BOOL
FileOpenDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
)
200 LPMEASUREITEMSTRUCT lpmeasure
;
201 LPDRAWITEMSTRUCT lpdis
;
203 static char CurPath
[512];
204 static LPOPENFILENAME lpofn
;
209 printf("FileOpenDlgProc // WM_INITDIALOG lParam=%08X\n", lParam
);
211 printf("FileOpenDlgProc // WM_INITDIALOG lParam=%08X\n", lParam
);
212 if (!FileDlg_Init(hWnd
, lParam
)) return TRUE
;
213 SendDlgItemMessage(hWnd
, cmb1
, CB_RESETCONTENT
, 0, 0L);
214 lpofn
= (LPOPENFILENAME
)lParam
;
215 ptr
= (LPSTR
)lpofn
->lpstrFilter
;
216 strcpy(CurPath
, lpofn
->lpstrInitialDir
);
218 printf("FileOpenDlgProc // lpstrInitialDir='%s' !\n", CurPath
);
220 while((n
= strlen(ptr
)) != 0) {
222 printf("FileOpenDlgProc // file type '%s' !\n", ptr
);
224 SendDlgItemMessage(hWnd
, cmb1
, CB_ADDSTRING
, 0, (DWORD
)ptr
);
227 printf("FileOpenDlgProc // file spec '%s' !\n", ptr
);
232 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (DWORD
)str
);
233 SendDlgItemMessage(hWnd
, cmb1
, CB_SETCURSEL
,
234 lpofn
->nFilterIndex
- 1, 0L);
235 DlgDirListComboBox(hWnd
, "", cmb2
, 0, 0xC000);
236 nDrive
= 2; /* Drive 'C:' */
237 SendDlgItemMessage(hWnd
, cmb2
, CB_SETCURSEL
, nDrive
, 0L);
238 sprintf(str
, "%c:\\%s", nDrive
+ 'A', DOS_GetCurrentDir(nDrive
));
239 fspec
= OpenDlg_GetFileType(lpofn
->lpstrFilter
,
240 lpofn
->nFilterIndex
);
242 printf("FileOpenDlgProc // WM_INITDIALOG fspec #%d = '%s' !\n",
243 lpofn
->nFilterIndex
, fspec
);
245 if (!OpenDlg_ScanDir(hWnd
, nDrive
, str
, fspec
)) {
246 printf("OpenDlg_ScanDir // ChangeDir Error !\n");
249 strcpy(CurPath
, str
);
251 ShowWindow(hWnd
, SW_SHOWNORMAL
);
255 if (wParam
== 0) break;
256 if (!(lpofn
->Flags
& OFN_SHOWHELP
)) {
257 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
259 if (lpofn
->Flags
& OFN_HIDEREADONLY
) {
260 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
265 GetObject(hFolder2
, sizeof(BITMAP
), (LPSTR
)&bm
);
266 lpmeasure
= (LPMEASUREITEMSTRUCT
)lParam
;
267 lpmeasure
->itemHeight
= bm
.bmHeight
;
268 #ifdef DEBUG_OPENDLG_DRAW
269 printf("FileOpenDlgProc WM_MEASUREITEM Height=%d !\n", bm
.bmHeight
);
274 #ifdef DEBUG_OPENDLG_DRAW
275 printf("FileOpenDlgProc // WM_DRAWITEM w=%04X l=%08X\n", wParam
, lParam
);
277 if (lParam
== 0L) break;
278 lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
279 #ifdef DEBUG_OPENDLG_DRAW
280 printf("FileOpenDlgProc // WM_DRAWITEM CtlType=%04X CtlID=%04X \n",
281 lpdis
->CtlType
, lpdis
->CtlID
);
283 if ((lpdis
->CtlType
== ODT_LISTBOX
) && (lpdis
->CtlID
== lst1
)) {
284 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
285 SelectObject(lpdis
->hDC
, hBrush
);
286 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
287 ptr
= (LPSTR
) lpdis
->itemData
;
288 if (ptr
== NULL
) break;
289 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
292 if ((lpdis
->CtlType
== ODT_LISTBOX
) && (lpdis
->CtlID
== lst2
)) {
293 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
294 SelectObject(lpdis
->hDC
, hBrush
);
295 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
296 ptr
= (LPSTR
) lpdis
->itemData
;
297 if (ptr
== NULL
) break;
298 if (strcmp(ptr
, "[.]") == 0) {
300 /* ptr = OpenDlg_ExtractCurDir(CurPath, -1); */
305 GetObject(hBitmap
, sizeof(BITMAP
), (LPSTR
)&bm
);
306 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
307 lpdis
->rcItem
.top
, ptr
, strlen(ptr
));
308 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
309 SelectObject(hMemDC
, hBitmap
);
310 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
311 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
314 if ((lpdis
->CtlType
== ODT_COMBOBOX
) && (lpdis
->CtlID
== cmb2
)) {
315 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
316 SelectObject(lpdis
->hDC
, hBrush
);
317 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
318 ptr
= (LPSTR
) lpdis
->itemData
;
319 if (ptr
== NULL
) break;
328 GetObject(hBitmap
, sizeof(BITMAP
), (LPSTR
)&bm
);
329 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
330 lpdis
->rcItem
.top
, ptr
, strlen(ptr
));
331 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
332 SelectObject(hMemDC
, hBitmap
);
333 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
334 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
337 if (lpdis
->itemState
!= 0) {
338 InvertRect(lpdis
->hDC
, &lpdis
->rcItem
);
345 if (HIWORD(lParam
) == LBN_DBLCLK
||
346 HIWORD(lParam
) == LBN_SELCHANGE
) {
348 printf("FileOpenDlgProc // LBN_SELCHANGE on lst1 !\n");
350 wRet
= SendDlgItemMessage(hWnd
, lst1
, LB_GETCURSEL
, 0, 0L);
351 SendDlgItemMessage(hWnd
, lst1
, LB_GETTEXT
, wRet
, (DWORD
)C2
);
353 if (HIWORD(lParam
) == LBN_DBLCLK
) {
355 printf("FileOpenDlgProc // LBN_DBLCLK on lst1 !\n");
357 return SendMessage(hWnd
, WM_COMMAND
, IDOK
, 0L);
361 if (HIWORD(lParam
) == LBN_DBLCLK
) {
363 printf("FileOpenDlgProc // LBN_DBLCLK on lst2 !\n");
365 wRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0L);
366 if (wRet
== (WORD
)LB_ERR
) return 0;
367 fspec
= OpenDlg_GetFileType(lpofn
->lpstrFilter
, wRet
+ 1);
369 wRet
= SendDlgItemMessage(hWnd
, lst2
, LB_GETCURSEL
, 0, 0L);
370 if (wRet
== (WORD
)LB_ERR
) return 0;
371 SendDlgItemMessage(hWnd
, lst2
, LB_GETTEXT
, wRet
, (DWORD
)C2
);
373 C2
[strlen(C2
) - 1] = '\0';
374 sprintf(str
, "%s\\%s", CurPath
, &C2
[1]);
375 if (!OpenDlg_ScanDir(hWnd
, nDrive
, str
, fspec
)) {
376 printf("OpenDlg_ScanDir // ChangeDir Error !\n");
379 strcpy(CurPath
, str
);
385 if (HIWORD(lParam
) == CBN_SELCHANGE
) {
386 wRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0L);
387 if (wRet
== (WORD
)LB_ERR
) return 0;
388 fspec
= OpenDlg_GetFileType(lpofn
->lpstrFilter
, wRet
+ 1);
389 printf("FileOpenDlgProc // new fspec #%d = '%s' !\n", wRet
, fspec
);
390 if (!OpenDlg_ScanFiles(hWnd
, nDrive
, CurPath
, fspec
)) {
391 printf("OpenDlg_ScanFiles // Change FileType Error !\n");
397 printf("FileOpenDlgProc // combo #2 changed !\n");
399 wRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0L);
400 if (wRet
== (WORD
)LB_ERR
) return 0;
401 fspec
= OpenDlg_GetFileType(lpofn
->lpstrFilter
, wRet
+ 1);
402 wRet
= SendDlgItemMessage(hWnd
, cmb2
, CB_GETCURSEL
, 0, 0L);
403 if (wRet
== (WORD
)LB_ERR
) return 0;
404 printf("FileOpenDlgProc // combo #2 CB_GETCURSEL=%d !\n", wRet
);
405 SendDlgItemMessage(hWnd
, cmb2
, CB_GETLBTEXT
, wRet
, (DWORD
)C2
);
406 nDrive
= C2
[2] - 'a';
408 printf("FileOpenDlgProc // new drive selected=%d !\n", nDrive
);
410 sprintf(str
, "%c:\\%s", nDrive
+ 'A', DOS_GetCurrentDir(nDrive
));
412 printf("FileOpenDlgProc // new drive , curPath='%s' !\n", str
);
414 if (!OpenDlg_ScanDir(hWnd
, nDrive
, str
, fspec
)) {
415 printf("OpenDlg_ScanDir // ChangeDir Error !\n");
418 strcpy(CurPath
, str
);
423 printf("FileOpenDlgProc // read-only toggled !\n");
428 printf("FileOpenDlgProc // pshHelp pressed !\n");
432 ShowWindow(hWnd
, SW_HIDE
);
433 SendDlgItemMessage(hWnd
, edt1
, WM_GETTEXT
, 0, (DWORD
)str
);
434 wRet
= SendDlgItemMessage(hWnd
, lst1
, LB_GETCURSEL
, 0, 0L);
435 SendDlgItemMessage(hWnd
, lst1
, LB_GETTEXT
, wRet
, (DWORD
)str
);
436 printf("FileOpenDlgProc // IDOK str='%s'\n", str
);
437 strcpy(lpofn
->lpstrFile
, str
);
438 lpofn
->nFileOffset
= 0;
439 lpofn
->nFileExtension
= strlen(lpofn
->lpstrFile
) - 3;
440 if (lpofn
->lpstrFileTitle
!= NULL
) {
441 wRet
= SendDlgItemMessage(hWnd
, lst1
, LB_GETCURSEL
, 0, 0L);
442 SendDlgItemMessage(hWnd
, lst1
, LB_GETTEXT
, wRet
, (DWORD
)str
);
443 strcpy(lpofn
->lpstrFileTitle
, str
);
445 EndDialog(hWnd
, TRUE
);
448 EndDialog(hWnd
, FALSE
);
457 SetBkColor((HDC)wParam, 0x00C0C0C0);
458 switch (HIWORD(lParam))
461 SetTextColor((HDC)wParam, 0x00000000);
463 case CTLCOLOR_STATIC:
464 SetTextColor((HDC)wParam, 0x00000000);
474 /***********************************************************************
475 * FileDlg_Init [internal]
477 BOOL
FileDlg_Init(HWND hWnd
, DWORD lParam
)
479 LPOPENFILENAME lpofn
;
480 lpofn
= (LPOPENFILENAME
)lParam
;
482 fprintf(stderr
, "FileDlg_Init // Bad LPOPENFILENAME pointer !");
485 if (hFolder
== (HBITMAP
)NULL
)
486 hFolder
= LoadBitmap((HINSTANCE
)NULL
, MAKEINTRESOURCE(OBM_FOLDER
));
487 if (hFolder2
== (HBITMAP
)NULL
)
488 hFolder2
= LoadBitmap((HINSTANCE
)NULL
, MAKEINTRESOURCE(OBM_FOLDER2
));
489 if (hFloppy
== (HBITMAP
)NULL
)
490 hFloppy
= LoadBitmap((HINSTANCE
)NULL
, MAKEINTRESOURCE(OBM_FLOPPY
));
491 if (hHDisk
== (HBITMAP
)NULL
)
492 hHDisk
= LoadBitmap((HINSTANCE
)NULL
, MAKEINTRESOURCE(OBM_HDISK
));
493 if (hCDRom
== (HBITMAP
)NULL
)
494 hCDRom
= LoadBitmap((HINSTANCE
)NULL
, MAKEINTRESOURCE(OBM_CDROM
));
495 if (hFolder
== 0 || hFolder2
== 0 || hFloppy
== 0 ||
496 hHDisk
== 0 || hCDRom
== 0)
497 fprintf(stderr
, "FileDlg_Init // Error loading bitmaps !");
502 /***********************************************************************
503 * OpenDlg_ScanFiles [internal]
505 BOOL
OpenDlg_ScanFiles(HWND hWnd
, WORD nDrive
, LPSTR newPath
, LPSTR fileSpec
)
510 OldDrive
= DOS_GetDefaultDrive();
511 DOS_SetDefaultDrive(nDrive
) ;
512 strcpy(OldPath
, DOS_GetCurrentDir(nDrive
));
514 printf("OpenDlg_ScanFiles // OldDrive=%d OldPath='%s'\n", OldDrive
, OldPath
);
515 printf("OpenDlg_ScanFiles // wanted newPath='%s'\n", newPath
);
517 if (newPath
[1] == ':')
518 DOS_ChangeDir(nDrive
, &newPath
[2]);
520 DOS_ChangeDir(nDrive
, newPath
);
521 sprintf(newPath
, "%c:\\%s", nDrive
+ 'A', DOS_GetCurrentDir(nDrive
));
523 printf("OpenDlg_ScanFiles // actual newPath='%s'\n", newPath
);
525 if (strlen(newPath
) == 3) newPath
[2] = '\0';
526 sprintf(str
, "%s\\%s", newPath
, fileSpec
);
527 DlgDirList(hWnd
, str
, lst1
, 0, 0x0000);
528 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (DWORD
)str
);
529 DOS_ChangeDir(nDrive
, OldPath
);
530 DOS_SetDefaultDrive(OldDrive
);
536 /***********************************************************************
537 * OpenDlg_ScanDir [internal]
539 BOOL
OpenDlg_ScanDir(HWND hWnd
, WORD nDrive
, LPSTR newPath
, LPSTR fileSpec
)
544 OldDrive
= DOS_GetDefaultDrive();
545 DOS_SetDefaultDrive(nDrive
) ;
546 strcpy(OldPath
, DOS_GetCurrentDir(nDrive
));
548 printf("OpenDlg_ScanDir // OldDrive=%d OldPath='%s'\n", OldDrive
, OldPath
);
549 printf("OpenDlg_ScanDir // wanted newPath='%s'\n", newPath
);
551 if (newPath
[1] == ':')
552 DOS_ChangeDir(nDrive
, &newPath
[2]);
554 DOS_ChangeDir(nDrive
, newPath
);
555 sprintf(newPath
, "%c:\\%s", nDrive
+ 'A', DOS_GetCurrentDir(nDrive
));
557 printf("OpenDlg_ScanDir // actual newPath='%s'\n", newPath
);
559 if (strlen(newPath
) == 3) newPath
[2] = '\0';
560 sprintf(str
, "%s\\%s", newPath
, fileSpec
);
561 DlgDirList(hWnd
, str
, lst1
, 0, 0x0000);
562 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (DWORD
)str
);
563 sprintf(str
, "%s\\*.*", newPath
);
564 DlgDirList(hWnd
, str
, lst2
, 0, 0x8010);
565 if (strlen(newPath
) == 2) strcat(newPath
, "\\");
566 SendDlgItemMessage(hWnd
, stc1
, WM_SETTEXT
, 0, (DWORD
)newPath
);
567 DOS_ChangeDir(nDrive
, OldPath
);
568 DOS_SetDefaultDrive(OldDrive
);
574 /***********************************************************************
575 * OpenDlg_GetFileType [internal]
577 LPSTR
OpenDlg_GetFileType(LPCSTR types
, WORD index
)
581 LPSTR ptr
= (LPSTR
) types
;
582 if (ptr
== NULL
) return NULL
;
583 while((n
= strlen(ptr
)) != 0) {
585 printf("OpenDlg_GetFileType // file type '%s' !\n", ptr
);
589 printf("OpenDlg_GetFileType // file spec '%s' !\n", ptr
);
591 if (i
++ == index
) return ptr
;
599 /***********************************************************************
600 * OpenDlg_ExtractCurDir [internal]
602 LPSTR
OpenDlg_ExtractCurDir(LPSTR FullPath
, short MaxLen
)
605 if (MaxLen
< 0) MaxLen
= strlen(FullPath
);
606 ptr
= FullPath
+ MaxLen
- 1;
607 if (*ptr
== '\\') return NULL
;
608 while (ptr
> FullPath
) {
609 if (*ptr
== '\\') return (ptr
+ 1);
616 /***********************************************************************
617 * FileSaveDlgProc [COMMDLG.7]
619 BOOL
FileSaveDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
)
631 LPMEASUREITEMSTRUCT lpmeasure
;
632 LPDRAWITEMSTRUCT lpdis
;
635 static char OldPath
[512];
636 static char CurPath
[512];
637 static LPOPENFILENAME lpofn
;
642 printf("FileSaveDlgProc // WM_INITDIALOG lParam=%08X\n", lParam
);
644 if (!FileDlg_Init(hWnd
, lParam
)) return TRUE
;
645 SendDlgItemMessage(hWnd
, cmb1
, CB_RESETCONTENT
, 0, 0L);
646 lpofn
= (LPOPENFILENAME
)lParam
;
647 ptr
= (LPSTR
)lpofn
->lpstrFilter
;
648 strcpy(CurPath
, lpofn
->lpstrInitialDir
);
649 while((n
= strlen(ptr
)) != 0) {
651 printf("FileSaveDlgProc // file type '%s' !\n", ptr
);
653 SendDlgItemMessage(hWnd
, cmb1
, CB_ADDSTRING
, 0, (DWORD
)ptr
);
656 printf("FileSaveDlgProc // file spec '%s' !\n", ptr
);
661 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (DWORD
)str
);
662 SendDlgItemMessage(hWnd
, cmb1
, CB_SETCURSEL
,
663 lpofn
->nFilterIndex
- 1, 0L);
664 DlgDirListComboBox(hWnd
, "", cmb2
, 0, 0xC000);
665 nDrive
= 2; /* Drive 'C:' */
666 SendDlgItemMessage(hWnd
, cmb2
, CB_SETCURSEL
, nDrive
, 0L);
667 sprintf(str
, "%c:\\%s", nDrive
+ 'A', DOS_GetCurrentDir(nDrive
));
668 fspec
= OpenDlg_GetFileType(lpofn
->lpstrFilter
,
669 lpofn
->nFilterIndex
);
671 printf("FileSaveDlgProc // WM_INITDIALOG fspec #%d = '%s' !\n",
672 lpofn
->nFilterIndex
, fspec
);
674 if (!OpenDlg_ScanDir(hWnd
, nDrive
, str
, fspec
)) {
675 printf("OpenDlg_ScanDir // ChangeDir Error !\n");
678 strcpy(CurPath
, str
);
680 ShowWindow(hWnd
, SW_SHOWNORMAL
);
684 if (wParam
== 0) break;
685 if (!(lpofn
->Flags
& OFN_SHOWHELP
)) {
686 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
688 if (lpofn
->Flags
& OFN_HIDEREADONLY
) {
689 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
694 GetObject(hFolder2
, sizeof(BITMAP
), (LPSTR
)&bm
);
695 lpmeasure
= (LPMEASUREITEMSTRUCT
)lParam
;
696 lpmeasure
->itemHeight
= bm
.bmHeight
;
697 #ifdef DEBUG_OPENDLG_DRAW
698 printf("FileSaveDlgProc WM_MEASUREITEM Height=%d !\n", bm
.bmHeight
);
703 #ifdef DEBUG_OPENDLG_DRAW
704 printf("FileSaveDlgProc // WM_DRAWITEM w=%04X l=%08X\n", wParam
, lParam
);
706 if (lParam
== 0L) break;
707 lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
708 #ifdef DEBUG_OPENDLG_DRAW
709 printf("FileSaveDlgProc // WM_DRAWITEM lpdis->CtlID=%04X\n", lpdis
->CtlID
);
711 if ((lpdis
->CtlType
== ODT_LISTBOX
) && (lpdis
->CtlID
== lst1
)) {
712 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
713 SelectObject(lpdis
->hDC
, hBrush
);
714 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
715 ptr
= (LPSTR
) lpdis
->itemData
;
716 if (ptr
== NULL
) break;
717 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
720 if ((lpdis
->CtlType
== ODT_LISTBOX
) && (lpdis
->CtlID
== lst2
)) {
721 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
722 SelectObject(lpdis
->hDC
, hBrush
);
723 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
724 ptr
= (LPSTR
) lpdis
->itemData
;
725 if (ptr
== NULL
) break;
726 if (strcmp(ptr
, "[.]") == 0) {
732 GetObject(hBitmap
, sizeof(BITMAP
), (LPSTR
)&bm
);
733 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
734 lpdis
->rcItem
.top
, ptr
, strlen(ptr
));
735 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
736 SelectObject(hMemDC
, hBitmap
);
737 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
738 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
741 if ((lpdis
->CtlType
== ODT_COMBOBOX
) && (lpdis
->CtlID
== cmb2
)) {
742 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
743 SelectObject(lpdis
->hDC
, hBrush
);
744 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
745 ptr
= (LPSTR
) lpdis
->itemData
;
746 if (ptr
== NULL
) break;
755 GetObject(hBitmap
, sizeof(BITMAP
), (LPSTR
)&bm
);
756 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
757 lpdis
->rcItem
.top
, ptr
, strlen(ptr
));
758 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
759 SelectObject(hMemDC
, hBitmap
);
760 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
761 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
769 if (HIWORD(lParam
) == LBN_DBLCLK
||
770 HIWORD(lParam
) == LBN_SELCHANGE
) {
772 printf("FileSaveDlgProc // LBN_SELCHANGE on lst1 !\n");
774 wRet
= SendDlgItemMessage(hWnd
, lst1
, LB_GETCURSEL
, 0, 0L);
775 SendDlgItemMessage(hWnd
, lst1
, LB_GETTEXT
, wRet
, (DWORD
)C2
);
777 if (HIWORD(lParam
) == LBN_DBLCLK
) {
779 printf("FileSaveDlgProc // LBN_DBLCLK on lst1 !\n");
781 return SendMessage(hWnd
, WM_COMMAND
, IDOK
, 0L);
785 if (HIWORD(lParam
) == LBN_DBLCLK
) {
787 printf("FileSaveDlgProc // LBN_DBLCLK on lst2 !\n");
789 wRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0L);
790 fspec
= OpenDlg_GetFileType(lpofn
->lpstrFilter
, wRet
+ 1);
792 wRet
= SendDlgItemMessage(hWnd
, lst2
, LB_GETCURSEL
, 0, 0L);
793 SendDlgItemMessage(hWnd
, lst2
, LB_GETTEXT
, wRet
, (DWORD
)C2
);
795 C2
[strlen(C2
) - 1] = '\0';
796 sprintf(str
, "%s\\%s", CurPath
, &C2
[1]);
797 if (!OpenDlg_ScanDir(hWnd
, nDrive
, str
, fspec
)) {
798 printf("FileSaveDlgProc // ChangeDir Error !\n");
801 strcpy(CurPath
, str
);
807 if (HIWORD(lParam
) == CBN_SELCHANGE
) {
808 wRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0L);
809 fspec
= OpenDlg_GetFileType(lpofn
->lpstrFilter
, wRet
+ 1);
810 printf("FileSaveDlgProc // new fspec #%d = '%s' !\n", wRet
, fspec
);
811 if (!OpenDlg_ScanFiles(hWnd
, nDrive
, CurPath
, fspec
)) {
812 printf("OpenDlg_ScanFile // Change FileType Error !\n");
818 printf("FileSaveDlgProc // combo #2 changed !\n");
820 wRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0L);
821 if (wRet
== (WORD
)LB_ERR
) return 0;
822 fspec
= OpenDlg_GetFileType(lpofn
->lpstrFilter
, wRet
+ 1);
823 wRet
= SendDlgItemMessage(hWnd
, cmb2
, CB_GETCURSEL
, 0, 0L);
824 if (wRet
== (WORD
)LB_ERR
) return 0;
825 printf("FileSaveDlgProc // combo #2 CB_GETCURSEL=%d !\n", wRet
);
826 SendDlgItemMessage(hWnd
, cmb2
, CB_GETLBTEXT
, wRet
, (DWORD
)C2
);
827 nDrive
= C2
[2] - 'a';
829 printf("FileSaveDlgProc // new drive selected=%d !\n", nDrive
);
831 sprintf(str
, "%c:\\%s", nDrive
+ 'A', DOS_GetCurrentDir(nDrive
));
833 printf("FileSaveDlgProc // new drive , curPath='%s' !\n", str
);
835 if (!OpenDlg_ScanDir(hWnd
, nDrive
, str
, fspec
)) {
836 printf("FileSaveDlgProc // Change Drive Error !\n");
839 strcpy(CurPath
, str
);
844 printf("FileSaveDlgProc // read-only toggled !\n");
849 printf("FileSaveDlgProc // pshHelp pressed !\n");
853 strcpy(lpofn
->lpstrFile
, "titi.txt");
854 if (lpofn
->lpstrFileTitle
!= NULL
) {
855 strcpy(lpofn
->lpstrFileTitle
, "titi.txt");
857 EndDialog(hWnd
, TRUE
);
860 EndDialog(hWnd
, FALSE
);
869 /***********************************************************************
870 * ColorDlgProc [COMMDLG.8]
872 BOOL
ColorDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
)
876 printf("ColorDlgProc // WM_INITDIALOG lParam=%08X\n", lParam
);
877 ShowWindow(hWnd
, SW_SHOWNORMAL
);
883 EndDialog(hWnd
, TRUE
);
886 EndDialog(hWnd
, FALSE
);
895 /***********************************************************************
896 * FindTextDlg [COMMDLG.11]
898 BOOL
FindText(LPFINDREPLACE lpFind
)
904 hResInfo
= FindResource(hSysRes
, MAKEINTRESOURCE(FINDDLG
), RT_DIALOG
);
906 CommDlgLastError
= CDERR_FINDRESFAILURE
;
909 hDlgTmpl
= LoadResource(hSysRes
, hResInfo
);
911 CommDlgLastError
= CDERR_LOADRESFAILURE
;
914 wndPtr
= WIN_FindWndPtr(lpFind
->hwndOwner
);
915 bRet
= DialogBoxIndirectParam(wndPtr
->hInstance
, hDlgTmpl
,
916 lpFind
->hwndOwner
, (WNDPROC
)FindTextDlgProc
, (DWORD
)lpFind
);
921 /***********************************************************************
922 * ReplaceTextDlg [COMMDLG.12]
924 BOOL
ReplaceText(LPFINDREPLACE lpFind
)
930 hResInfo
= FindResource(hSysRes
, MAKEINTRESOURCE(REPLACEDLG
), RT_DIALOG
);
932 CommDlgLastError
= CDERR_FINDRESFAILURE
;
935 hDlgTmpl
= LoadResource(hSysRes
, hResInfo
);
937 CommDlgLastError
= CDERR_LOADRESFAILURE
;
940 wndPtr
= WIN_FindWndPtr(lpFind
->hwndOwner
);
941 bRet
= DialogBoxIndirectParam(wndPtr
->hInstance
, hDlgTmpl
,
942 lpFind
->hwndOwner
, (WNDPROC
)ReplaceTextDlgProc
, (DWORD
)lpFind
);
947 /***********************************************************************
948 * FindTextDlgProc [COMMDLG.13]
950 BOOL
FindTextDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
)
954 printf("FindTextDlgProc // WM_INITDIALOG lParam=%08X\n", lParam
);
955 ShowWindow(hWnd
, SW_SHOWNORMAL
);
961 EndDialog(hWnd
, TRUE
);
964 EndDialog(hWnd
, FALSE
);
973 /***********************************************************************
974 * ReplaceTextDlgProc [COMMDLG.14]
976 BOOL
ReplaceTextDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
)
980 printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08X\n", lParam
);
981 ShowWindow(hWnd
, SW_SHOWNORMAL
);
987 EndDialog(hWnd
, TRUE
);
990 EndDialog(hWnd
, FALSE
);
999 /***********************************************************************
1000 * PrintDlg [COMMDLG.20]
1002 BOOL
PrintDlg(LPPRINTDLG lpPrint
)
1008 printf("PrintDlg(%08X) // Flags=%08X\n", lpPrint
->Flags
);
1009 if (lpPrint
->Flags
& PD_PRINTSETUP
)
1010 hResInfo
= FindResource(hSysRes
, MAKEINTRESOURCE(PRINTSETUPDLG
), RT_DIALOG
);
1012 hResInfo
= FindResource(hSysRes
, MAKEINTRESOURCE(PRINTDLG
), RT_DIALOG
);
1013 if (hResInfo
== 0) {
1014 CommDlgLastError
= CDERR_FINDRESFAILURE
;
1017 hDlgTmpl
= LoadResource(hSysRes
, hResInfo
);
1018 if (hDlgTmpl
== 0) {
1019 CommDlgLastError
= CDERR_LOADRESFAILURE
;
1022 wndPtr
= WIN_FindWndPtr(lpPrint
->hwndOwner
);
1023 if (lpPrint
->Flags
& PD_PRINTSETUP
)
1024 bRet
= DialogBoxIndirectParam(wndPtr
->hInstance
, hDlgTmpl
,
1025 lpPrint
->hwndOwner
, (WNDPROC
)PrintSetupDlgProc
, (DWORD
)lpPrint
);
1027 bRet
= DialogBoxIndirectParam(wndPtr
->hInstance
, hDlgTmpl
,
1028 lpPrint
->hwndOwner
, (WNDPROC
)PrintDlgProc
, (DWORD
)lpPrint
);
1033 /***********************************************************************
1034 * PrintDlgProc [COMMDLG.21]
1036 BOOL
PrintDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
)
1040 printf("PrintDlgProc // WM_INITDIALOG lParam=%08X\n", lParam
);
1041 ShowWindow(hWnd
, SW_SHOWNORMAL
);
1047 EndDialog(hWnd
, TRUE
);
1050 EndDialog(hWnd
, FALSE
);
1059 /***********************************************************************
1060 * PrintSetupDlgProc [COMMDLG.22]
1062 BOOL
PrintSetupDlgProc(HWND hWnd
, WORD wMsg
, WORD wParam
, LONG lParam
)
1066 printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08X\n", lParam
);
1067 ShowWindow(hWnd
, SW_SHOWNORMAL
);
1073 EndDialog(hWnd
, TRUE
);
1076 EndDialog(hWnd
, FALSE
);
1085 /***********************************************************************
1086 * CommDlgExtendError [COMMDLG.26]
1088 DWORD
CommDlgExtendError(void)
1090 return CommDlgLastError
;
1094 /***********************************************************************
1095 * GetFileTitle [COMMDLG.27]
1097 int GetFileTitle(LPCSTR lpFile
, LPSTR lpTitle
, UINT cbBuf
)
1100 printf("GetFileTitle(%08X %08X %d); \n", lpFile
, lpTitle
, cbBuf
);
1101 if (lpFile
== NULL
|| lpTitle
== NULL
) return -1;
1102 len
= strlen(lpFile
);
1103 if (len
== 0) return -1;
1104 if (strchr(lpFile
, '*') != NULL
) return -1;
1105 if (strchr(lpFile
, '[') != NULL
) return -1;
1106 if (strchr(lpFile
, ']') != NULL
) return -1;
1108 if (lpFile
[len
] == '/' || lpFile
[len
] == '\\' || lpFile
[len
] == ':') return -1;
1109 for (i
= len
; i
>= 0; i
--) {
1110 if (lpFile
[i
] == '/' ||
1111 lpFile
[i
] == '\\' ||
1117 printf("\n---> '%s' ", &lpFile
[i
]);
1118 len
= min(cbBuf
, strlen(&lpFile
[i
]) + 1);
1119 strncpy(lpTitle
, &lpFile
[i
], len
+ 1);