4 * Copyright 1994 Martin Ayotte
15 #include "selectors.h"
19 #include "stackframe.h"
23 static DWORD CommDlgLastError
= 0;
25 static HBITMAP hFolder
= 0;
26 static HBITMAP hFolder2
= 0;
27 static HBITMAP hFloppy
= 0;
28 static HBITMAP hHDisk
= 0;
29 static HBITMAP hCDRom
= 0;
31 /***********************************************************************
32 * FileDlg_Init [internal]
34 static BOOL
FileDlg_Init()
36 static BOOL initialized
= 0;
39 if (!hFolder
) hFolder
= LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER
));
40 if (!hFolder2
) hFolder2
= LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER2
));
41 if (!hFloppy
) hFloppy
= LoadBitmap(0, MAKEINTRESOURCE(OBM_FLOPPY
));
42 if (!hHDisk
) hHDisk
= LoadBitmap(0, MAKEINTRESOURCE(OBM_HDISK
));
43 if (!hCDRom
) hCDRom
= LoadBitmap(0, MAKEINTRESOURCE(OBM_CDROM
));
44 if (hFolder
== 0 || hFolder2
== 0 || hFloppy
== 0 ||
45 hHDisk
== 0 || hCDRom
== 0)
47 fprintf(stderr
, "FileDlg_Init // Error loading bitmaps !");
55 /***********************************************************************
56 * GetOpenFileName (COMMDLG.1)
58 BOOL
GetOpenFileName(LPOPENFILENAME lpofn
)
61 HANDLE hDlgTmpl
, hResInfo
;
64 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
66 if (lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
) hDlgTmpl
= lpofn
->hInstance
;
67 else if (lpofn
->Flags
& OFN_ENABLETEMPLATE
)
69 if (!(hResInfo
= FindResource( lpofn
->hInstance
,
70 lpofn
->lpTemplateName
, RT_DIALOG
)))
72 CommDlgLastError
= CDERR_FINDRESFAILURE
;
75 hDlgTmpl
= LoadResource( lpofn
->hInstance
, hResInfo
);
77 else hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_OPEN_FILE
);
80 CommDlgLastError
= CDERR_LOADRESFAILURE
;
84 hInst
= WIN_GetWindowInstance( lpofn
->hwndOwner
);
85 bRet
= DialogBoxIndirectParam( hInst
, hDlgTmpl
, lpofn
->hwndOwner
,
86 GetWndProcEntry16("FileOpenDlgProc"),
89 if (!(lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
))
91 if (lpofn
->Flags
& OFN_ENABLETEMPLATE
) FreeResource( hDlgTmpl
);
92 else SYSRES_FreeResource( hDlgTmpl
);
95 dprintf_commdlg(stddeb
,"GetOpenFileName // return lpstrFile='%s' !\n",
96 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
101 /***********************************************************************
102 * GetSaveFileName (COMMDLG.2)
104 BOOL
GetSaveFileName(LPOPENFILENAME lpofn
)
107 HANDLE hDlgTmpl
, hResInfo
;
110 if (!lpofn
|| !FileDlg_Init()) return FALSE
;
112 if (lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
) hDlgTmpl
= lpofn
->hInstance
;
113 else if (lpofn
->Flags
& OFN_ENABLETEMPLATE
)
115 hInst
= lpofn
->hInstance
;
116 if (!(hResInfo
= FindResource( lpofn
->hInstance
,
117 lpofn
->lpTemplateName
, RT_DIALOG
)))
119 CommDlgLastError
= CDERR_FINDRESFAILURE
;
122 hDlgTmpl
= LoadResource( lpofn
->hInstance
, hResInfo
);
124 else hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_SAVE_FILE
);
126 hInst
= WIN_GetWindowInstance( lpofn
->hwndOwner
);
127 bRet
= DialogBoxIndirectParam( hInst
, hDlgTmpl
, lpofn
->hwndOwner
,
128 GetWndProcEntry16("FileSaveDlgProc"),
130 if (!(lpofn
->Flags
& OFN_ENABLETEMPLATEHANDLE
))
132 if (lpofn
->Flags
& OFN_ENABLETEMPLATE
) FreeResource( hDlgTmpl
);
133 else SYSRES_FreeResource( hDlgTmpl
);
136 dprintf_commdlg(stddeb
, "GetSaveFileName // return lpstrFile='%s' !\n",
137 (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFile
));
141 /***********************************************************************
142 * FILEDLG_StripEditControl [internal]
143 * Strip pathnames off the contents of the edit control.
145 static void FILEDLG_StripEditControl(HWND hwnd
)
149 SendDlgItemMessage(hwnd
, edt1
, WM_GETTEXT
, 511, (LPARAM
)MAKE_SEGPTR(temp
));
150 cp
= strrchr(temp
, '\\');
154 cp
= strrchr(temp
, ':');
160 /***********************************************************************
161 * FILEDLG_ScanDir [internal]
163 static BOOL
FILEDLG_ScanDir(HWND hWnd
, LPSTR newPath
)
165 char str
[512],str2
[512];
167 strncpy(str
,newPath
,511); str
[511]=0;
168 SendDlgItemMessage(hWnd
, edt1
, WM_GETTEXT
, 511, (LPARAM
)MAKE_SEGPTR(str2
));
169 strncat(str
,str2
,511-strlen(str
)); str
[511]=0;
170 if (!DlgDirList(hWnd
, MAKE_SEGPTR(str
), lst1
, 0, 0x0000)) return FALSE
;
171 strcpy( str
, "*.*" );
172 DlgDirList(hWnd
, MAKE_SEGPTR(str
), lst2
, stc1
, 0x8010);
176 /***********************************************************************
177 * FILEDLG_GetFileType [internal]
180 static LPSTR
FILEDLG_GetFileType(LPSTR cfptr
, LPSTR fptr
, WORD index
)
185 for ( ;(n
= strlen(cfptr
)) != 0; i
++)
190 cfptr
+= strlen(cfptr
) + 1;
193 for ( ;(n
= strlen(fptr
)) != 0; i
++)
198 fptr
+= strlen(fptr
) + 1;
203 /***********************************************************************
204 * FILEDLG_WMDrawItem [internal]
206 static LONG
FILEDLG_WMDrawItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
208 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
)PTR_SEG_TO_LIN(lParam
);
211 HBITMAP hBitmap
, hPrevBitmap
;
216 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst1
) {
217 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
218 SelectObject(lpdis
->hDC
, hBrush
);
219 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
220 SendMessage(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
221 (LPARAM
)MAKE_SEGPTR(str
));
222 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
224 if (lpdis
->itemState
!= 0) {
225 InvertRect(lpdis
->hDC
, &lpdis
->rcItem
);
230 if (lpdis
->CtlType
== ODT_LISTBOX
&& lpdis
->CtlID
== lst2
) {
231 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
232 SelectObject(lpdis
->hDC
, hBrush
);
233 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
234 SendMessage(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
,
235 (LPARAM
)MAKE_SEGPTR(str
));
238 GetObject(hBitmap
, sizeof(BITMAP
), (LPSTR
)&bm
);
239 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
240 lpdis
->rcItem
.top
, str
, strlen(str
));
241 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
242 hPrevBitmap
= SelectObject(hMemDC
, hBitmap
);
243 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
244 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
245 SelectObject(hMemDC
, hPrevBitmap
);
247 if (lpdis
->itemState
!= 0) {
248 InvertRect(lpdis
->hDC
, &lpdis
->rcItem
);
252 if (lpdis
->CtlType
== ODT_COMBOBOX
&& lpdis
->CtlID
== cmb2
) {
253 hBrush
= SelectObject(lpdis
->hDC
, GetStockObject(LTGRAY_BRUSH
));
254 SelectObject(lpdis
->hDC
, hBrush
);
255 FillRect(lpdis
->hDC
, &lpdis
->rcItem
, hBrush
);
256 SendMessage(lpdis
->hwndItem
, CB_GETLBTEXT
, lpdis
->itemID
,
257 (LPARAM
)MAKE_SEGPTR(str
));
258 switch(DRIVE_GetType( str
[2] - 'a' ))
260 case TYPE_FLOPPY
: hBitmap
= hFloppy
; break;
261 case TYPE_CDROM
: hBitmap
= hCDRom
; break;
264 default: hBitmap
= hHDisk
; break;
266 GetObject(hBitmap
, sizeof(BITMAP
), (LPSTR
)&bm
);
267 TextOut(lpdis
->hDC
, lpdis
->rcItem
.left
+ bm
.bmWidth
,
268 lpdis
->rcItem
.top
, str
, strlen(str
));
269 hMemDC
= CreateCompatibleDC(lpdis
->hDC
);
270 hPrevBitmap
= SelectObject(hMemDC
, hBitmap
);
271 BitBlt(lpdis
->hDC
, lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
272 bm
.bmWidth
, bm
.bmHeight
, hMemDC
, 0, 0, SRCCOPY
);
273 SelectObject(hMemDC
, hPrevBitmap
);
275 if (lpdis
->itemState
!= 0) {
276 InvertRect(lpdis
->hDC
, &lpdis
->rcItem
);
283 /***********************************************************************
284 * FILEDLG_WMMeasureItem [internal]
286 static LONG
FILEDLG_WMMeasureItem(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
289 LPMEASUREITEMSTRUCT lpmeasure
;
291 GetObject(hFolder2
, sizeof(BITMAP
), (LPSTR
)&bm
);
292 lpmeasure
= (LPMEASUREITEMSTRUCT
)PTR_SEG_TO_LIN(lParam
);
293 lpmeasure
->itemHeight
= bm
.bmHeight
;
297 /***********************************************************************
298 * FILEDLG_WMInitDialog [internal]
301 static LONG
FILEDLG_WMInitDialog(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
305 LPOPENFILENAME lpofn
;
308 SetWindowLong(hWnd
, DWL_USER
, lParam
);
309 lpofn
= (LPOPENFILENAME
)lParam
;
310 /* read custom filter information */
311 if (lpofn
->lpstrCustomFilter
)
313 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
);
314 dprintf_commdlg(stddeb
,"lpstrCustomFilter = %p\n", pstr
);
318 strncpy(tmpstr
, pstr
, 511); tmpstr
[511]=0;
319 dprintf_commdlg(stddeb
,"lpstrCustomFilter // add tmpstr='%s' ", tmpstr
);
320 i
= SendDlgItemMessage(hWnd
, cmb1
, CB_ADDSTRING
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr
));
323 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
324 SendDlgItemMessage(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
328 /* read filter information */
329 pstr
= (LPSTR
)PTR_SEG_TO_LIN(lpofn
->lpstrFilter
);
333 strncpy(tmpstr
, pstr
, 511); tmpstr
[511]=0;
334 dprintf_commdlg(stddeb
,"lpstrFilter // add tmpstr='%s' ", tmpstr
);
335 i
= SendDlgItemMessage(hWnd
, cmb1
, CB_ADDSTRING
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr
));
338 dprintf_commdlg(stddeb
,"associated to '%s'\n", pstr
);
339 SendDlgItemMessage(hWnd
, cmb1
, CB_SETITEMDATA
, i
, (LPARAM
)pstr
);
342 /* set default filter */
343 if (lpofn
->nFilterIndex
== 0 && lpofn
->lpstrCustomFilter
== (SEGPTR
)NULL
)
344 lpofn
->nFilterIndex
= 1;
345 SendDlgItemMessage(hWnd
, cmb1
, CB_SETCURSEL
, lpofn
->nFilterIndex
- 1, 0);
346 strncpy(tmpstr
, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
347 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
), lpofn
->nFilterIndex
- 1),511);
349 dprintf_commdlg(stddeb
,"nFilterIndex = %ld // SetText of edt1 to '%s'\n",
350 lpofn
->nFilterIndex
, tmpstr
);
351 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr
));
354 DlgDirListComboBox(hWnd
, MAKE_SEGPTR(tmpstr
), cmb2
, 0, 0xC000);
355 /* read initial directory */
356 if (PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
) != NULL
)
358 strncpy(tmpstr
, PTR_SEG_TO_LIN(lpofn
->lpstrInitialDir
), 510);
360 if (strlen(tmpstr
) > 0 && tmpstr
[strlen(tmpstr
)-1] != '\\'
361 && tmpstr
[strlen(tmpstr
)-1] != ':')
366 if (!FILEDLG_ScanDir(hWnd
, tmpstr
))
367 fprintf(stderr
, "FileDlg: couldn't read initial directory %s!\n", tmpstr
);
368 /* select current drive in combo 2 */
369 n
= DRIVE_GetCurrentDrive();
370 SendDlgItemMessage(hWnd
, cmb2
, CB_SETCURSEL
, n
, 0);
371 if (!(lpofn
->Flags
& OFN_SHOWHELP
))
372 ShowWindow(GetDlgItem(hWnd
, pshHelp
), SW_HIDE
);
373 if (lpofn
->Flags
& OFN_HIDEREADONLY
)
374 ShowWindow(GetDlgItem(hWnd
, chx1
), SW_HIDE
);
378 /***********************************************************************
379 * FILEDLG_WMCommand [internal]
381 static LRESULT
FILEDLG_WMCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
384 LPOPENFILENAME lpofn
;
385 char tmpstr
[512], tmpstr2
[512];
387 UINT control
,notification
;
389 /* Notifications are packaged differently in Win32 */
391 control
= LOWORD(wParam
);
392 notification
= HIWORD(wParam
);
395 notification
= HIWORD(lParam
);
398 lpofn
= (LPOPENFILENAME
)GetWindowLong(hWnd
, DWL_USER
);
401 case lst1
: /* file list */
402 FILEDLG_StripEditControl(hWnd
);
403 if (notification
== LBN_DBLCLK
)
405 lRet
= SendDlgItemMessage(hWnd
, lst1
, LB_GETCURSEL
, 0, 0);
406 if (lRet
== LB_ERR
) return TRUE
;
407 SendDlgItemMessage(hWnd
, lst1
, LB_GETTEXT
, lRet
,
408 (LPARAM
)MAKE_SEGPTR(tmpstr
));
409 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr
));
411 case lst2
: /* directory list */
412 FILEDLG_StripEditControl(hWnd
);
413 if (notification
== LBN_DBLCLK
)
415 lRet
= SendDlgItemMessage(hWnd
, lst2
, LB_GETCURSEL
, 0, 0);
416 if (lRet
== LB_ERR
) return TRUE
;
417 SendDlgItemMessage(hWnd
, lst2
, LB_GETTEXT
, lRet
,
418 (LPARAM
)MAKE_SEGPTR(tmpstr
));
419 if (tmpstr
[0] == '[')
421 tmpstr
[strlen(tmpstr
) - 1] = 0;
422 strcpy(tmpstr
,tmpstr
+1);
424 strcat(tmpstr
, "\\");
428 case cmb1
: /* file type drop list */
429 if (notification
== CBN_SELCHANGE
)
435 case cmb2
: /* disk drop list */
436 FILEDLG_StripEditControl(hWnd
);
437 lRet
= SendDlgItemMessage(hWnd
, cmb2
, CB_GETCURSEL
, 0, 0L);
438 if (lRet
== LB_ERR
) return 0;
439 SendDlgItemMessage(hWnd
, cmb2
, CB_GETLBTEXT
, lRet
, (LPARAM
)MAKE_SEGPTR(tmpstr
));
440 sprintf(tmpstr
, "%c:", tmpstr
[2]);
442 lRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
445 pstr
= (LPSTR
)SendDlgItemMessage(hWnd
, cmb1
, CB_GETITEMDATA
, lRet
, 0);
446 dprintf_commdlg(stddeb
,"Selected filter : %s\n", pstr
);
447 strncpy(tmpstr2
, pstr
, 511); tmpstr2
[511]=0;
448 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr2
));
449 FILEDLG_ScanDir(hWnd
, tmpstr
);
457 SendDlgItemMessage(hWnd
, edt1
, WM_GETTEXT
, 511, (LPARAM
)MAKE_SEGPTR(tmpstr
));
458 pstr
= strrchr(tmpstr
, '\\');
460 pstr
= strrchr(tmpstr
, ':');
461 if (strchr(tmpstr
,'*') != NULL
|| strchr(tmpstr
,'?') != NULL
)
463 /* edit control contains wildcards */
466 strncpy(tmpstr2
, pstr
+1, 511); tmpstr2
[511]=0;
471 strcpy(tmpstr2
, tmpstr
);
474 dprintf_commdlg(stddeb
,"commdlg: %s, %s\n", tmpstr
, tmpstr2
);
475 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr2
));
476 FILEDLG_ScanDir(hWnd
, tmpstr
);
479 /* no wildcards, we might have a directory or a filename */
480 /* try appending a wildcard and reading the directory */
481 pstr2
= tmpstr
+ strlen(tmpstr
);
482 if (pstr
== NULL
|| *(pstr
+1) != 0)
483 strcat(tmpstr
, "\\");
484 lRet
= SendDlgItemMessage(hWnd
, cmb1
, CB_GETCURSEL
, 0, 0);
485 if (lRet
== LB_ERR
) return TRUE
;
486 lpofn
->nFilterIndex
= lRet
+ 1;
487 dprintf_commdlg(stddeb
,"commdlg: lpofn->nFilterIndex=%ld\n", lpofn
->nFilterIndex
);
489 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn
->lpstrCustomFilter
),
490 PTR_SEG_TO_LIN(lpofn
->lpstrFilter
),
493 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr2
));
494 /* if ScanDir succeeds, we have changed the directory */
495 if (FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
496 /* if not, this must be a filename */
500 /* strip off the pathname */
502 strncpy(tmpstr2
, pstr
+1, 511); tmpstr2
[511]=0;
503 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr2
));
504 /* Should we MessageBox() if this fails? */
505 if (!FILEDLG_ScanDir(hWnd
, tmpstr
)) return TRUE
;
506 strcpy(tmpstr
, tmpstr2
);
509 SendDlgItemMessage(hWnd
, edt1
, WM_SETTEXT
, 0, (LPARAM
)MAKE_SEGPTR(tmpstr
));
510 ShowWindow(hWnd
, SW_HIDE
);
512 int drive
= DRIVE_GetCurrentDrive();
513 tmpstr2
[0] = 'A'+ drive
;
516 strncpy(tmpstr2
+ 3, DRIVE_GetDosCwd(drive
), 507); tmpstr2
[510]=0;
517 if (strlen(tmpstr2
) > 3)
518 strcat(tmpstr2
, "\\");
519 strncat(tmpstr2
, tmpstr
, 511-strlen(tmpstr2
)); tmpstr2
[511]=0;
520 strcpy(PTR_SEG_TO_LIN(lpofn
->lpstrFile
), tmpstr2
);
522 lpofn
->nFileOffset
= 0;
523 lpofn
->nFileExtension
= 0;
524 while(tmpstr2
[lpofn
->nFileExtension
] != '.' && tmpstr2
[lpofn
->nFileExtension
] != '\0')
525 lpofn
->nFileExtension
++;
526 if (lpofn
->nFileExtension
== '\0')
527 lpofn
->nFileExtension
= 0;
529 lpofn
->nFileExtension
++;
530 if (PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
) != NULL
)
532 lRet
= SendDlgItemMessage(hWnd
, lst1
, LB_GETCURSEL
, 0, 0);
533 SendDlgItemMessage(hWnd
, lst1
, LB_GETTEXT
, lRet
,
534 (LPARAM
)MAKE_SEGPTR(tmpstr
));
535 dprintf_commdlg(stddeb
,"strcpy'ing '%s'\n",tmpstr
); fflush(stdout
);
536 strcpy(PTR_SEG_TO_LIN(lpofn
->lpstrFileTitle
), tmpstr
);
538 EndDialog(hWnd
, TRUE
);
541 EndDialog(hWnd
, FALSE
);
548 /***********************************************************************
549 * FileOpenDlgProc (COMMDLG.6)
551 LRESULT
FileOpenDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
556 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
558 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
560 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
);
562 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
565 SetBkColor((HDC
)wParam
, 0x00C0C0C0);
566 switch (HIWORD(lParam
))
569 SetTextColor((HDC
)wParam
, 0x00000000);
571 case CTLCOLOR_STATIC
:
572 SetTextColor((HDC
)wParam
, 0x00000000);
582 /***********************************************************************
583 * FileSaveDlgProc (COMMDLG.7)
585 LRESULT
FileSaveDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
589 return FILEDLG_WMInitDialog(hWnd
, wParam
, lParam
);
592 return FILEDLG_WMMeasureItem(hWnd
, wParam
, lParam
);
595 return FILEDLG_WMDrawItem(hWnd
, wParam
, lParam
);
598 return FILEDLG_WMCommand(hWnd
, wParam
, lParam
);
603 SetBkColor((HDC)wParam, 0x00C0C0C0);
604 switch (HIWORD(lParam))
607 SetTextColor((HDC)wParam, 0x00000000);
609 case CTLCOLOR_STATIC:
610 SetTextColor((HDC)wParam, 0x00000000);
620 /***********************************************************************
621 * ChooseColor (COMMDLG.5)
623 BOOL
ChooseColor(LPCHOOSECOLOR lpChCol
)
625 HANDLE hInst
, hDlgTmpl
;
628 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_COLOR
);
629 hInst
= WIN_GetWindowInstance( lpChCol
->hwndOwner
);
630 bRet
= DialogBoxIndirectParam( hInst
, hDlgTmpl
, lpChCol
->hwndOwner
,
631 GetWndProcEntry16("ColorDlgProc"),
633 SYSRES_FreeResource( hDlgTmpl
);
638 /***********************************************************************
639 * ColorDlgProc (COMMDLG.8)
641 LRESULT
ColorDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
646 dprintf_commdlg(stddeb
,"ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
647 ShowWindow(hWnd
, SW_SHOWNORMAL
);
653 EndDialog(hWnd
, TRUE
);
656 EndDialog(hWnd
, FALSE
);
665 /***********************************************************************
666 * FindTextDlg (COMMDLG.11)
668 BOOL
FindText(LPFINDREPLACE lpFind
)
670 HANDLE hInst
, hDlgTmpl
;
673 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_FIND_TEXT
);
674 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
675 bRet
= DialogBoxIndirectParam( hInst
, hDlgTmpl
, lpFind
->hwndOwner
,
676 GetWndProcEntry16("FindTextDlgProc"),
678 SYSRES_FreeResource( hDlgTmpl
);
683 /***********************************************************************
684 * ReplaceTextDlg (COMMDLG.12)
686 BOOL
ReplaceText(LPFINDREPLACE lpFind
)
688 HANDLE hInst
, hDlgTmpl
;
691 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_REPLACE_TEXT
);
692 hInst
= WIN_GetWindowInstance( lpFind
->hwndOwner
);
693 bRet
= DialogBoxIndirectParam( hInst
, hDlgTmpl
, lpFind
->hwndOwner
,
694 GetWndProcEntry16("ReplaceTextDlgProc"),
696 SYSRES_FreeResource( hDlgTmpl
);
701 /***********************************************************************
702 * FindTextDlgProc (COMMDLG.13)
704 LRESULT
FindTextDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
709 dprintf_commdlg(stddeb
,"FindTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
710 ShowWindow(hWnd
, SW_SHOWNORMAL
);
716 EndDialog(hWnd
, TRUE
);
719 EndDialog(hWnd
, FALSE
);
728 /***********************************************************************
729 * ReplaceTextDlgProc (COMMDLG.14)
731 LRESULT
ReplaceTextDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
736 dprintf_commdlg(stddeb
,"ReplaceTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
737 ShowWindow(hWnd
, SW_SHOWNORMAL
);
743 EndDialog(hWnd
, TRUE
);
746 EndDialog(hWnd
, FALSE
);
755 /***********************************************************************
756 * PrintDlg (COMMDLG.20)
758 BOOL
PrintDlg(LPPRINTDLG lpPrint
)
760 HANDLE hInst
, hDlgTmpl
;
763 dprintf_commdlg(stddeb
,"PrintDlg(%p) // Flags=%08lX\n", lpPrint
, lpPrint
->Flags
);
765 if (lpPrint
->Flags
& PD_RETURNDEFAULT
)
766 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
769 if (lpPrint
->Flags
& PD_PRINTSETUP
)
770 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_PRINT_SETUP
);
772 hDlgTmpl
= SYSRES_LoadResource( SYSRES_DIALOG_PRINT
);
774 hInst
= WIN_GetWindowInstance( lpPrint
->hwndOwner
);
775 bRet
= DialogBoxIndirectParam( hInst
, hDlgTmpl
, lpPrint
->hwndOwner
,
776 (lpPrint
->Flags
& PD_PRINTSETUP
) ?
777 GetWndProcEntry16("PrintSetupDlgProc") :
778 GetWndProcEntry16("PrintDlgProc"),
780 SYSRES_FreeResource( hDlgTmpl
);
785 /***********************************************************************
786 * PrintDlgProc (COMMDLG.21)
788 LRESULT
PrintDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
793 dprintf_commdlg(stddeb
,"PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
794 ShowWindow(hWnd
, SW_SHOWNORMAL
);
800 EndDialog(hWnd
, TRUE
);
803 EndDialog(hWnd
, FALSE
);
812 /***********************************************************************
813 * PrintSetupDlgProc (COMMDLG.22)
815 LRESULT
PrintSetupDlgProc(HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
)
820 dprintf_commdlg(stddeb
,"PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam
);
821 ShowWindow(hWnd
, SW_SHOWNORMAL
);
826 EndDialog(hWnd
, TRUE
);
829 EndDialog(hWnd
, FALSE
);
838 /***********************************************************************
839 * CommDlgExtendedError (COMMDLG.26)
841 DWORD
CommDlgExtendedError(void)
843 return CommDlgLastError
;
847 /***********************************************************************
848 * GetFileTitle (COMMDLG.27)
850 short GetFileTitle(LPCSTR lpFile
, LPSTR lpTitle
, UINT cbBuf
)
853 dprintf_commdlg(stddeb
,"GetFileTitle(%p %p %d); \n", lpFile
, lpTitle
, cbBuf
);
854 if (lpFile
== NULL
|| lpTitle
== NULL
)
856 len
= strlen(lpFile
);
859 if (strpbrk(lpFile
, "*[]"))
862 if (lpFile
[len
] == '/' || lpFile
[len
] == '\\' || lpFile
[len
] == ':')
864 for (i
= len
; i
>= 0; i
--)
865 if (lpFile
[i
] == '/' || lpFile
[i
] == '\\' || lpFile
[i
] == ':')
870 dprintf_commdlg(stddeb
,"\n---> '%s' ", &lpFile
[i
]);
872 len
= strlen(lpFile
+i
)+1;
876 strncpy(lpTitle
, &lpFile
[i
], len
);