Release 950606
[wine/testsucceed.git] / misc / commdlg.c
blob47d08ed34a94f0ac3f63cabe307d33c53bf03c38
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 LPSTR str;
214 HBRUSH hBrush;
215 HBITMAP hBitmap, hPrevBitmap;
216 BITMAP bm;
217 HDC hMemDC;
219 if (lpdis->CtlType == ODT_LISTBOX && lpdis->CtlID == lst1) {
220 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
221 SelectObject(lpdis->hDC, hBrush);
222 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
223 str = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
224 if (str != NULL) {
225 TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
226 str, strlen(str));
227 if (lpdis->itemState != 0) {
228 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 str = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
239 if (str != NULL) {
240 hBitmap = hFolder;
241 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
242 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
243 lpdis->rcItem.top, str, strlen(str));
244 hMemDC = CreateCompatibleDC(lpdis->hDC);
245 hPrevBitmap = SelectObject(hMemDC, hBitmap);
246 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
247 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
248 SelectObject(hMemDC, hPrevBitmap);
249 DeleteDC(hMemDC);
250 if (lpdis->itemState != 0) {
251 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 str = (LPSTR) PTR_SEG_TO_LIN(lpdis->itemData);
261 if (str != NULL) {
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);
283 return TRUE;
285 return FALSE;
288 /***********************************************************************
289 * FILEDLG_WMMeasureItem [internal]
291 static LONG FILEDLG_WMMeasureItem(HWND hWnd, WORD wParam, LONG lParam)
293 BITMAP bm;
294 LPMEASUREITEMSTRUCT lpmeasure;
296 GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
297 lpmeasure = (LPMEASUREITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
298 lpmeasure->itemHeight = bm.bmHeight;
299 return TRUE;
302 /***********************************************************************
303 * FILEDLG_WMInitDialog [internal]
305 static LONG FILEDLG_WMInitDialog(HWND hWnd, WORD wParam, LONG lParam)
307 int n;
308 LPOPENFILENAME lpofn;
309 char tmpstr[512];
310 LPSTR pstr;
312 SetWindowLong(hWnd, DWL_USER, lParam);
313 lpofn = (LPOPENFILENAME)lParam;
315 /* read filter information */
316 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
317 while(*pstr) {
318 n = strlen(pstr);
319 strcpy(tmpstr, pstr);
320 SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, MAKE_SEGPTR(tmpstr));
321 pstr += n + 1;
322 n = strlen(pstr);
323 pstr += n + 1;
326 /* set default filter */
327 SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL,
328 lpofn->nFilterIndex - 1, 0);
329 strcpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter),
330 lpofn->nFilterIndex));
331 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
333 /* get drive list */
334 strcpy(tmpstr,"");
335 DlgDirListComboBox(hWnd, MAKE_SEGPTR(tmpstr), cmb2, 0, 0xC000);
337 /* read initial directory */
338 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL) {
339 strcpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir));
340 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
341 && tmpstr[strlen(tmpstr)-1] != ':')
343 strcat(tmpstr,"\\");
345 } else {
346 strcpy(tmpstr,"");
348 if (!FILEDLG_ScanDir(hWnd, tmpstr)) {
349 fprintf(stderr, "FileDlg: couldn't read initial directory!\n");
352 /* select current drive in combo 2 */
353 n = DOS_GetDefaultDrive();
354 SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, n, 0);
356 if (!(lpofn->Flags & OFN_SHOWHELP)) {
357 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
359 if (lpofn->Flags & OFN_HIDEREADONLY) {
360 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
362 return TRUE;
365 /***********************************************************************
366 * FILEDLG_WMCommand [internal]
368 static LONG FILEDLG_WMCommand(HWND hWnd, WORD wParam, LONG lParam)
370 LONG lRet;
371 LPOPENFILENAME lpofn;
372 char tmpstr[512], tmpstr2[512];
373 LPSTR pstr, pstr2;
375 lpofn = (LPOPENFILENAME)GetWindowLong(hWnd, DWL_USER);
376 switch (wParam) {
377 case lst1:
378 FILEDLG_StripEditControl(hWnd);
379 if (HIWORD(lParam) == LBN_DBLCLK) {
380 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
381 if (lRet == LB_ERR) return TRUE;
382 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet, MAKE_SEGPTR(tmpstr));
383 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
384 return SendMessage(hWnd, WM_COMMAND, IDOK, 0);
386 return TRUE;
387 case lst2:
388 FILEDLG_StripEditControl(hWnd);
389 if (HIWORD(lParam) == LBN_DBLCLK) {
390 lRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0);
391 if (lRet == LB_ERR) return TRUE;
392 SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, lRet, MAKE_SEGPTR(tmpstr));
394 if (tmpstr[0] == '[') {
395 tmpstr[strlen(tmpstr) - 1] = 0;
396 strcpy(tmpstr,tmpstr+1);
398 strcat(tmpstr, "\\");
399 FILEDLG_ScanDir(hWnd, tmpstr);
401 return TRUE;
403 case cmb1:
404 if (HIWORD(lParam) == CBN_SELCHANGE) {
405 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
406 if (lRet == LB_ERR) return TRUE;
407 strcpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter),
408 lRet + 1));
409 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
410 FILEDLG_ScanDir(hWnd, "");
412 return TRUE;
414 case cmb2:
415 FILEDLG_StripEditControl(hWnd);
416 lRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
417 if (lRet == LB_ERR) return 0;
418 SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, lRet, MAKE_SEGPTR(tmpstr));
419 sprintf(tmpstr, "%c:", tmpstr[2]);
420 FILEDLG_ScanDir(hWnd, tmpstr);
421 return TRUE;
423 case chx1:
424 return TRUE;
426 case pshHelp:
427 return TRUE;
429 case IDOK:
430 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, MAKE_SEGPTR(tmpstr));
432 pstr = strrchr(tmpstr, '\\');
433 if (pstr == NULL) pstr = strrchr(tmpstr, ':');
435 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL) {
436 /* edit control contains wildcards */
437 if (pstr != NULL) {
438 strcpy(tmpstr2, pstr+1);
439 *(pstr+1) = 0;
440 } else {
441 strcpy(tmpstr2, tmpstr);
442 strcpy(tmpstr, "");
444 printf("commdlg: %s, %s\n", tmpstr, tmpstr2);
445 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
446 FILEDLG_ScanDir(hWnd, tmpstr);
447 return TRUE;
450 /* no wildcards, we might have a directory or a filename */
451 /* try appending a wildcard and reading the directory */
452 pstr2 = tmpstr + strlen(tmpstr);
453 if (pstr == NULL || *(pstr+1) != 0) {
454 strcat(tmpstr, "\\");
456 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
457 if (lRet == LB_ERR) return TRUE;
458 strcpy(tmpstr2, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrFilter),
459 lRet + 1));
460 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
461 /* if ScanDir succeeds, we have changed the directory */
462 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
464 /* if not, this must be a filename */
465 *pstr2 = 0;
467 if (pstr != NULL) {
468 /* strip off the pathname */
469 *pstr = 0;
470 strcpy(tmpstr2, pstr+1);
471 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr2));
472 /* Should we MessageBox() if this fails? */
473 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
474 strcpy(tmpstr, tmpstr2);
475 } else {
476 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, MAKE_SEGPTR(tmpstr));
479 ShowWindow(hWnd, SW_HIDE);
480 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr);
481 lpofn->nFileOffset = 0;
482 lpofn->nFileExtension = strlen(PTR_SEG_TO_LIN(lpofn->lpstrFile)) - 3;
483 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL) {
484 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
485 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet, MAKE_SEGPTR(tmpstr));
486 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFileTitle), tmpstr);
488 EndDialog(hWnd, TRUE);
489 return TRUE;
490 case IDCANCEL:
491 EndDialog(hWnd, FALSE);
492 return TRUE;
494 return FALSE;
497 /***********************************************************************
498 * FileOpenDlgProc [COMMDLG.6]
500 BOOL FileOpenDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
502 switch (wMsg) {
503 case WM_INITDIALOG:
504 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
506 case WM_MEASUREITEM:
507 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
509 case WM_DRAWITEM:
510 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
512 case WM_COMMAND:
513 return FILEDLG_WMCommand(hWnd, wParam, lParam);
517 case WM_CTLCOLOR:
518 SetBkColor((HDC)wParam, 0x00C0C0C0);
519 switch (HIWORD(lParam))
521 case CTLCOLOR_BTN:
522 SetTextColor((HDC)wParam, 0x00000000);
523 return hGRAYBrush;
524 case CTLCOLOR_STATIC:
525 SetTextColor((HDC)wParam, 0x00000000);
526 return hGRAYBrush;
528 return FALSE;
531 return FALSE;
535 /***********************************************************************
536 * FileSaveDlgProc [COMMDLG.7]
538 BOOL FileSaveDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
540 switch (wMsg) {
541 case WM_INITDIALOG:
542 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
544 case WM_MEASUREITEM:
545 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
547 case WM_DRAWITEM:
548 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
550 case WM_COMMAND:
551 return FILEDLG_WMCommand(hWnd, wParam, lParam);
555 case WM_CTLCOLOR:
556 SetBkColor((HDC)wParam, 0x00C0C0C0);
557 switch (HIWORD(lParam))
559 case CTLCOLOR_BTN:
560 SetTextColor((HDC)wParam, 0x00000000);
561 return hGRAYBrush;
562 case CTLCOLOR_STATIC:
563 SetTextColor((HDC)wParam, 0x00000000);
564 return hGRAYBrush;
566 return FALSE;
569 return FALSE;
573 /***********************************************************************
574 * ChooseColor [COMMDLG.5]
576 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
578 WND *wndPtr;
579 BOOL bRet;
580 wndPtr = WIN_FindWndPtr(lpChCol->hwndOwner);
581 bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, sysres_DIALOG_8,
582 lpChCol->hwndOwner, GetWndProcEntry16("ColorDlgProc"),
583 (DWORD)lpChCol);
584 return bRet;
588 /***********************************************************************
589 * ColorDlgProc [COMMDLG.8]
591 BOOL ColorDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
593 switch (wMsg) {
594 case WM_INITDIALOG:
595 printf("ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
596 ShowWindow(hWnd, SW_SHOWNORMAL);
597 return (TRUE);
599 case WM_COMMAND:
600 switch (wParam) {
601 case IDOK:
602 EndDialog(hWnd, TRUE);
603 return(TRUE);
604 case IDCANCEL:
605 EndDialog(hWnd, FALSE);
606 return(TRUE);
608 return(FALSE);
610 return FALSE;
614 /***********************************************************************
615 * FindTextDlg [COMMDLG.11]
617 BOOL FindText(LPFINDREPLACE lpFind)
619 WND *wndPtr;
620 BOOL bRet;
621 LPCSTR lpTemplate;
623 lpTemplate = sysres_DIALOG_9;
624 wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
625 bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
626 lpFind->hwndOwner, GetWndProcEntry16("FindTextDlgProc"),
627 (DWORD)lpFind);
628 return bRet;
632 /***********************************************************************
633 * ReplaceTextDlg [COMMDLG.12]
635 BOOL ReplaceText(LPFINDREPLACE lpFind)
637 WND *wndPtr;
638 BOOL bRet;
639 LPCSTR lpTemplate;
641 lpTemplate = sysres_DIALOG_10;
642 wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
643 bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
644 lpFind->hwndOwner, GetWndProcEntry16("ReplaceTextDlgProc"),
645 (DWORD)lpFind);
646 return bRet;
650 /***********************************************************************
651 * FindTextDlgProc [COMMDLG.13]
653 BOOL FindTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
655 switch (wMsg) {
656 case WM_INITDIALOG:
657 printf("FindTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
658 ShowWindow(hWnd, SW_SHOWNORMAL);
659 return (TRUE);
661 case WM_COMMAND:
662 switch (wParam) {
663 case IDOK:
664 EndDialog(hWnd, TRUE);
665 return(TRUE);
666 case IDCANCEL:
667 EndDialog(hWnd, FALSE);
668 return(TRUE);
670 return(FALSE);
672 return FALSE;
676 /***********************************************************************
677 * ReplaceTextDlgProc [COMMDLG.14]
679 BOOL ReplaceTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
681 switch (wMsg) {
682 case WM_INITDIALOG:
683 printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
684 ShowWindow(hWnd, SW_SHOWNORMAL);
685 return (TRUE);
687 case WM_COMMAND:
688 switch (wParam) {
689 case IDOK:
690 EndDialog(hWnd, TRUE);
691 return(TRUE);
692 case IDCANCEL:
693 EndDialog(hWnd, FALSE);
694 return(TRUE);
696 return(FALSE);
698 return FALSE;
702 /***********************************************************************
703 * PrintDlg [COMMDLG.20]
705 BOOL PrintDlg(LPPRINTDLG lpPrint)
707 WND *wndPtr;
708 BOOL bRet;
709 LPCSTR lpTemplate;
711 printf("PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags);
712 if (lpPrint->Flags & PD_PRINTSETUP) {
713 lpTemplate = sysres_DIALOG_6;
714 } else {
715 lpTemplate = sysres_DIALOG_5;
717 wndPtr = WIN_FindWndPtr(lpPrint->hwndOwner);
718 if (lpPrint->Flags & PD_PRINTSETUP)
719 bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
720 lpPrint->hwndOwner, GetWndProcEntry16("PrintSetupDlgProc"),
721 (DWORD)lpPrint);
722 else
723 bRet = DialogBoxIndirectParamPtr(wndPtr->hInstance, lpTemplate,
724 lpPrint->hwndOwner, GetWndProcEntry16("PrintDlgProc"),
725 (DWORD)lpPrint);
726 return bRet;
730 /***********************************************************************
731 * PrintDlgProc [COMMDLG.21]
733 BOOL PrintDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
735 switch (wMsg) {
736 case WM_INITDIALOG:
737 printf("PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
738 ShowWindow(hWnd, SW_SHOWNORMAL);
739 return (TRUE);
741 case WM_COMMAND:
742 switch (wParam) {
743 case IDOK:
744 EndDialog(hWnd, TRUE);
745 return(TRUE);
746 case IDCANCEL:
747 EndDialog(hWnd, FALSE);
748 return(TRUE);
750 return(FALSE);
752 return FALSE;
756 /***********************************************************************
757 * PrintSetupDlgProc [COMMDLG.22]
759 BOOL PrintSetupDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
761 switch (wMsg) {
762 case WM_INITDIALOG:
763 printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
764 ShowWindow(hWnd, SW_SHOWNORMAL);
765 return (TRUE);
767 case WM_COMMAND:
768 switch (wParam) {
769 case IDOK:
770 EndDialog(hWnd, TRUE);
771 return(TRUE);
772 case IDCANCEL:
773 EndDialog(hWnd, FALSE);
774 return(TRUE);
776 return(FALSE);
778 return FALSE;
782 /***********************************************************************
783 * CommDlgExtendError [COMMDLG.26]
785 DWORD CommDlgExtendError(void)
787 return CommDlgLastError;
791 /***********************************************************************
792 * GetFileTitle [COMMDLG.27]
794 int GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
796 int i, len;
797 printf("GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
798 if (lpFile == NULL || lpTitle == NULL) return -1;
799 len = strlen(lpFile);
800 if (len == 0) return -1;
801 if (strchr(lpFile, '*') != NULL) return -1;
802 if (strchr(lpFile, '[') != NULL) return -1;
803 if (strchr(lpFile, ']') != NULL) return -1;
804 len--;
805 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':') return -1;
806 for (i = len; i >= 0; i--) {
807 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':') {
808 i++;
809 break;
812 printf("\n---> '%s' ", &lpFile[i]);
813 len = min(cbBuf, strlen(&lpFile[i]) + 1);
814 strncpy(lpTitle, &lpFile[i], len + 1);
815 if (len != cbBuf)
816 return len;
817 else
818 return 0;