Release 960324
[wine/multimedia.git] / misc / commdlg.c
blob3d242f799e7309293ebf51454d23a2f0f804384c
1 /*
2 * COMMDLG functions
4 * Copyright 1994 Martin Ayotte
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include "win.h"
11 #include "user.h"
12 #include "message.h"
13 #include "commdlg.h"
14 #include "dlgs.h"
15 #include "selectors.h"
16 #include "resource.h"
17 #include "dos_fs.h"
18 #include "drive.h"
19 #include "stackframe.h"
20 #include "stddebug.h"
21 #include "debug.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;
38 if (!initialized) {
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 !");
48 return FALSE;
50 initialized = TRUE;
52 return TRUE;
55 /***********************************************************************
56 * GetOpenFileName (COMMDLG.1)
58 BOOL GetOpenFileName(LPOPENFILENAME lpofn)
60 HINSTANCE hInst;
61 HANDLE hDlgTmpl, hResInfo;
62 BOOL bRet;
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;
73 return FALSE;
75 hDlgTmpl = LoadResource( lpofn->hInstance, hResInfo );
77 else hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_OPEN_FILE );
78 if (!hDlgTmpl)
80 CommDlgLastError = CDERR_LOADRESFAILURE;
81 return FALSE;
84 hInst = WIN_GetWindowInstance( lpofn->hwndOwner );
85 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpofn->hwndOwner,
86 GetWndProcEntry16("FileOpenDlgProc"),
87 (DWORD)lpofn );
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));
97 return bRet;
101 /***********************************************************************
102 * GetSaveFileName (COMMDLG.2)
104 BOOL GetSaveFileName(LPOPENFILENAME lpofn)
106 HINSTANCE hInst;
107 HANDLE hDlgTmpl, hResInfo;
108 BOOL bRet;
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;
120 return FALSE;
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"),
129 (DWORD)lpofn);
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));
138 return bRet;
141 /***********************************************************************
142 * FILEDLG_StripEditControl [internal]
143 * Strip pathnames off the contents of the edit control.
145 static void FILEDLG_StripEditControl(HWND hwnd)
147 char temp[512], *cp;
149 SendDlgItemMessage(hwnd, edt1, WM_GETTEXT, 511, (LPARAM)MAKE_SEGPTR(temp));
150 cp = strrchr(temp, '\\');
151 if (cp != NULL) {
152 strcpy(temp, cp+1);
154 cp = strrchr(temp, ':');
155 if (cp != NULL) {
156 strcpy(temp, cp+1);
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);
173 return TRUE;
176 /***********************************************************************
177 * FILEDLG_GetFileType [internal]
180 static LPSTR FILEDLG_GetFileType(LPSTR cfptr, LPSTR fptr, WORD index)
182 int n, i;
183 i = 0;
184 if (cfptr)
185 for ( ;(n = strlen(cfptr)) != 0; i++)
187 cfptr += n + 1;
188 if (i == index)
189 return cfptr;
190 cfptr += strlen(cfptr) + 1;
192 if (fptr)
193 for ( ;(n = strlen(fptr)) != 0; i++)
195 fptr += n + 1;
196 if (i == index)
197 return fptr;
198 fptr += strlen(fptr) + 1;
200 return NULL;
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);
209 char str[512];
210 HBRUSH hBrush;
211 HBITMAP hBitmap, hPrevBitmap;
212 BITMAP bm;
213 HDC hMemDC;
215 str[0]=0;
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,
223 str, strlen(str));
224 if (lpdis->itemState != 0) {
225 InvertRect(lpdis->hDC, &lpdis->rcItem);
227 return TRUE;
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));
237 hBitmap = hFolder;
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);
246 DeleteDC(hMemDC);
247 if (lpdis->itemState != 0) {
248 InvertRect(lpdis->hDC, &lpdis->rcItem);
250 return TRUE;
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;
262 case TYPE_HD:
263 case TYPE_NETWORK:
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);
274 DeleteDC(hMemDC);
275 if (lpdis->itemState != 0) {
276 InvertRect(lpdis->hDC, &lpdis->rcItem);
278 return TRUE;
280 return FALSE;
283 /***********************************************************************
284 * FILEDLG_WMMeasureItem [internal]
286 static LONG FILEDLG_WMMeasureItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
288 BITMAP bm;
289 LPMEASUREITEMSTRUCT lpmeasure;
291 GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
292 lpmeasure = (LPMEASUREITEMSTRUCT)PTR_SEG_TO_LIN(lParam);
293 lpmeasure->itemHeight = bm.bmHeight;
294 return TRUE;
297 /***********************************************************************
298 * FILEDLG_HookCallChk [internal]
300 static int FILEDLG_HookCallChk(LPOPENFILENAME lpofn)
302 if (lpofn)
303 if (lpofn->Flags & OFN_ENABLEHOOK)
304 if (lpofn->lpfnHook)
305 return 1;
306 return 0;
309 /***********************************************************************
310 * FILEDLG_WMInitDialog [internal]
313 static LONG FILEDLG_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
315 int n;
316 int i;
317 LPOPENFILENAME lpofn;
318 char tmpstr[512];
319 LPSTR pstr;
320 SetWindowLong(hWnd, DWL_USER, lParam);
321 lpofn = (LPOPENFILENAME)lParam;
322 /* read custom filter information */
323 if (lpofn->lpstrCustomFilter)
325 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter);
326 dprintf_commdlg(stddeb,"lpstrCustomFilter = %p\n", pstr);
327 while(*pstr)
329 n = strlen(pstr);
330 strncpy(tmpstr, pstr, 511); tmpstr[511]=0;
331 dprintf_commdlg(stddeb,"lpstrCustomFilter // add tmpstr='%s' ", tmpstr);
332 i = SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
333 pstr += n + 1;
334 n = strlen(pstr);
335 dprintf_commdlg(stddeb,"associated to '%s'\n", pstr);
336 SendDlgItemMessage(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr);
337 pstr += n + 1;
340 /* read filter information */
341 pstr = (LPSTR)PTR_SEG_TO_LIN(lpofn->lpstrFilter);
342 while(*pstr)
344 n = strlen(pstr);
345 strncpy(tmpstr, pstr, 511); tmpstr[511]=0;
346 dprintf_commdlg(stddeb,"lpstrFilter // add tmpstr='%s' ", tmpstr);
347 i = SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
348 pstr += n + 1;
349 n = strlen(pstr);
350 dprintf_commdlg(stddeb,"associated to '%s'\n", pstr);
351 SendDlgItemMessage(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr);
352 pstr += n + 1;
354 /* set default filter */
355 if (lpofn->nFilterIndex == 0 && lpofn->lpstrCustomFilter == (SEGPTR)NULL)
356 lpofn->nFilterIndex = 1;
357 SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL, lpofn->nFilterIndex - 1, 0);
358 strncpy(tmpstr, FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
359 PTR_SEG_TO_LIN(lpofn->lpstrFilter), lpofn->nFilterIndex - 1),511);
360 tmpstr[511]=0;
361 dprintf_commdlg(stddeb,"nFilterIndex = %ld // SetText of edt1 to '%s'\n",
362 lpofn->nFilterIndex, tmpstr);
363 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
364 /* get drive list */
365 *tmpstr = 0;
366 DlgDirListComboBox(hWnd, MAKE_SEGPTR(tmpstr), cmb2, 0, 0xC000);
367 /* read initial directory */
368 if (PTR_SEG_TO_LIN(lpofn->lpstrInitialDir) != NULL)
370 strncpy(tmpstr, PTR_SEG_TO_LIN(lpofn->lpstrInitialDir), 510);
371 tmpstr[510]=0;
372 if (strlen(tmpstr) > 0 && tmpstr[strlen(tmpstr)-1] != '\\'
373 && tmpstr[strlen(tmpstr)-1] != ':')
374 strcat(tmpstr,"\\");
376 else
377 *tmpstr = 0;
378 if (!FILEDLG_ScanDir(hWnd, tmpstr))
379 fprintf(stderr, "FileDlg: couldn't read initial directory %s!\n", tmpstr);
380 /* select current drive in combo 2 */
381 n = DRIVE_GetCurrentDrive();
382 SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, n, 0);
383 if (!(lpofn->Flags & OFN_SHOWHELP))
384 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
385 if (lpofn->Flags & OFN_HIDEREADONLY)
386 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
387 if (FILEDLG_HookCallChk(lpofn))
388 return (BOOL)CallWindowProc(lpofn->lpfnHook,
389 hWnd, WM_INITDIALOG, wParam,(LPARAM)MAKE_SEGPTR(lpofn));
390 else
391 return TRUE;
394 /***********************************************************************
395 * FILEDLG_WMCommand [internal]
397 static LRESULT FILEDLG_WMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
399 LONG lRet;
400 LPOPENFILENAME lpofn;
401 OPENFILENAME ofn2;
402 char tmpstr[512], tmpstr2[512];
403 LPSTR pstr, pstr2;
404 UINT control,notification;
406 /* Notifications are packaged differently in Win32 */
407 #ifdef WINELIB32
408 control = LOWORD(wParam);
409 notification = HIWORD(wParam);
410 #else
411 control = wParam;
412 notification = HIWORD(lParam);
413 #endif
415 lpofn = (LPOPENFILENAME)GetWindowLong(hWnd, DWL_USER);
416 switch (control)
418 case lst1: /* file list */
419 FILEDLG_StripEditControl(hWnd);
420 if (notification == LBN_DBLCLK)
421 goto almost_ok;
422 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
423 if (lRet == LB_ERR) return TRUE;
424 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet,
425 (LPARAM)MAKE_SEGPTR(tmpstr));
426 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
428 if (FILEDLG_HookCallChk(lpofn))
429 CallWindowProc (lpofn->lpfnHook, hWnd,
430 RegisterWindowMessage(MAKE_SEGPTR(LBSELCHSTRING)),
431 control, MAKELONG(lRet,CD_LBSELCHANGE));
432 /* FIXME: for OFN_ALLOWMULTISELECT we need CD_LBSELSUB, CD_SELADD, CD_LBSELNOITEMS */
433 return TRUE;
434 case lst2: /* directory list */
435 FILEDLG_StripEditControl(hWnd);
436 if (notification == LBN_DBLCLK)
438 lRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0);
439 if (lRet == LB_ERR) return TRUE;
440 SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, lRet,
441 (LPARAM)MAKE_SEGPTR(tmpstr));
442 if (tmpstr[0] == '[')
444 tmpstr[strlen(tmpstr) - 1] = 0;
445 strcpy(tmpstr,tmpstr+1);
447 strcat(tmpstr, "\\");
448 goto reset_scan;
450 return TRUE;
451 case cmb1: /* file type drop list */
452 if (notification == CBN_SELCHANGE)
454 *tmpstr = 0;
455 goto reset_scan;
457 return TRUE;
458 case cmb2: /* disk drop list */
459 FILEDLG_StripEditControl(hWnd);
460 lRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
461 if (lRet == LB_ERR) return 0;
462 SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, lRet, (LPARAM)MAKE_SEGPTR(tmpstr));
463 sprintf(tmpstr, "%c:", tmpstr[2]);
464 reset_scan:
465 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
466 if (lRet == LB_ERR)
467 return TRUE;
468 pstr = (LPSTR)SendDlgItemMessage(hWnd, cmb1, CB_GETITEMDATA, lRet, 0);
469 dprintf_commdlg(stddeb,"Selected filter : %s\n", pstr);
470 strncpy(tmpstr2, pstr, 511); tmpstr2[511]=0;
471 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
472 FILEDLG_ScanDir(hWnd, tmpstr);
473 return TRUE;
474 case chx1:
475 return TRUE;
476 case pshHelp:
477 return TRUE;
478 case IDOK:
479 almost_ok:
480 ofn2=*lpofn; /* for later restoring */
481 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 511, (LPARAM)MAKE_SEGPTR(tmpstr));
482 pstr = strrchr(tmpstr, '\\');
483 if (pstr == NULL)
484 pstr = strrchr(tmpstr, ':');
485 if (strchr(tmpstr,'*') != NULL || strchr(tmpstr,'?') != NULL)
487 /* edit control contains wildcards */
488 if (pstr != NULL)
490 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
491 *(pstr+1) = 0;
493 else
495 strcpy(tmpstr2, tmpstr);
496 *tmpstr=0;
498 dprintf_commdlg(stddeb,"commdlg: %s, %s\n", tmpstr, tmpstr2);
499 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
500 FILEDLG_ScanDir(hWnd, tmpstr);
501 return TRUE;
503 /* no wildcards, we might have a directory or a filename */
504 /* try appending a wildcard and reading the directory */
505 pstr2 = tmpstr + strlen(tmpstr);
506 if (pstr == NULL || *(pstr+1) != 0)
507 strcat(tmpstr, "\\");
508 lRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0);
509 if (lRet == LB_ERR) return TRUE;
510 lpofn->nFilterIndex = lRet + 1;
511 dprintf_commdlg(stddeb,"commdlg: lpofn->nFilterIndex=%ld\n", lpofn->nFilterIndex);
512 strncpy(tmpstr2,
513 FILEDLG_GetFileType(PTR_SEG_TO_LIN(lpofn->lpstrCustomFilter),
514 PTR_SEG_TO_LIN(lpofn->lpstrFilter),
515 lRet), 511);
516 tmpstr2[511]=0;
517 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
518 /* if ScanDir succeeds, we have changed the directory */
519 if (FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
520 /* if not, this must be a filename */
521 *pstr2 = 0;
522 if (pstr != NULL)
524 /* strip off the pathname */
525 *pstr = 0;
526 strncpy(tmpstr2, pstr+1, 511); tmpstr2[511]=0;
527 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr2));
528 /* Should we MessageBox() if this fails? */
529 if (!FILEDLG_ScanDir(hWnd, tmpstr)) return TRUE;
530 strcpy(tmpstr, tmpstr2);
532 else
533 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(tmpstr));
534 #if 0
535 ShowWindow(hWnd, SW_HIDE); /* this should not be necessary ?! (%%%) */
536 #endif
538 int drive = DRIVE_GetCurrentDrive();
539 tmpstr2[0] = 'A'+ drive;
540 tmpstr2[1] = ':';
541 tmpstr2[2] = '\\';
542 strncpy(tmpstr2 + 3, DRIVE_GetDosCwd(drive), 507); tmpstr2[510]=0;
543 if (strlen(tmpstr2) > 3)
544 strcat(tmpstr2, "\\");
545 strncat(tmpstr2, tmpstr, 511-strlen(tmpstr2)); tmpstr2[511]=0;
546 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFile), tmpstr2);
548 lpofn->nFileOffset = 0;
549 lpofn->nFileExtension = 0;
550 while(tmpstr2[lpofn->nFileExtension] != '.' && tmpstr2[lpofn->nFileExtension] != '\0')
551 lpofn->nFileExtension++;
552 if (lpofn->nFileExtension == '\0')
553 lpofn->nFileExtension = 0;
554 else
555 lpofn->nFileExtension++;
556 if (PTR_SEG_TO_LIN(lpofn->lpstrFileTitle) != NULL)
558 lRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0);
559 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, lRet,
560 (LPARAM)MAKE_SEGPTR(tmpstr));
561 dprintf_commdlg(stddeb,"strcpy'ing '%s'\n",tmpstr); fflush(stdout);
562 strcpy(PTR_SEG_TO_LIN(lpofn->lpstrFileTitle), tmpstr);
564 if (FILEDLG_HookCallChk(lpofn))
566 lRet= (BOOL)CallWindowProc (lpofn->lpfnHook,
567 hWnd, RegisterWindowMessage(MAKE_SEGPTR(FILEOKSTRING)),
568 0, (LPARAM)MAKE_SEGPTR(lpofn));
569 if (lRet)
571 *lpofn=ofn2; /* restore old state */
572 #if 0
573 ShowWindow(hWnd, SW_SHOW); /* only if above (%%%) SW_HIDE used */
574 #endif
575 break;
578 EndDialog(hWnd, TRUE);
579 return TRUE;
580 case IDCANCEL:
581 EndDialog(hWnd, FALSE);
582 return TRUE;
584 return FALSE;
588 /***********************************************************************
589 * FileOpenDlgProc (COMMDLG.6)
591 LRESULT FileOpenDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
593 LPOPENFILENAME lpofn = (LPOPENFILENAME)GetWindowLong(hWnd, DWL_USER);
595 if (wMsg!=WM_INITDIALOG)
596 if (FILEDLG_HookCallChk(lpofn))
598 LRESULT lRet=(BOOL)CallWindowProc(lpofn->lpfnHook, hWnd, wMsg, wParam, lParam);
599 if (lRet)
600 return lRet; /* else continue message processing */
602 switch (wMsg)
604 case WM_INITDIALOG:
605 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
606 case WM_MEASUREITEM:
607 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
608 case WM_DRAWITEM:
609 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
610 case WM_COMMAND:
611 return FILEDLG_WMCommand(hWnd, wParam, lParam);
612 #if 0
613 case WM_CTLCOLOR:
614 SetBkColor((HDC)wParam, 0x00C0C0C0);
615 switch (HIWORD(lParam))
617 case CTLCOLOR_BTN:
618 SetTextColor((HDC)wParam, 0x00000000);
619 return hGRAYBrush;
620 case CTLCOLOR_STATIC:
621 SetTextColor((HDC)wParam, 0x00000000);
622 return hGRAYBrush;
624 break;
625 #endif
627 return FALSE;
631 /***********************************************************************
632 * FileSaveDlgProc (COMMDLG.7)
634 LRESULT FileSaveDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
636 LPOPENFILENAME lpofn = (LPOPENFILENAME)GetWindowLong(hWnd, DWL_USER);
638 if (wMsg!=WM_INITDIALOG)
639 if (FILEDLG_HookCallChk(lpofn))
641 LRESULT lRet=(BOOL)CallWindowProc(lpofn->lpfnHook, hWnd, wMsg, wParam, lParam);
642 if (lRet)
643 return lRet; /* else continue message processing */
645 switch (wMsg) {
646 case WM_INITDIALOG:
647 return FILEDLG_WMInitDialog(hWnd, wParam, lParam);
649 case WM_MEASUREITEM:
650 return FILEDLG_WMMeasureItem(hWnd, wParam, lParam);
652 case WM_DRAWITEM:
653 return FILEDLG_WMDrawItem(hWnd, wParam, lParam);
655 case WM_COMMAND:
656 return FILEDLG_WMCommand(hWnd, wParam, lParam);
660 case WM_CTLCOLOR:
661 SetBkColor((HDC)wParam, 0x00C0C0C0);
662 switch (HIWORD(lParam))
664 case CTLCOLOR_BTN:
665 SetTextColor((HDC)wParam, 0x00000000);
666 return hGRAYBrush;
667 case CTLCOLOR_STATIC:
668 SetTextColor((HDC)wParam, 0x00000000);
669 return hGRAYBrush;
671 return FALSE;
674 return FALSE;
678 /***********************************************************************
679 * ChooseColor (COMMDLG.5)
681 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
683 HANDLE hInst, hDlgTmpl;
684 BOOL bRet;
686 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_CHOOSE_COLOR );
687 hInst = WIN_GetWindowInstance( lpChCol->hwndOwner );
688 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpChCol->hwndOwner,
689 GetWndProcEntry16("ColorDlgProc"),
690 (DWORD)lpChCol );
691 SYSRES_FreeResource( hDlgTmpl );
692 return bRet;
696 /***********************************************************************
697 * ColorDlgProc (COMMDLG.8)
699 LRESULT ColorDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
701 switch (wMsg)
703 case WM_INITDIALOG:
704 dprintf_commdlg(stddeb,"ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
705 ShowWindow(hWnd, SW_SHOWNORMAL);
706 return (TRUE);
707 case WM_COMMAND:
708 switch (wParam)
710 case IDOK:
711 EndDialog(hWnd, TRUE);
712 return(TRUE);
713 case IDCANCEL:
714 EndDialog(hWnd, FALSE);
715 return(TRUE);
717 return(FALSE);
719 return FALSE;
723 /***********************************************************************
724 * FindTextDlg (COMMDLG.11)
726 BOOL FindText(LPFINDREPLACE lpFind)
728 HANDLE hInst, hDlgTmpl;
729 BOOL bRet;
730 SEGPTR ptr;
733 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
734 * For now, only the standard dialog works.
737 * FIXME : We should do error checking on the lpFind structure here
738 * and make CommDlgExtendedError() return the error condition.
740 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_FIND_TEXT );
741 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
742 if (!(ptr = (SEGPTR)WIN16_GlobalLock( hDlgTmpl ))) return -1;
743 bRet = CreateDialogIndirectParam( hInst, ptr, lpFind->hwndOwner,
744 GetWndProcEntry16("FindTextDlgProc"),
745 (DWORD)lpFind );
746 GlobalUnlock( hDlgTmpl );
747 SYSRES_FreeResource( hDlgTmpl );
748 return bRet;
752 /***********************************************************************
753 * ReplaceTextDlg (COMMDLG.12)
755 BOOL ReplaceText(LPFINDREPLACE lpFind)
757 HANDLE hInst, hDlgTmpl;
758 BOOL bRet;
759 SEGPTR ptr;
762 * FIXME : Should respond to FR_ENABLETEMPLATE and FR_ENABLEHOOK here
763 * For now, only the standard dialog works.
766 * FIXME : We should do error checking on the lpFind structure here
767 * and make CommDlgExtendedError() return the error condition.
769 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_REPLACE_TEXT );
770 hInst = WIN_GetWindowInstance( lpFind->hwndOwner );
771 if (!(ptr = (SEGPTR)WIN16_GlobalLock( hDlgTmpl ))) return -1;
772 bRet = CreateDialogIndirectParam( hInst, ptr, lpFind->hwndOwner,
773 GetWndProcEntry16("ReplaceTextDlgProc"),
774 (DWORD)lpFind );
775 GlobalUnlock( hDlgTmpl );
776 SYSRES_FreeResource( hDlgTmpl );
777 return bRet;
781 /***********************************************************************
782 * FINDDLG_WMInitDialog [internal]
784 static LRESULT FINDDLG_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
786 LPFINDREPLACE lpfr;
788 SetWindowLong(hWnd, DWL_USER, lParam);
789 lpfr = (LPFINDREPLACE)lParam;
790 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
792 * FIXME : If the initial FindWhat string is empty, we should disable the
793 * FindNext (IDOK) button. Only after typing some text, the button should be
794 * enabled.
796 SetDlgItemText(hWnd, edt1, lpfr->lpstrFindWhat);
797 CheckRadioButton(hWnd, rad1, rad2, (lpfr->Flags & FR_DOWN) ? rad2 : rad1);
798 if (lpfr->Flags & (FR_HIDEUPDOWN | FR_NOUPDOWN)) {
799 EnableWindow(GetDlgItem(hWnd, rad1), FALSE);
800 EnableWindow(GetDlgItem(hWnd, rad2), FALSE);
802 if (lpfr->Flags & FR_HIDEUPDOWN) {
803 ShowWindow(GetDlgItem(hWnd, rad1), SW_HIDE);
804 ShowWindow(GetDlgItem(hWnd, rad2), SW_HIDE);
805 ShowWindow(GetDlgItem(hWnd, grp1), SW_HIDE);
807 CheckDlgButton(hWnd, chx1, (lpfr->Flags & FR_WHOLEWORD) ? 1 : 0);
808 if (lpfr->Flags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
809 EnableWindow(GetDlgItem(hWnd, chx1), FALSE);
810 if (lpfr->Flags & FR_HIDEWHOLEWORD)
811 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
812 CheckDlgButton(hWnd, chx2, (lpfr->Flags & FR_MATCHCASE) ? 1 : 0);
813 if (lpfr->Flags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
814 EnableWindow(GetDlgItem(hWnd, chx2), FALSE);
815 if (lpfr->Flags & FR_HIDEMATCHCASE)
816 ShowWindow(GetDlgItem(hWnd, chx2), SW_HIDE);
817 if (!(lpfr->Flags & FR_SHOWHELP)) {
818 EnableWindow(GetDlgItem(hWnd, pshHelp), FALSE);
819 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
821 ShowWindow(hWnd, SW_SHOWNORMAL);
822 return TRUE;
826 /***********************************************************************
827 * FINDDLG_WMCommand [internal]
829 static LRESULT FINDDLG_WMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
831 LPFINDREPLACE lpfr;
832 int uFindReplaceMessage = RegisterWindowMessage(MAKE_SEGPTR(FINDMSGSTRING));
833 int uHelpMessage = RegisterWindowMessage(MAKE_SEGPTR(HELPMSGSTRING));
835 lpfr = (LPFINDREPLACE)GetWindowLong(hWnd, DWL_USER);
836 switch (wParam) {
837 case IDOK:
838 GetDlgItemText(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
839 if (IsDlgButtonChecked(hWnd, rad2))
840 lpfr->Flags |= FR_DOWN;
841 else lpfr->Flags &= ~FR_DOWN;
842 if (IsDlgButtonChecked(hWnd, chx1))
843 lpfr->Flags |= FR_WHOLEWORD;
844 else lpfr->Flags &= ~FR_WHOLEWORD;
845 if (IsDlgButtonChecked(hWnd, chx2))
846 lpfr->Flags |= FR_MATCHCASE;
847 else lpfr->Flags &= ~FR_MATCHCASE;
848 lpfr->Flags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
849 lpfr->Flags |= FR_FINDNEXT;
850 SendMessage(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
851 return TRUE;
852 case IDCANCEL:
853 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
854 lpfr->Flags |= FR_DIALOGTERM;
855 SendMessage(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
856 DestroyWindow(hWnd);
857 return TRUE;
858 case pshHelp:
859 /* FIXME : should lpfr structure be passed as an argument ??? */
860 SendMessage(lpfr->hwndOwner, uHelpMessage, 0, 0);
861 return TRUE;
863 return FALSE;
867 /***********************************************************************
868 * FindTextDlgProc (COMMDLG.13)
870 LRESULT FindTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
872 switch (wMsg) {
873 case WM_INITDIALOG:
874 return FINDDLG_WMInitDialog(hWnd, wParam, lParam);
875 case WM_COMMAND:
876 return FINDDLG_WMCommand(hWnd, wParam, lParam);
878 return FALSE;
882 /***********************************************************************
883 * REPLACEDLG_WMInitDialog [internal]
885 static LRESULT REPLACEDLG_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam)
887 LPFINDREPLACE lpfr;
889 SetWindowLong(hWnd, DWL_USER, lParam);
890 lpfr = (LPFINDREPLACE)lParam;
891 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
893 * FIXME : If the initial FindWhat string is empty, we should disable the FinNext /
894 * Replace / ReplaceAll buttons. Only after typing some text, the buttons should be
895 * enabled.
897 SetDlgItemText(hWnd, edt1, lpfr->lpstrFindWhat);
898 SetDlgItemText(hWnd, edt2, lpfr->lpstrReplaceWith);
899 CheckDlgButton(hWnd, chx1, (lpfr->Flags & FR_WHOLEWORD) ? 1 : 0);
900 if (lpfr->Flags & (FR_HIDEWHOLEWORD | FR_NOWHOLEWORD))
901 EnableWindow(GetDlgItem(hWnd, chx1), FALSE);
902 if (lpfr->Flags & FR_HIDEWHOLEWORD)
903 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
904 CheckDlgButton(hWnd, chx2, (lpfr->Flags & FR_MATCHCASE) ? 1 : 0);
905 if (lpfr->Flags & (FR_HIDEMATCHCASE | FR_NOMATCHCASE))
906 EnableWindow(GetDlgItem(hWnd, chx2), FALSE);
907 if (lpfr->Flags & FR_HIDEMATCHCASE)
908 ShowWindow(GetDlgItem(hWnd, chx2), SW_HIDE);
909 if (!(lpfr->Flags & FR_SHOWHELP)) {
910 EnableWindow(GetDlgItem(hWnd, pshHelp), FALSE);
911 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
913 ShowWindow(hWnd, SW_SHOWNORMAL);
914 return TRUE;
918 /***********************************************************************
919 * REPLACEDLG_WMCommand [internal]
921 static LRESULT REPLACEDLG_WMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
923 LPFINDREPLACE lpfr;
924 int uFindReplaceMessage = RegisterWindowMessage(MAKE_SEGPTR(FINDMSGSTRING));
925 int uHelpMessage = RegisterWindowMessage(MAKE_SEGPTR(HELPMSGSTRING));
927 lpfr = (LPFINDREPLACE)GetWindowLong(hWnd, DWL_USER);
928 switch (wParam) {
929 case IDOK:
930 GetDlgItemText(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
931 GetDlgItemText(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
932 if (IsDlgButtonChecked(hWnd, chx1))
933 lpfr->Flags |= FR_WHOLEWORD;
934 else lpfr->Flags &= ~FR_WHOLEWORD;
935 if (IsDlgButtonChecked(hWnd, chx2))
936 lpfr->Flags |= FR_MATCHCASE;
937 else lpfr->Flags &= ~FR_MATCHCASE;
938 lpfr->Flags &= ~(FR_REPLACE | FR_REPLACEALL | FR_DIALOGTERM);
939 lpfr->Flags |= FR_FINDNEXT;
940 SendMessage(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
941 return TRUE;
942 case IDCANCEL:
943 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_REPLACEALL);
944 lpfr->Flags |= FR_DIALOGTERM;
945 SendMessage(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
946 DestroyWindow(hWnd);
947 return TRUE;
948 case psh1:
949 GetDlgItemText(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
950 GetDlgItemText(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
951 if (IsDlgButtonChecked(hWnd, chx1))
952 lpfr->Flags |= FR_WHOLEWORD;
953 else lpfr->Flags &= ~FR_WHOLEWORD;
954 if (IsDlgButtonChecked(hWnd, chx2))
955 lpfr->Flags |= FR_MATCHCASE;
956 else lpfr->Flags &= ~FR_MATCHCASE;
957 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACEALL | FR_DIALOGTERM);
958 lpfr->Flags |= FR_REPLACE;
959 SendMessage(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
960 return TRUE;
961 case psh2:
962 GetDlgItemText(hWnd, edt1, lpfr->lpstrFindWhat, lpfr->wFindWhatLen);
963 GetDlgItemText(hWnd, edt2, lpfr->lpstrReplaceWith, lpfr->wReplaceWithLen);
964 if (IsDlgButtonChecked(hWnd, chx1))
965 lpfr->Flags |= FR_WHOLEWORD;
966 else lpfr->Flags &= ~FR_WHOLEWORD;
967 if (IsDlgButtonChecked(hWnd, chx2))
968 lpfr->Flags |= FR_MATCHCASE;
969 else lpfr->Flags &= ~FR_MATCHCASE;
970 lpfr->Flags &= ~(FR_FINDNEXT | FR_REPLACE | FR_DIALOGTERM);
971 lpfr->Flags |= FR_REPLACEALL;
972 SendMessage(lpfr->hwndOwner, uFindReplaceMessage, 0, (LPARAM)MAKE_SEGPTR(lpfr));
973 return TRUE;
974 case pshHelp:
975 /* FIXME : should lpfr structure be passed as an argument ??? */
976 SendMessage(lpfr->hwndOwner, uHelpMessage, 0, 0);
977 return TRUE;
979 return FALSE;
983 /***********************************************************************
984 * ReplaceTextDlgProc (COMMDLG.14)
986 LRESULT ReplaceTextDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
988 switch (wMsg) {
989 case WM_INITDIALOG:
990 return REPLACEDLG_WMInitDialog(hWnd, wParam, lParam);
991 case WM_COMMAND:
992 return REPLACEDLG_WMCommand(hWnd, wParam, lParam);
994 return FALSE;
998 /***********************************************************************
999 * PrintDlg (COMMDLG.20)
1001 BOOL PrintDlg(LPPRINTDLG lpPrint)
1003 HANDLE hInst, hDlgTmpl;
1004 BOOL bRet;
1006 dprintf_commdlg(stddeb,"PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags );
1008 if (lpPrint->Flags & PD_RETURNDEFAULT)
1009 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
1010 return TRUE;
1012 if (lpPrint->Flags & PD_PRINTSETUP)
1013 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_PRINT_SETUP );
1014 else
1015 hDlgTmpl = SYSRES_LoadResource( SYSRES_DIALOG_PRINT );
1017 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
1018 bRet = DialogBoxIndirectParam( hInst, hDlgTmpl, lpPrint->hwndOwner,
1019 (lpPrint->Flags & PD_PRINTSETUP) ?
1020 GetWndProcEntry16("PrintSetupDlgProc") :
1021 GetWndProcEntry16("PrintDlgProc"),
1022 (DWORD)lpPrint );
1023 SYSRES_FreeResource( hDlgTmpl );
1024 return bRet;
1028 /***********************************************************************
1029 * PrintDlgProc (COMMDLG.21)
1031 LRESULT PrintDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
1033 switch (wMsg)
1035 case WM_INITDIALOG:
1036 dprintf_commdlg(stddeb,"PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1037 ShowWindow(hWnd, SW_SHOWNORMAL);
1038 return (TRUE);
1039 case WM_COMMAND:
1040 switch (wParam)
1042 case IDOK:
1043 EndDialog(hWnd, TRUE);
1044 return(TRUE);
1045 case IDCANCEL:
1046 EndDialog(hWnd, FALSE);
1047 return(TRUE);
1049 return(FALSE);
1051 return FALSE;
1055 /***********************************************************************
1056 * PrintSetupDlgProc (COMMDLG.22)
1058 LRESULT PrintSetupDlgProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
1060 switch (wMsg)
1062 case WM_INITDIALOG:
1063 dprintf_commdlg(stddeb,"PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1064 ShowWindow(hWnd, SW_SHOWNORMAL);
1065 return (TRUE);
1066 case WM_COMMAND:
1067 switch (wParam) {
1068 case IDOK:
1069 EndDialog(hWnd, TRUE);
1070 return(TRUE);
1071 case IDCANCEL:
1072 EndDialog(hWnd, FALSE);
1073 return(TRUE);
1075 return(FALSE);
1077 return FALSE;
1081 /***********************************************************************
1082 * CommDlgExtendedError (COMMDLG.26)
1084 DWORD CommDlgExtendedError(void)
1086 return CommDlgLastError;
1090 /***********************************************************************
1091 * GetFileTitle (COMMDLG.27)
1093 short GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
1095 int i, len;
1096 dprintf_commdlg(stddeb,"GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
1097 if (lpFile == NULL || lpTitle == NULL)
1098 return -1;
1099 len = strlen(lpFile);
1100 if (len == 0)
1101 return -1;
1102 if (strpbrk(lpFile, "*[]"))
1103 return -1;
1104 len--;
1105 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
1106 return -1;
1107 for (i = len; i >= 0; i--)
1108 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
1110 i++;
1111 break;
1113 dprintf_commdlg(stddeb,"\n---> '%s' ", &lpFile[i]);
1115 len = strlen(lpFile+i)+1;
1116 if (cbBuf < len)
1117 return len;
1119 strncpy(lpTitle, &lpFile[i], len);
1120 return 0;