Release 950620
[wine/multimedia.git] / misc / commdlg.c
blob23832295fa7a6fd62dbcb56652ed433cedaa3482
1 /*
2 * COMMDLG functions
4 * Copyright 1994 Martin Ayotte
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include "dialog.h"
11 #include "win.h"
12 #include "user.h"
13 #include "message.h"
14 #include "commdlg.h"
15 #include "dlgs.h"
16 #include "selectors.h"
17 #include "../rc/sysres.h"
18 #include "dos_fs.h"
19 #include "stackframe.h"
21 #define OPENFILEDLG2 11
22 #define SAVEFILEDLG2 12
24 static DWORD CommDlgLastError = 0;
26 static HBITMAP hFolder = 0;
27 static HBITMAP hFolder2 = 0;
28 static HBITMAP hFloppy = 0;
29 static HBITMAP hHDisk = 0;
30 static HBITMAP hCDRom = 0;
32 /***********************************************************************
33 * FileDlg_Init [internal]
35 static BOOL FileDlg_Init()
37 static BOOL initialized = 0;
39 if (!initialized) {
40 if (!hFolder) hFolder = LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER));
41 if (!hFolder2) hFolder2 = LoadBitmap(0, MAKEINTRESOURCE(OBM_FOLDER2));
42 if (!hFloppy) hFloppy = LoadBitmap(0, MAKEINTRESOURCE(OBM_FLOPPY));
43 if (!hHDisk) hHDisk = LoadBitmap(0, MAKEINTRESOURCE(OBM_HDISK));
44 if (!hCDRom) hCDRom = LoadBitmap(0, MAKEINTRESOURCE(OBM_CDROM));
45 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
46 hHDisk == 0 || hCDRom == 0)
48 fprintf(stderr, "FileDlg_Init // Error loading bitmaps !");
49 return FALSE;
51 initialized = TRUE;
53 return TRUE;
56 /***********************************************************************
57 * GetOpenFileName [COMMDLG.1]
59 BOOL GetOpenFileName(LPOPENFILENAME lpofn)
61 HANDLE hDlgTmpl;
62 HANDLE hResInfo;
63 HINSTANCE hInst;
64 BOOL bRet;
65 LPCSTR dlgTemplate;
67 if (!FileDlg_Init()) return FALSE;
69 if (lpofn == NULL) return FALSE;
70 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
71 dlgTemplate = GlobalLock(lpofn->hInstance);
72 if (!dlgTemplate) {
73 CommDlgLastError = CDERR_LOADRESFAILURE;
74 return FALSE;
76 } else {
77 if (lpofn->Flags & OFN_ENABLETEMPLATE) {
78 hInst = lpofn->hInstance;
79 hResInfo = FindResource(hInst, lpofn->lpTemplateName, RT_DIALOG);
80 if (hResInfo == 0) {
81 CommDlgLastError = CDERR_FINDRESFAILURE;
82 return FALSE;
84 hDlgTmpl = LoadResource(hInst, hResInfo);
85 if (hDlgTmpl == 0) {
86 CommDlgLastError = CDERR_LOADRESFAILURE;
87 return FALSE;
89 dlgTemplate = GlobalLock(hDlgTmpl);
90 } else {
91 dlgTemplate = sysres_DIALOG_3;
94 hInst = GetWindowWord(lpofn->hwndOwner, GWW_HINSTANCE);
95 bRet = DialogBoxIndirectParamPtr(hInst, dlgTemplate, lpofn->hwndOwner,
96 GetWndProcEntry16("FileOpenDlgProc"),
97 (DWORD)lpofn);
99 printf("GetOpenFileName // return lpstrFile='%s' !\n",
100 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
101 return bRet;
105 /***********************************************************************
106 * GetSaveFileName [COMMDLG.2]
108 BOOL GetSaveFileName(LPOPENFILENAME lpofn)
110 HANDLE hDlgTmpl;
111 HANDLE hResInfo;
112 HINSTANCE hInst;
113 BOOL bRet;
114 LPCSTR dlgTemplate;
116 if (!FileDlg_Init()) return FALSE;
118 if (lpofn == NULL) return FALSE;
119 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
120 dlgTemplate = GlobalLock(lpofn->hInstance);
121 if (!dlgTemplate) {
122 CommDlgLastError = CDERR_LOADRESFAILURE;
123 return FALSE;
125 } else {
126 if (lpofn->Flags & OFN_ENABLETEMPLATE) {
127 hInst = lpofn->hInstance;
128 hResInfo = FindResource(hInst, lpofn->lpTemplateName, RT_DIALOG);
129 if (hResInfo == 0) {
130 CommDlgLastError = CDERR_FINDRESFAILURE;
131 return FALSE;
133 hDlgTmpl = LoadResource(hInst, hResInfo);
134 if (hDlgTmpl == 0) {
135 CommDlgLastError = CDERR_LOADRESFAILURE;
136 return FALSE;
138 dlgTemplate = GlobalLock(hDlgTmpl);
139 } else {
140 dlgTemplate = sysres_DIALOG_4; /* SAVEFILEDIALOG */
143 hInst = GetWindowWord(lpofn->hwndOwner, GWW_HINSTANCE);
144 bRet = DialogBoxIndirectParamPtr(hInst, dlgTemplate, lpofn->hwndOwner,
145 GetWndProcEntry16("FileSaveDlgProc"),
146 (DWORD)lpofn);
147 printf("GetSaveFileName // return lpstrFile='%s' !\n",
148 (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFile));
149 return bRet;
152 /***********************************************************************
153 * FILEDLG_StripEditControl [internal]
154 * Strip pathnames off the contents of the edit control.
156 static void FILEDLG_StripEditControl(HWND hwnd)
158 char temp[512], *cp;
160 SendDlgItemMessage(hwnd, edt1, WM_GETTEXT, 511, MAKE_SEGPTR(temp));
161 cp = strrchr(temp, '\\');
162 if (cp != NULL) {
163 strcpy(temp, cp+1);
165 cp = strrchr(temp, ':');
166 if (cp != NULL) {
167 strcpy(temp, cp+1);
171 /***********************************************************************
172 * FILEDLG_ScanDir [internal]
174 static BOOL FILEDLG_ScanDir(HWND hWnd, LPSTR newPath)
176 char str[512],str2[512];
178 strcpy(str,newPath);
179 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, MAKE_SEGPTR(str2));
180 strcat(str, str2);
181 if (!DlgDirList(hWnd, str, lst1, 0, 0x0000)) return FALSE;
182 DlgDirList(hWnd, "*.*", lst2, stc1, 0x8010);
184 return TRUE;
187 /***********************************************************************
188 * FILEDLG_GetFileType [internal]
190 static LPSTR FILEDLG_GetFileType(LPSTR ptr, WORD index)
192 int n, i;
194 if (ptr == NULL) return NULL;
196 for (i = 1;;i++) {
197 n = strlen(ptr);
198 if (n == 0) break;
199 ptr += n + 1;
200 if (i == index) return ptr;
201 n = strlen(ptr);
202 ptr += n + 1;
204 return NULL;
207 /***********************************************************************
208 * FILEDLG_WMDrawItem [internal]
210 static LONG FILEDLG_WMDrawItem(HWND hWnd, WORD wParam, LONG lParam)
212 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
213 char str[512];
214 HBRUSH hBrush;
215 HBITMAP hBitmap, hPrevBitmap;
216 BITMAP bm;
217 HDC hMemDC;
219 strcpy(str, "");
220 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1) {
221 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
222 SelectObject(lpdis->hDC, hBrush);
223 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
224 SendMessage(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
225 MAKE_SEGPTR(str));
226 TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
227 str, strlen(str));
228 if (lpdis->itemState != 0) {
229 InvertRect(lpdis->hDC, &lpdis->rcItem);
231 return TRUE;
234 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst2) {
235 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
236 SelectObject(lpdis->hDC, hBrush);
237 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
238 SendMessage(lpdis->hwndItem, LB_GETTEXT, lpdis->itemID,
239 MAKE_SEGPTR(str));
241 hBitmap = hFolder;
242 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
243 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
244 lpdis->rcItem.top, str, strlen(str));
245 hMemDC = CreateCompatibleDC(lpdis->hDC);
246 hPrevBitmap = SelectObject(hMemDC, hBitmap);
247 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
248 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
249 SelectObject(hMemDC, hPrevBitmap);
250 DeleteDC(hMemDC);
251 if (lpdis->itemState != 0) {
252 InvertRect(lpdis->hDC, &lpdis->rcItem);
254 return TRUE;
256 if (lpdis->CtlType == ODT_COMBOBOX && lpdis->CtlID == cmb2) {
257 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
258 SelectObject(lpdis->hDC, hBrush);
259 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
260 SendMessage(lpdis->hwndItem, CB_GETLBTEXT, lpdis->itemID,
261 MAKE_SEGPTR(str));
262 switch(str[2]) {
263 case 'a': case 'b':
264 hBitmap = hFloppy;
265 break;
266 default:
267 hBitmap = hHDisk;
268 break;
270 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
271 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
272 lpdis->rcItem.top, str, strlen(str));
273 hMemDC = CreateCompatibleDC(lpdis->hDC);
274 hPrevBitmap = SelectObject(hMemDC, hBitmap);
275 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
276 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
277 SelectObject(hMemDC, hPrevBitmap);
278 DeleteDC(hMemDC);
279 if (lpdis->itemState != 0) {
280 InvertRect(lpdis->hDC, &lpdis->rcItem);
282 return TRUE;
284 return FALSE;
287 /***********************************************************************
288 * FILEDLG_WMMeasureItem [internal]
290 static LONG FILEDLG_WMMeasureItem(HWND hWnd, WORD wParam, LONG lParam)
292 BITMAP bm;
293 LPMEASUREITEMSTRUCT lpmeasure;
295 GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
296 lpmeasure = (LPMEASUREITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
297 lpmeasure->itemHeight = bm.bmHeight;
298 return TRUE;
301 /***********************************************************************
302 * FILEDLG_WMInitDialog [internal]
304 static LONG FILEDLG_WMInitDialog(HWND hWnd, WORD wParam, LONG lParam)
306 int n;
307 LPOPENFILENAME lpofn;
308 char tmpstr[512];
309 LPSTR pstr;
311 SetWindowLong(hWnd, DWL_USER, lParam);
312 lpofn = (LPOPENFILENAME)lParam;
314 /* read filter information */
315 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
316 while(*pstr) {
317 n = strlen(pstr);
318 strcpy(tmpstr, pstr);
319 SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, MAKE_SEGPTR(tmpstr));
320 pstr += n + 1;
321 n = strlen(pstr);
322 pstr += n + 1;
325 /* set default filter */
326 SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL,
327 lpofn->nFilterIndex - 1, 0);
328 strcpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter),
329 lpofn->nFilterIndex));
330 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
332 /* get drive list */
333 strcpy(tmpstr,"");
334 DlgDirListComboBox(hWnd, MAKE_SEGPTR(tmpstr), cmb2, 0, 0xC000);
336 /* read initial directory */
337 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL) {
338 strcpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir));
339 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
340 && tmpstr[strlen(tmpstr)-1] != ':')
342 strcat(tmpstr,"\\");
344 } else {
345 strcpy(tmpstr,"");
347 if (!FILEDLG_ScanDir(hWnd, tmpstr)) {
348 fprintf(stderr, "FileDlg: couldn't read initial directory!\n");
351 /* select current drive in combo 2 */
352 n = DOS_GetDefaultDrive();
353 SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, n, 0);
355 if (!(lpofn->Flags & OFN_SHOWHELP)) {
356 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
358 if (lpofn->Flags & OFN_HIDEREADONLY) {
359 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
361 return TRUE;
364 /***********************************************************************
365 * FILEDLG_WMCommand [internal]
367 static LONG FILEDLG_WMCommand(HWND hWnd, WORD wParam, LONG lParam)
369 LONG lRet;
370 LPOPENFILENAME lpofn;
371 char tmpstr[512], tmpstr2[512];
372 LPSTR pstr, pstr2;
374 lpofn = (LPOPENFILENAME)GetWindowLong(hWnd, DWL_USER);
375 switch (wParam) {
376 case lst1:
377 FILEDLG_StripEditControl(hWnd);
378 if (HIWORD(lParam) == LBN_DBLCLK) {
379 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
380 if (lRet == LB_ERR) return TRUE;
381 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet, MAKE_SEGPTR(tmpstr));
382 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
383 return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
385 return TRUE;
386 case lst2:
387 FILEDLG_StripEditControl(hWnd);
388 if (HIWORD(lParam) == LBN_DBLCLK) {
389 lRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0);
390 if (lRet == LB_ERR) return TRUE;
391 SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, lRet, MAKE_SEGPTR(tmpstr));
393 if (tmpstr[0] == '[') {
394 tmpstr[strlen(tmpstr) - 1] = 0;
395 strcpy(tmpstr,tmpstr+1);
397 strcat(tmpstr, "\\");
398 FILEDLG_ScanDir(hWnd, tmpstr);
400 return TRUE;
402 case cmb1:
403 if (HIWORD(lParam) == CBN_SELCHANGE) {
404 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
405 if (lRet == LB_ERR) return TRUE;
406 strcpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter),
407 lRet + 1));
408 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
409 FILEDLG_ScanDir(hWnd, "");
411 return TRUE;
413 case cmb2:
414 FILEDLG_StripEditControl(hWnd);
415 lRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
416 if (lRet == LB_ERR) return 0;
417 SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, lRet, MAKE_SEGPTR(tmpstr));
418 sprintf(tmpstr, "%c:", tmpstr[2]);
419 FILEDLG_ScanDir(hWnd, tmpstr);
420 return TRUE;
422 case chx1:
423 return TRUE;
425 case pshHelp:
426 return TRUE;
428 case IDOK:
429 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, MAKE_SEGPTR(tmpstr));
431 pstr = strrchr(tmpstr, '\\');
432 if (pstr == NULL) pstr = strrchr(tmpstr, ':');
434 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL) {
435 /* edit control contains wildcards */
436 if (pstr != NULL) {
437 strcpy(tmpstr2, pstr+1);
438 *(pstr+1) = 0;
439 } else {
440 strcpy(tmpstr2, tmpstr);
441 strcpy(tmpstr, "");
443 printf("commdlg: %s, %s\n", tmpstr, tmpstr2);
444 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
445 FILEDLG_ScanDir(hWnd, tmpstr);
446 return TRUE;
449 /* no wildcards, we might have a directory or a filename */
450 /* try appending a wildcard and reading the directory */
451 pstr2 = tmpstr + strlen(tmpstr);
452 if (pstr == NULL || *(pstr+1) != 0) {
453 strcat(tmpstr, "\\");
455 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
456 if (lRet == LB_ERR) return TRUE;
457 strcpy(tmpstr2, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter),
458 lRet + 1));
459 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
460 /* if ScanDir succeeds, we have changed the directory */
461 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
463 /* if not, this must be a filename */
464 *pstr2 = 0;
466 if (pstr != NULL) {
467 /* strip off the pathname */
468 *pstr = 0;
469 strcpy(tmpstr2, pstr+1);
470 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
471 /* Should we MessageBox() if this fails? */
472 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
473 strcpy(tmpstr, tmpstr2);
474 } else {
475 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
478 ShowWindow(hWnd, SW_HIDE);
479 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr);
480 lpofn->nFileOffset = 0;
481 lpofn->nFileExtension = strlen(PTR_SEG_TO_LIN(lpofn->lpstrFile)) - 3;
482 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL) {
483 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
484 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet, MAKE_SEGPTR(tmpstr));
485 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFileTitle), tmpstr);
487 EndDialog(hWnd, TRUE);
488 return TRUE;
489 case IDCANCEL:
490 EndDialog(hWnd, FALSE);
491 return TRUE;
493 return FALSE;
496 /***********************************************************************
497 * FileOpenDlgProc [COMMDLG.6]
499 BOOL FileOpenDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
501 switch (wMsg) {
502 case WM_INITDIALOG:
503 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
505 case WM_MEASUREITEM:
506 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
508 case WM_DRAWITEM:
509 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
511 case WM_COMMAND:
512 return FILEDLG_WMCommand(hWnd, wParam, lParam);
516 case WM_CTLCOLOR:
517 SetBkColor((HDC)wParam, 0x00C0C0C0);
518 switch (HIWORD(lParam))
520 case CTLCOLOR_BTN:
521 SetTextColor((HDC)wParam, 0x00000000);
522 return hGRAYBrush;
523 case CTLCOLOR_STATIC:
524 SetTextColor((HDC)wParam, 0x00000000);
525 return hGRAYBrush;
527 return FALSE;
530 return FALSE;
534 /***********************************************************************
535 * FileSaveDlgProc [COMMDLG.7]
537 BOOL FileSaveDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
539 switch (wMsg) {
540 case WM_INITDIALOG:
541 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
543 case WM_MEASUREITEM:
544 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
546 case WM_DRAWITEM:
547 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
549 case WM_COMMAND:
550 return FILEDLG_WMCommand(hWnd, wParam, lParam);
554 case WM_CTLCOLOR:
555 SetBkColor((HDC)wParam, 0x00C0C0C0);
556 switch (HIWORD(lParam))
558 case CTLCOLOR_BTN:
559 SetTextColor((HDC)wParam, 0x00000000);
560 return hGRAYBrush;
561 case CTLCOLOR_STATIC:
562 SetTextColor((HDC)wParam, 0x00000000);
563 return hGRAYBrush;
565 return FALSE;
568 return FALSE;
572 /***********************************************************************
573 * ChooseColor [COMMDLG.5]
575 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
577 WND *wndPtr;
578 BOOL bRet;
579 wndPtr = WIN_FindWndPtr(lpChCol->hwndOwner);
580 bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, sysres_DIALOG_8,
581 lpChCol->hwndOwner, GetWndProcEntry16("ColorDlgProc"),
582 (DWORD)lpChCol);
583 return bRet;
587 /***********************************************************************
588 * ColorDlgProc [COMMDLG.8]
590 BOOL ColorDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
592 switch (wMsg) {
593 case WM_INITDIALOG:
594 printf("ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
595 ShowWindow(hWnd, SW_SHOWNORMAL);
596 return (TRUE);
598 case WM_COMMAND:
599 switch (wParam) {
600 case IDOK:
601 EndDialog(hWnd, TRUE);
602 return(TRUE);
603 case IDCANCEL:
604 EndDialog(hWnd, FALSE);
605 return(TRUE);
607 return(FALSE);
609 return FALSE;
613 /***********************************************************************
614 * FindTextDlg [COMMDLG.11]
616 BOOL FindText(LPFINDREPLACE lpFind)
618 WND *wndPtr;
619 BOOL bRet;
620 LPCSTR lpTemplate;
622 lpTemplate = sysres_DIALOG_9;
623 wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
624 bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
625 lpFind->hwndOwner, GetWndProcEntry16("FindTextDlgProc"),
626 (DWORD)lpFind);
627 return bRet;
631 /***********************************************************************
632 * ReplaceTextDlg [COMMDLG.12]
634 BOOL ReplaceText(LPFINDREPLACE lpFind)
636 WND *wndPtr;
637 BOOL bRet;
638 LPCSTR lpTemplate;
640 lpTemplate = sysres_DIALOG_10;
641 wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
642 bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
643 lpFind->hwndOwner, GetWndProcEntry16("ReplaceTextDlgProc"),
644 (DWORD)lpFind);
645 return bRet;
649 /***********************************************************************
650 * FindTextDlgProc [COMMDLG.13]
652 BOOL FindTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
654 switch (wMsg) {
655 case WM_INITDIALOG:
656 printf("FindTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
657 ShowWindow(hWnd, SW_SHOWNORMAL);
658 return (TRUE);
660 case WM_COMMAND:
661 switch (wParam) {
662 case IDOK:
663 EndDialog(hWnd, TRUE);
664 return(TRUE);
665 case IDCANCEL:
666 EndDialog(hWnd, FALSE);
667 return(TRUE);
669 return(FALSE);
671 return FALSE;
675 /***********************************************************************
676 * ReplaceTextDlgProc [COMMDLG.14]
678 BOOL ReplaceTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
680 switch (wMsg) {
681 case WM_INITDIALOG:
682 printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
683 ShowWindow(hWnd, SW_SHOWNORMAL);
684 return (TRUE);
686 case WM_COMMAND:
687 switch (wParam) {
688 case IDOK:
689 EndDialog(hWnd, TRUE);
690 return(TRUE);
691 case IDCANCEL:
692 EndDialog(hWnd, FALSE);
693 return(TRUE);
695 return(FALSE);
697 return FALSE;
701 /***********************************************************************
702 * PrintDlg [COMMDLG.20]
704 BOOL PrintDlg(LPPRINTDLG lpPrint)
706 WND *wndPtr;
707 BOOL bRet;
708 LPCSTR lpTemplate;
710 printf("PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags);
711 if (lpPrint->Flags & PD_PRINTSETUP) {
712 lpTemplate = sysres_DIALOG_6;
713 } else {
714 lpTemplate = sysres_DIALOG_5;
716 wndPtr = WIN_FindWndPtr(lpPrint->hwndOwner);
717 if (lpPrint->Flags & PD_PRINTSETUP)
718 bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
719 lpPrint->hwndOwner, GetWndProcEntry16("PrintSetupDlgProc"),
720 (DWORD)lpPrint);
721 else
722 bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
723 lpPrint->hwndOwner, GetWndProcEntry16("PrintDlgProc"),
724 (DWORD)lpPrint);
725 return bRet;
729 /***********************************************************************
730 * PrintDlgProc [COMMDLG.21]
732 BOOL PrintDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
734 switch (wMsg) {
735 case WM_INITDIALOG:
736 printf("PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
737 ShowWindow(hWnd, SW_SHOWNORMAL);
738 return (TRUE);
740 case WM_COMMAND:
741 switch (wParam) {
742 case IDOK:
743 EndDialog(hWnd, TRUE);
744 return(TRUE);
745 case IDCANCEL:
746 EndDialog(hWnd, FALSE);
747 return(TRUE);
749 return(FALSE);
751 return FALSE;
755 /***********************************************************************
756 * PrintSetupDlgProc [COMMDLG.22]
758 BOOL PrintSetupDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
760 switch (wMsg) {
761 case WM_INITDIALOG:
762 printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
763 ShowWindow(hWnd, SW_SHOWNORMAL);
764 return (TRUE);
766 case WM_COMMAND:
767 switch (wParam) {
768 case IDOK:
769 EndDialog(hWnd, TRUE);
770 return(TRUE);
771 case IDCANCEL:
772 EndDialog(hWnd, FALSE);
773 return(TRUE);
775 return(FALSE);
777 return FALSE;
781 /***********************************************************************
782 * CommDlgExtendError [COMMDLG.26]
784 DWORD CommDlgExtendError(void)
786 return CommDlgLastError;
790 /***********************************************************************
791 * GetFileTitle [COMMDLG.27]
793 int GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
795 int i, len;
796 printf("GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
797 if (lpFile == NULL || lpTitle == NULL) return -1;
798 len = strlen(lpFile);
799 if (len == 0) return -1;
800 if (strchr(lpFile, '*') != NULL) return -1;
801 if (strchr(lpFile, '[') != NULL) return -1;
802 if (strchr(lpFile, ']') != NULL) return -1;
803 len--;
804 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':') return -1;
805 for (i = len; i >= 0; i--) {
806 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':') {
807 i++;
808 break;
811 printf("\n---> '%s' ", &lpFile[i]);
812 len = min(cbBuf, strlen(&lpFile[i]) + 1);
813 strncpy(lpTitle, &lpFile[i], len + 1);
814 if (len != cbBuf)
815 return len;
816 else
817 return 0;