Release 950109
[wine/multimedia.git] / misc / commdlg.c
blobabf119f63133f4d76c4b42cc93d1eb44fe9ada26
1 /*
2 * COMMDLG functions
4 * Copyright 1994 Martin Ayotte
5 static char Copyright[] = "Copyright Martin Ayotte, 1994";
6 */
8 /*
9 #define DEBUG_OPENDLG
10 #define DEBUG_OPENDLG_DRAW
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include "dialog.h"
17 #include "win.h"
18 #include "user.h"
19 #include "message.h"
20 #include "library.h"
21 #include "heap.h"
22 #include "commdlg.h"
23 #include "dlgs.h"
25 #define OPENFILEDLG2 11
26 #define SAVEFILEDLG2 12
28 static DWORD CommDlgLastError = 0;
30 static HBITMAP hFolder = 0;
31 static HBITMAP hFolder2 = 0;
32 static HBITMAP hFloppy = 0;
33 static HBITMAP hHDisk = 0;
34 static HBITMAP hCDRom = 0;
36 int DOS_GetDefaultDrive(void);
37 void DOS_SetDefaultDrive(int drive);
38 char *DOS_GetCurrentDir(int drive);
39 int DOS_ChangeDir(int drive, char *dirname);
41 BOOL FileDlg_Init(HWND hWnd, DWORD lParam);
42 BOOL OpenDlg_ScanFiles(HWND hWnd, WORD nDrive, LPSTR newPath, LPSTR fileSpec);
43 BOOL OpenDlg_ScanDir(HWND hWnd, WORD nDrive, LPSTR newPath, LPSTR fileSpec);
44 LPSTR OpenDlg_GetFileType(LPCSTR types, WORD index);
45 LPSTR OpenDlg_ExtractCurDir(LPSTR FullPath, short MaxLen);
46 BOOL FileOpenDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
47 BOOL FileSaveDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
48 BOOL ColorDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
49 BOOL PrintDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
50 BOOL PrintSetupDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
51 BOOL ReplaceTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
52 BOOL FindTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
54 /***********************************************************************
55 * GetOpenFileName [COMMDLG.1]
57 BOOL GetOpenFileName(LPOPENFILENAME lpofn)
59 HANDLE hDlgTmpl;
60 HANDLE hResInfo;
61 HINSTANCE hInst;
62 WND *wndPtr;
63 BOOL bRet;
64 printf("GetOpenFileName(%p); !\n", lpofn);
65 if (lpofn == NULL) return FALSE;
66 printf("GetOpenFileName // Flags=%08lX !\n", lpofn->Flags);
67 printf("GetOpenFileName // nMaxFile=%ld lpstrFile='%s' !\n",
68 lpofn->nMaxFile, lpofn->lpstrFile);
69 printf("GetOpenFileName // lpstrInitialDir='%s' !\n", lpofn->lpstrInitialDir);
70 printf("GetOpenFileName // lpstrFilter=%p !\n", lpofn->lpstrFilter);
71 printf("GetOpenFileName // nFilterIndex=%ld !\n", lpofn->nFilterIndex);
72 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
73 hDlgTmpl = lpofn->hInstance;
75 else {
76 if (lpofn->Flags & OFN_ENABLETEMPLATE) {
77 printf("GetOpenFileName // avant FindResource hInstance=%04X lpTemplateName='%s' !\n",
78 lpofn->hInstance, lpofn->lpTemplateName);
79 hInst = lpofn->hInstance;
80 hResInfo = FindResource(hInst,
81 (LPSTR)lpofn->lpTemplateName, RT_DIALOG);
83 else {
84 printf("GetOpenFileName // avant FindResource hSysRes=%04X !\n", hSysRes);
85 hInst = hSysRes;
86 hResInfo = FindResource(hInst, MAKEINTRESOURCE(OPENFILEDLG2), RT_DIALOG);
88 if (hResInfo == 0) {
89 CommDlgLastError = CDERR_FINDRESFAILURE;
90 return FALSE;
92 printf("GetOpenFileName // apres FindResource hResInfo=%04X!\n", hResInfo);
93 hDlgTmpl = LoadResource(hInst, hResInfo);
95 if (hDlgTmpl == 0) {
96 CommDlgLastError = CDERR_LOADRESFAILURE;
97 return FALSE;
99 printf("GetOpenFileName // apres LoadResource hDlgTmpl=%04X!\n", hDlgTmpl);
100 wndPtr = WIN_FindWndPtr(lpofn->hwndOwner);
101 bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
102 lpofn->hwndOwner, (WNDPROC)FileOpenDlgProc, (DWORD)lpofn);
104 /* strcpy(lpofn->lpstrFile, "SETUP.TXT"); */
105 /* strcpy(lpofn->lpstrFileTitle, "SETUP.TXT");*/
107 lpofn->nFileOffset = 0;
108 lpofn->nFileExtension = strlen(lpofn->lpstrFile) - 3;
109 bRet = TRUE;
111 printf("GetOpenFileName // return lpstrFile='%s' !\n", lpofn->lpstrFile);
112 return bRet;
116 /***********************************************************************
117 * GetSaveFileName [COMMDLG.2]
119 BOOL GetSaveFileName(LPOPENFILENAME lpofn)
121 HANDLE hDlgTmpl;
122 HANDLE hResInfo;
123 HINSTANCE hInst;
124 WND *wndPtr;
125 BOOL bRet;
126 printf("GetSaveFileName(%p); !\n", lpofn);
127 if (lpofn == NULL) return FALSE;
128 printf("GetSaveFileName // Flags=%08lX !\n", lpofn->Flags);
129 printf("GetSaveFileName // nMaxFile=%ld lpstrFile='%s' !\n",
130 lpofn->nMaxFile, lpofn->lpstrFile);
131 printf("GetSaveFileName // lpstrInitialDir='%s' !\n", lpofn->lpstrInitialDir);
132 printf("GetSaveFileName // lpstrFilter=%p !\n", lpofn->lpstrFilter);
133 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
134 hDlgTmpl = lpofn->hInstance;
136 else {
137 if (lpofn->Flags & OFN_ENABLETEMPLATE) {
138 printf("GetSaveFileName // avant FindResource lpTemplateName='%s' !\n",
139 lpofn->lpTemplateName);
140 hInst = lpofn->hInstance;
141 hResInfo = FindResource(hInst,
142 (LPSTR)lpofn->lpTemplateName, RT_DIALOG);
144 else {
145 printf("GetSaveFileName // avant FindResource !\n");
146 hInst = hSysRes;
147 hResInfo = FindResource(hInst, MAKEINTRESOURCE(SAVEFILEDLG2), RT_DIALOG);
149 if (hResInfo == 0) {
150 CommDlgLastError = CDERR_FINDRESFAILURE;
151 return FALSE;
153 hDlgTmpl = LoadResource(hInst, hResInfo);
155 if (hDlgTmpl == 0) {
156 CommDlgLastError = CDERR_LOADRESFAILURE;
157 return FALSE;
159 wndPtr = WIN_FindWndPtr(lpofn->hwndOwner);
160 bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
161 lpofn->hwndOwner, (WNDPROC)FileSaveDlgProc, (DWORD)lpofn);
162 printf("GetSaveFileName // return lpstrFile='%s' !\n", lpofn->lpstrFile);
163 return bRet;
167 /***********************************************************************
168 * ChooseColor [COMMDLG.5]
170 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
172 HANDLE hDlgTmpl;
173 HANDLE hResInfo;
174 WND *wndPtr;
175 BOOL bRet;
176 hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(COLORDLG), RT_DIALOG);
177 hDlgTmpl = LoadResource(hSysRes, hResInfo);
178 wndPtr = WIN_FindWndPtr(lpChCol->hwndOwner);
179 bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
180 lpChCol->hwndOwner, (WNDPROC)ColorDlgProc, (DWORD)lpChCol);
181 return bRet;
185 /***********************************************************************
186 * FileOpenDlgProc [COMMDLG.6]
188 BOOL FileOpenDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
190 int n;
191 LPSTR ptr;
192 LPSTR fspec;
193 char str[512];
194 char C2[128];
195 WORD wRet;
196 HBRUSH hBrush;
197 HDC hMemDC;
198 HBITMAP hBitmap;
199 BITMAP bm;
200 LPMEASUREITEMSTRUCT lpmeasure;
201 LPDRAWITEMSTRUCT lpdis;
202 static int nDrive;
203 static char CurPath[512];
204 static LPOPENFILENAME lpofn;
206 switch (wMsg) {
207 case WM_INITDIALOG:
208 #ifdef DEBUG_OPENDLG
209 printf("FileOpenDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
210 #endif
211 printf("FileOpenDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
212 if (!FileDlg_Init(hWnd, lParam)) return TRUE;
213 SendDlgItemMessage(hWnd, cmb1, CB_RESETCONTENT, 0, 0L);
214 lpofn = (LPOPENFILENAME)lParam;
215 ptr = (LPSTR)lpofn->lpstrFilter;
216 strcpy(CurPath, lpofn->lpstrInitialDir);
217 #ifdef DEBUG_OPENDLG
218 printf("FileOpenDlgProc // lpstrInitialDir='%s' !\n", CurPath);
219 #endif
220 while((n = strlen(ptr)) != 0) {
221 #ifdef DEBUG_OPENDLG
222 printf("FileOpenDlgProc // file type '%s' !\n", ptr);
223 #endif
224 SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, (DWORD)ptr);
225 ptr += ++n;
226 #ifdef DEBUG_OPENDLG
227 printf("FileOpenDlgProc // file spec '%s' !\n", ptr);
228 #endif
229 n = strlen(ptr);
230 ptr += ++n;
232 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (DWORD)str);
233 SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL,
234 lpofn->nFilterIndex - 1, 0L);
235 DlgDirListComboBox(hWnd, "", cmb2, 0, 0xC000);
236 nDrive = 2; /* Drive 'C:' */
237 SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, nDrive, 0L);
238 sprintf(str, "%c:\\%s", nDrive + 'A', DOS_GetCurrentDir(nDrive));
239 fspec = OpenDlg_GetFileType(lpofn->lpstrFilter,
240 lpofn->nFilterIndex);
241 #ifdef DEBUG_OPENDLG
242 printf("FileOpenDlgProc // WM_INITDIALOG fspec #%d = '%s' !\n",
243 lpofn->nFilterIndex, fspec);
244 #endif
245 if (!OpenDlg_ScanDir(hWnd, nDrive, str, fspec)) {
246 printf("OpenDlg_ScanDir // ChangeDir Error !\n");
248 else {
249 strcpy(CurPath, str);
251 ShowWindow(hWnd, SW_SHOWNORMAL);
252 return TRUE;
254 case WM_SHOWWINDOW:
255 if (wParam == 0) break;
256 if (!(lpofn->Flags & OFN_SHOWHELP)) {
257 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
259 if (lpofn->Flags & OFN_HIDEREADONLY) {
260 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
262 return TRUE;
264 case WM_MEASUREITEM:
265 GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
266 lpmeasure = (LPMEASUREITEMSTRUCT)lParam;
267 lpmeasure->itemHeight = bm.bmHeight;
268 #ifdef DEBUG_OPENDLG_DRAW
269 printf("FileOpenDlgProc WM_MEASUREITEM Height=%d !\n", bm.bmHeight);
270 #endif
271 return TRUE;
273 case WM_DRAWITEM:
274 #ifdef DEBUG_OPENDLG_DRAW
275 printf("FileOpenDlgProc // WM_DRAWITEM w=%04X l=%08X\n", wParam, lParam);
276 #endif
277 if (lParam == 0L) break;
278 lpdis = (LPDRAWITEMSTRUCT)lParam;
279 #ifdef DEBUG_OPENDLG_DRAW
280 printf("FileOpenDlgProc // WM_DRAWITEM CtlType=%04X CtlID=%04X \n",
281 lpdis->CtlType, lpdis->CtlID);
282 #endif
283 if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst1)) {
284 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
285 SelectObject(lpdis->hDC, hBrush);
286 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
287 ptr = (LPSTR) lpdis->itemData;
288 if (ptr == NULL) break;
289 TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
290 ptr, strlen(ptr));
292 if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst2)) {
293 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
294 SelectObject(lpdis->hDC, hBrush);
295 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
296 ptr = (LPSTR) lpdis->itemData;
297 if (ptr == NULL) break;
298 if (strcmp(ptr, "[.]") == 0) {
299 hBitmap = hFolder2;
300 /* ptr = OpenDlg_ExtractCurDir(CurPath, -1); */
301 ptr = CurPath;
303 else
304 hBitmap = hFolder;
305 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
306 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
307 lpdis->rcItem.top, ptr, strlen(ptr));
308 hMemDC = CreateCompatibleDC(lpdis->hDC);
309 SelectObject(hMemDC, hBitmap);
310 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
311 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
312 DeleteDC(hMemDC);
314 if ((lpdis->CtlType == ODT_COMBOBOX) && (lpdis->CtlID == cmb2)) {
315 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
316 SelectObject(lpdis->hDC, hBrush);
317 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
318 ptr = (LPSTR) lpdis->itemData;
319 if (ptr == NULL) break;
320 switch(ptr[2]) {
321 case 'a':
322 case 'b':
323 hBitmap = hFloppy;
324 break;
325 default:
326 hBitmap = hHDisk;
328 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
329 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
330 lpdis->rcItem.top, ptr, strlen(ptr));
331 hMemDC = CreateCompatibleDC(lpdis->hDC);
332 SelectObject(hMemDC, hBitmap);
333 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
334 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
335 DeleteDC(hMemDC);
337 if (lpdis->itemState != 0) {
338 InvertRect(lpdis->hDC, &lpdis->rcItem);
340 break;
342 case WM_COMMAND:
343 switch (wParam) {
344 case lst1:
345 if (HIWORD(lParam) == LBN_DBLCLK ||
346 HIWORD(lParam) == LBN_SELCHANGE) {
347 #ifdef DEBUG_OPENDLG
348 printf("FileOpenDlgProc // LBN_SELCHANGE on lst1 !\n");
349 #endif
350 wRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
351 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, wRet, (DWORD)C2);
353 if (HIWORD(lParam) == LBN_DBLCLK) {
354 #ifdef DEBUG_OPENDLG
355 printf("FileOpenDlgProc // LBN_DBLCLK on lst1 !\n");
356 #endif
357 return SendMessage(hWnd, WM_COMMAND, IDOK, 0L);
359 break;
360 case lst2:
361 if (HIWORD(lParam) == LBN_DBLCLK) {
362 #ifdef DEBUG_OPENDLG
363 printf("FileOpenDlgProc // LBN_DBLCLK on lst2 !\n");
364 #endif
365 wRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
366 if (wRet == (WORD)LB_ERR) return 0;
367 fspec = OpenDlg_GetFileType(lpofn->lpstrFilter, wRet + 1);
368 C2[0] = '\0';
369 wRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0L);
370 if (wRet == (WORD)LB_ERR) return 0;
371 SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, wRet, (DWORD)C2);
372 if (C2[0] == '[') {
373 C2[strlen(C2) - 1] = '\0';
374 sprintf(str, "%s\\%s", CurPath, &C2[1]);
375 if (!OpenDlg_ScanDir(hWnd, nDrive, str, fspec)) {
376 printf("OpenDlg_ScanDir // ChangeDir Error !\n");
378 else {
379 strcpy(CurPath, str);
383 break;
384 case cmb1:
385 if (HIWORD(lParam) == CBN_SELCHANGE) {
386 wRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
387 if (wRet == (WORD)LB_ERR) return 0;
388 fspec = OpenDlg_GetFileType(lpofn->lpstrFilter, wRet + 1);
389 printf("FileOpenDlgProc // new fspec #%d = '%s' !\n", wRet, fspec);
390 if (!OpenDlg_ScanFiles(hWnd, nDrive, CurPath, fspec)) {
391 printf("OpenDlg_ScanFiles // Change FileType Error !\n");
394 break;
395 case cmb2:
396 #ifdef DEBUG_OPENDLG
397 printf("FileOpenDlgProc // combo #2 changed !\n");
398 #endif
399 wRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
400 if (wRet == (WORD)LB_ERR) return 0;
401 fspec = OpenDlg_GetFileType(lpofn->lpstrFilter, wRet + 1);
402 wRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
403 if (wRet == (WORD)LB_ERR) return 0;
404 printf("FileOpenDlgProc // combo #2 CB_GETCURSEL=%d !\n", wRet);
405 SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, wRet, (DWORD)C2);
406 nDrive = C2[2] - 'a';
407 #ifdef DEBUG_OPENDLG
408 printf("FileOpenDlgProc // new drive selected=%d !\n", nDrive);
409 #endif
410 sprintf(str, "%c:\\%s", nDrive + 'A', DOS_GetCurrentDir(nDrive));
411 #ifdef DEBUG_OPENDLG
412 printf("FileOpenDlgProc // new drive , curPath='%s' !\n", str);
413 #endif
414 if (!OpenDlg_ScanDir(hWnd, nDrive, str, fspec)) {
415 printf("OpenDlg_ScanDir // ChangeDir Error !\n");
417 else {
418 strcpy(CurPath, str);
420 break;
421 case chx1:
422 #ifdef DEBUG_OPENDLG
423 printf("FileOpenDlgProc // read-only toggled !\n");
424 #endif
425 break;
426 case pshHelp:
427 #ifdef DEBUG_OPENDLG
428 printf("FileOpenDlgProc // pshHelp pressed !\n");
429 #endif
430 break;
431 case IDOK:
432 ShowWindow(hWnd, SW_HIDE);
433 SendDlgItemMessage(hWnd, edt1, WM_GETTEXT, 0, (DWORD)str);
434 wRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
435 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, wRet, (DWORD)str);
436 printf("FileOpenDlgProc // IDOK str='%s'\n", str);
437 strcpy(lpofn->lpstrFile, str);
438 lpofn->nFileOffset = 0;
439 lpofn->nFileExtension = strlen(lpofn->lpstrFile) - 3;
440 if (lpofn->lpstrFileTitle != NULL) {
441 wRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
442 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, wRet, (DWORD)str);
443 strcpy(lpofn->lpstrFileTitle, str);
445 EndDialog(hWnd, TRUE);
446 return(TRUE);
447 case IDCANCEL:
448 EndDialog(hWnd, FALSE);
449 return(TRUE);
451 return(FALSE);
456 case WM_CTLCOLOR:
457 SetBkColor((HDC)wParam, 0x00C0C0C0);
458 switch (HIWORD(lParam))
460 case CTLCOLOR_BTN:
461 SetTextColor((HDC)wParam, 0x00000000);
462 return(hGRAYBrush);
463 case CTLCOLOR_STATIC:
464 SetTextColor((HDC)wParam, 0x00000000);
465 return(hGRAYBrush);
467 return(FALSE);
470 return FALSE;
474 /***********************************************************************
475 * FileDlg_Init [internal]
477 BOOL FileDlg_Init(HWND hWnd, DWORD lParam)
479 LPOPENFILENAME lpofn;
480 lpofn = (LPOPENFILENAME)lParam;
481 if (lpofn == NULL) {
482 fprintf(stderr, "FileDlg_Init // Bad LPOPENFILENAME pointer !");
483 return FALSE;
485 if (hFolder == (HBITMAP)NULL)
486 hFolder = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_FOLDER));
487 if (hFolder2 == (HBITMAP)NULL)
488 hFolder2 = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_FOLDER2));
489 if (hFloppy == (HBITMAP)NULL)
490 hFloppy = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_FLOPPY));
491 if (hHDisk == (HBITMAP)NULL)
492 hHDisk = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_HDISK));
493 if (hCDRom == (HBITMAP)NULL)
494 hCDRom = LoadBitmap((HINSTANCE)NULL, MAKEINTRESOURCE(OBM_CDROM));
495 if (hFolder == 0 || hFolder2 == 0 || hFloppy == 0 ||
496 hHDisk == 0 || hCDRom == 0)
497 fprintf(stderr, "FileDlg_Init // Error loading bitmaps !");
498 return TRUE;
502 /***********************************************************************
503 * OpenDlg_ScanFiles [internal]
505 BOOL OpenDlg_ScanFiles(HWND hWnd, WORD nDrive, LPSTR newPath, LPSTR fileSpec)
507 int OldDrive;
508 char OldPath[512];
509 char str[512];
510 OldDrive = DOS_GetDefaultDrive();
511 DOS_SetDefaultDrive(nDrive) ;
512 strcpy(OldPath, DOS_GetCurrentDir(nDrive));
513 #ifdef DEBUG_OPENDLG
514 printf("OpenDlg_ScanFiles // OldDrive=%d OldPath='%s'\n", OldDrive, OldPath);
515 printf("OpenDlg_ScanFiles // wanted newPath='%s'\n", newPath);
516 #endif
517 if (newPath[1] == ':')
518 DOS_ChangeDir(nDrive, &newPath[2]);
519 else
520 DOS_ChangeDir(nDrive, newPath);
521 sprintf(newPath, "%c:\\%s", nDrive + 'A', DOS_GetCurrentDir(nDrive));
522 #ifdef DEBUG_OPENDLG
523 printf("OpenDlg_ScanFiles // actual newPath='%s'\n", newPath);
524 #endif
525 if (strlen(newPath) == 3) newPath[2] = '\0';
526 sprintf(str, "%s\\%s", newPath, fileSpec);
527 DlgDirList(hWnd, str, lst1, 0, 0x0000);
528 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (DWORD)str);
529 DOS_ChangeDir(nDrive, OldPath);
530 DOS_SetDefaultDrive(OldDrive);
531 return TRUE;
536 /***********************************************************************
537 * OpenDlg_ScanDir [internal]
539 BOOL OpenDlg_ScanDir(HWND hWnd, WORD nDrive, LPSTR newPath, LPSTR fileSpec)
541 int OldDrive;
542 char OldPath[512];
543 char str[512];
544 OldDrive = DOS_GetDefaultDrive();
545 DOS_SetDefaultDrive(nDrive) ;
546 strcpy(OldPath, DOS_GetCurrentDir(nDrive));
547 #ifdef DEBUG_OPENDLG
548 printf("OpenDlg_ScanDir // OldDrive=%d OldPath='%s'\n", OldDrive, OldPath);
549 printf("OpenDlg_ScanDir // wanted newPath='%s'\n", newPath);
550 #endif
551 if (newPath[1] == ':')
552 DOS_ChangeDir(nDrive, &newPath[2]);
553 else
554 DOS_ChangeDir(nDrive, newPath);
555 sprintf(newPath, "%c:\\%s", nDrive + 'A', DOS_GetCurrentDir(nDrive));
556 #ifdef DEBUG_OPENDLG
557 printf("OpenDlg_ScanDir // actual newPath='%s'\n", newPath);
558 #endif
559 if (strlen(newPath) == 3) newPath[2] = '\0';
560 sprintf(str, "%s\\%s", newPath, fileSpec);
561 DlgDirList(hWnd, str, lst1, 0, 0x0000);
562 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (DWORD)str);
563 sprintf(str, "%s\\*.*", newPath);
564 DlgDirList(hWnd, str, lst2, 0, 0x8010);
565 if (strlen(newPath) == 2) strcat(newPath, "\\");
566 SendDlgItemMessage(hWnd, stc1, WM_SETTEXT, 0, (DWORD)newPath);
567 DOS_ChangeDir(nDrive, OldPath);
568 DOS_SetDefaultDrive(OldDrive);
569 return TRUE;
574 /***********************************************************************
575 * OpenDlg_GetFileType [internal]
577 LPSTR OpenDlg_GetFileType(LPCSTR types, WORD index)
579 int n;
580 int i = 1;
581 LPSTR ptr = (LPSTR) types;
582 if (ptr == NULL) return NULL;
583 while((n = strlen(ptr)) != 0) {
584 #ifdef DEBUG_OPENDLG
585 printf("OpenDlg_GetFileType // file type '%s' !\n", ptr);
586 #endif
587 ptr += ++n;
588 #ifdef DEBUG_OPENDLG
589 printf("OpenDlg_GetFileType // file spec '%s' !\n", ptr);
590 #endif
591 if (i++ == index) return ptr;
592 n = strlen(ptr);
593 ptr += ++n;
595 return NULL;
599 /***********************************************************************
600 * OpenDlg_ExtractCurDir [internal]
602 LPSTR OpenDlg_ExtractCurDir(LPSTR FullPath, short MaxLen)
604 LPSTR ptr;
605 if (MaxLen < 0) MaxLen = strlen(FullPath);
606 ptr = FullPath + MaxLen - 1;
607 if (*ptr == '\\') return NULL;
608 while (ptr > FullPath) {
609 if (*ptr == '\\') return (ptr + 1);
610 ptr--;
612 return NULL;
616 /***********************************************************************
617 * FileSaveDlgProc [COMMDLG.7]
619 BOOL FileSaveDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
621 int n;
622 LPSTR ptr;
623 LPSTR fspec;
624 char str[512];
625 char C2[128];
626 WORD wRet;
627 HBRUSH hBrush;
628 HDC hMemDC;
629 HBITMAP hBitmap;
630 BITMAP bm;
631 LPMEASUREITEMSTRUCT lpmeasure;
632 LPDRAWITEMSTRUCT lpdis;
633 static int nDrive;
634 static char CurPath[512];
635 static LPOPENFILENAME lpofn;
637 switch (wMsg) {
638 case WM_INITDIALOG:
639 #ifdef DEBUG_OPENDLG
640 printf("FileSaveDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
641 #endif
642 if (!FileDlg_Init(hWnd, lParam)) return TRUE;
643 SendDlgItemMessage(hWnd, cmb1, CB_RESETCONTENT, 0, 0L);
644 lpofn = (LPOPENFILENAME)lParam;
645 ptr = (LPSTR)lpofn->lpstrFilter;
646 strcpy(CurPath, lpofn->lpstrInitialDir);
647 while((n = strlen(ptr)) != 0) {
648 #ifdef DEBUG_OPENDLG
649 printf("FileSaveDlgProc // file type '%s' !\n", ptr);
650 #endif
651 SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, (DWORD)ptr);
652 ptr += ++n;
653 #ifdef DEBUG_OPENDLG
654 printf("FileSaveDlgProc // file spec '%s' !\n", ptr);
655 #endif
656 n = strlen(ptr);
657 ptr += ++n;
659 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (DWORD)str);
660 SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL,
661 lpofn->nFilterIndex - 1, 0L);
662 DlgDirListComboBox(hWnd, "", cmb2, 0, 0xC000);
663 nDrive = 2; /* Drive 'C:' */
664 SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, nDrive, 0L);
665 sprintf(str, "%c:\\%s", nDrive + 'A', DOS_GetCurrentDir(nDrive));
666 fspec = OpenDlg_GetFileType(lpofn->lpstrFilter,
667 lpofn->nFilterIndex);
668 #ifdef DEBUG_OPENDLG
669 printf("FileSaveDlgProc // WM_INITDIALOG fspec #%d = '%s' !\n",
670 lpofn->nFilterIndex, fspec);
671 #endif
672 if (!OpenDlg_ScanDir(hWnd, nDrive, str, fspec)) {
673 printf("OpenDlg_ScanDir // ChangeDir Error !\n");
675 else {
676 strcpy(CurPath, str);
678 ShowWindow(hWnd, SW_SHOWNORMAL);
679 return (TRUE);
681 case WM_SHOWWINDOW:
682 if (wParam == 0) break;
683 if (!(lpofn->Flags & OFN_SHOWHELP)) {
684 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
686 if (lpofn->Flags & OFN_HIDEREADONLY) {
687 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
689 return TRUE;
691 case WM_MEASUREITEM:
692 GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
693 lpmeasure = (LPMEASUREITEMSTRUCT)lParam;
694 lpmeasure->itemHeight = bm.bmHeight;
695 #ifdef DEBUG_OPENDLG_DRAW
696 printf("FileSaveDlgProc WM_MEASUREITEM Height=%d !\n", bm.bmHeight);
697 #endif
698 return TRUE;
700 case WM_DRAWITEM:
701 #ifdef DEBUG_OPENDLG_DRAW
702 printf("FileSaveDlgProc // WM_DRAWITEM w=%04X l=%08X\n", wParam, lParam);
703 #endif
704 if (lParam == 0L) break;
705 lpdis = (LPDRAWITEMSTRUCT)lParam;
706 #ifdef DEBUG_OPENDLG_DRAW
707 printf("FileSaveDlgProc // WM_DRAWITEM lpdis->CtlID=%04X\n", lpdis->CtlID);
708 #endif
709 if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst1)) {
710 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
711 SelectObject(lpdis->hDC, hBrush);
712 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
713 ptr = (LPSTR) lpdis->itemData;
714 if (ptr == NULL) break;
715 TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
716 ptr, strlen(ptr));
718 if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst2)) {
719 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
720 SelectObject(lpdis->hDC, hBrush);
721 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
722 ptr = (LPSTR) lpdis->itemData;
723 if (ptr == NULL) break;
724 if (strcmp(ptr, "[.]") == 0) {
725 hBitmap = hFolder2;
726 ptr = CurPath;
728 else
729 hBitmap = hFolder;
730 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
731 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
732 lpdis->rcItem.top, ptr, strlen(ptr));
733 hMemDC = CreateCompatibleDC(lpdis->hDC);
734 SelectObject(hMemDC, hBitmap);
735 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
736 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
737 DeleteDC(hMemDC);
739 if ((lpdis->CtlType == ODT_COMBOBOX) && (lpdis->CtlID == cmb2)) {
740 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
741 SelectObject(lpdis->hDC, hBrush);
742 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
743 ptr = (LPSTR) lpdis->itemData;
744 if (ptr == NULL) break;
745 switch(ptr[2]) {
746 case 'a':
747 case 'b':
748 hBitmap = hFloppy;
749 break;
750 default:
751 hBitmap = hHDisk;
753 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
754 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
755 lpdis->rcItem.top, ptr, strlen(ptr));
756 hMemDC = CreateCompatibleDC(lpdis->hDC);
757 SelectObject(hMemDC, hBitmap);
758 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
759 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
760 DeleteDC(hMemDC);
762 break;
764 case WM_COMMAND:
765 switch (wParam) {
766 case lst1:
767 if (HIWORD(lParam) == LBN_DBLCLK ||
768 HIWORD(lParam) == LBN_SELCHANGE) {
769 #ifdef DEBUG_OPENDLG
770 printf("FileSaveDlgProc // LBN_SELCHANGE on lst1 !\n");
771 #endif
772 wRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
773 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, wRet, (DWORD)C2);
775 if (HIWORD(lParam) == LBN_DBLCLK) {
776 #ifdef DEBUG_OPENDLG
777 printf("FileSaveDlgProc // LBN_DBLCLK on lst1 !\n");
778 #endif
779 return SendMessage(hWnd, WM_COMMAND, IDOK, 0L);
781 break;
782 case lst2:
783 if (HIWORD(lParam) == LBN_DBLCLK) {
784 #ifdef DEBUG_OPENDLG
785 printf("FileSaveDlgProc // LBN_DBLCLK on lst2 !\n");
786 #endif
787 wRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
788 fspec = OpenDlg_GetFileType(lpofn->lpstrFilter, wRet + 1);
789 C2[0] = '\0';
790 wRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0L);
791 SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, wRet, (DWORD)C2);
792 if (C2[0] == '[') {
793 C2[strlen(C2) - 1] = '\0';
794 sprintf(str, "%s\\%s", CurPath, &C2[1]);
795 if (!OpenDlg_ScanDir(hWnd, nDrive, str, fspec)) {
796 printf("FileSaveDlgProc // ChangeDir Error !\n");
798 else {
799 strcpy(CurPath, str);
803 break;
804 case cmb1:
805 if (HIWORD(lParam) == CBN_SELCHANGE) {
806 wRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
807 fspec = OpenDlg_GetFileType(lpofn->lpstrFilter, wRet + 1);
808 printf("FileSaveDlgProc // new fspec #%d = '%s' !\n", wRet, fspec);
809 if (!OpenDlg_ScanFiles(hWnd, nDrive, CurPath, fspec)) {
810 printf("OpenDlg_ScanFile // Change FileType Error !\n");
813 break;
814 case cmb2:
815 #ifdef DEBUG_OPENDLG
816 printf("FileSaveDlgProc // combo #2 changed !\n");
817 #endif
818 wRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
819 if (wRet == (WORD)LB_ERR) return 0;
820 fspec = OpenDlg_GetFileType(lpofn->lpstrFilter, wRet + 1);
821 wRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
822 if (wRet == (WORD)LB_ERR) return 0;
823 printf("FileSaveDlgProc // combo #2 CB_GETCURSEL=%d !\n", wRet);
824 SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, wRet, (DWORD)C2);
825 nDrive = C2[2] - 'a';
826 #ifdef DEBUG_OPENDLG
827 printf("FileSaveDlgProc // new drive selected=%d !\n", nDrive);
828 #endif
829 sprintf(str, "%c:\\%s", nDrive + 'A', DOS_GetCurrentDir(nDrive));
830 #ifdef DEBUG_OPENDLG
831 printf("FileSaveDlgProc // new drive , curPath='%s' !\n", str);
832 #endif
833 if (!OpenDlg_ScanDir(hWnd, nDrive, str, fspec)) {
834 printf("FileSaveDlgProc // Change Drive Error !\n");
836 else {
837 strcpy(CurPath, str);
839 break;
840 case chx1:
841 #ifdef DEBUG_OPENDLG
842 printf("FileSaveDlgProc // read-only toggled !\n");
843 #endif
844 break;
845 case pshHelp:
846 #ifdef DEBUG_OPENDLG
847 printf("FileSaveDlgProc // pshHelp pressed !\n");
848 #endif
849 break;
850 case IDOK:
851 strcpy(lpofn->lpstrFile, "titi.txt");
852 if (lpofn->lpstrFileTitle != NULL) {
853 strcpy(lpofn->lpstrFileTitle, "titi.txt");
855 EndDialog(hWnd, TRUE);
856 return(TRUE);
857 case IDCANCEL:
858 EndDialog(hWnd, FALSE);
859 return(TRUE);
861 return(FALSE);
863 return FALSE;
867 /***********************************************************************
868 * ColorDlgProc [COMMDLG.8]
870 BOOL ColorDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
872 switch (wMsg) {
873 case WM_INITDIALOG:
874 printf("ColorDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
875 ShowWindow(hWnd, SW_SHOWNORMAL);
876 return (TRUE);
878 case WM_COMMAND:
879 switch (wParam) {
880 case IDOK:
881 EndDialog(hWnd, TRUE);
882 return(TRUE);
883 case IDCANCEL:
884 EndDialog(hWnd, FALSE);
885 return(TRUE);
887 return(FALSE);
889 return FALSE;
893 /***********************************************************************
894 * FindTextDlg [COMMDLG.11]
896 BOOL FindText(LPFINDREPLACE lpFind)
898 HANDLE hDlgTmpl;
899 HANDLE hResInfo;
900 WND *wndPtr;
901 BOOL bRet;
902 hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(FINDDLG), RT_DIALOG);
903 if (hResInfo == 0) {
904 CommDlgLastError = CDERR_FINDRESFAILURE;
905 return FALSE;
907 hDlgTmpl = LoadResource(hSysRes, hResInfo);
908 if (hDlgTmpl == 0) {
909 CommDlgLastError = CDERR_LOADRESFAILURE;
910 return FALSE;
912 wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
913 bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
914 lpFind->hwndOwner, (WNDPROC)FindTextDlgProc, (DWORD)lpFind);
915 return bRet;
919 /***********************************************************************
920 * ReplaceTextDlg [COMMDLG.12]
922 BOOL ReplaceText(LPFINDREPLACE lpFind)
924 HANDLE hDlgTmpl;
925 HANDLE hResInfo;
926 WND *wndPtr;
927 BOOL bRet;
928 hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(REPLACEDLG), RT_DIALOG);
929 if (hResInfo == 0) {
930 CommDlgLastError = CDERR_FINDRESFAILURE;
931 return FALSE;
933 hDlgTmpl = LoadResource(hSysRes, hResInfo);
934 if (hDlgTmpl == 0) {
935 CommDlgLastError = CDERR_LOADRESFAILURE;
936 return FALSE;
938 wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
939 bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
940 lpFind->hwndOwner, (WNDPROC)ReplaceTextDlgProc, (DWORD)lpFind);
941 return bRet;
945 /***********************************************************************
946 * FindTextDlgProc [COMMDLG.13]
948 BOOL FindTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
950 switch (wMsg) {
951 case WM_INITDIALOG:
952 printf("FindTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
953 ShowWindow(hWnd, SW_SHOWNORMAL);
954 return (TRUE);
956 case WM_COMMAND:
957 switch (wParam) {
958 case IDOK:
959 EndDialog(hWnd, TRUE);
960 return(TRUE);
961 case IDCANCEL:
962 EndDialog(hWnd, FALSE);
963 return(TRUE);
965 return(FALSE);
967 return FALSE;
971 /***********************************************************************
972 * ReplaceTextDlgProc [COMMDLG.14]
974 BOOL ReplaceTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
976 switch (wMsg) {
977 case WM_INITDIALOG:
978 printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
979 ShowWindow(hWnd, SW_SHOWNORMAL);
980 return (TRUE);
982 case WM_COMMAND:
983 switch (wParam) {
984 case IDOK:
985 EndDialog(hWnd, TRUE);
986 return(TRUE);
987 case IDCANCEL:
988 EndDialog(hWnd, FALSE);
989 return(TRUE);
991 return(FALSE);
993 return FALSE;
997 /***********************************************************************
998 * PrintDlg [COMMDLG.20]
1000 BOOL PrintDlg(LPPRINTDLG lpPrint)
1002 HANDLE hDlgTmpl;
1003 HANDLE hResInfo;
1004 WND *wndPtr;
1005 BOOL bRet;
1006 printf("PrintDlg(%p) // Flags=%08lX\n", lpPrint, lpPrint->Flags);
1007 if (lpPrint->Flags & PD_PRINTSETUP)
1008 hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(PRINTSETUPDLG), RT_DIALOG);
1009 else
1010 hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(PRINTDLG), RT_DIALOG);
1011 if (hResInfo == 0) {
1012 CommDlgLastError = CDERR_FINDRESFAILURE;
1013 return FALSE;
1015 hDlgTmpl = LoadResource(hSysRes, hResInfo);
1016 if (hDlgTmpl == 0) {
1017 CommDlgLastError = CDERR_LOADRESFAILURE;
1018 return FALSE;
1020 wndPtr = WIN_FindWndPtr(lpPrint->hwndOwner);
1021 if (lpPrint->Flags & PD_PRINTSETUP)
1022 bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
1023 lpPrint->hwndOwner, (WNDPROC)PrintSetupDlgProc, (DWORD)lpPrint);
1024 else
1025 bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
1026 lpPrint->hwndOwner, (WNDPROC)PrintDlgProc, (DWORD)lpPrint);
1027 return bRet;
1031 /***********************************************************************
1032 * PrintDlgProc [COMMDLG.21]
1034 BOOL PrintDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
1036 switch (wMsg) {
1037 case WM_INITDIALOG:
1038 printf("PrintDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1039 ShowWindow(hWnd, SW_SHOWNORMAL);
1040 return (TRUE);
1042 case WM_COMMAND:
1043 switch (wParam) {
1044 case IDOK:
1045 EndDialog(hWnd, TRUE);
1046 return(TRUE);
1047 case IDCANCEL:
1048 EndDialog(hWnd, FALSE);
1049 return(TRUE);
1051 return(FALSE);
1053 return FALSE;
1057 /***********************************************************************
1058 * PrintSetupDlgProc [COMMDLG.22]
1060 BOOL PrintSetupDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
1062 switch (wMsg) {
1063 case WM_INITDIALOG:
1064 printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08lX\n", lParam);
1065 ShowWindow(hWnd, SW_SHOWNORMAL);
1066 return (TRUE);
1068 case WM_COMMAND:
1069 switch (wParam) {
1070 case IDOK:
1071 EndDialog(hWnd, TRUE);
1072 return(TRUE);
1073 case IDCANCEL:
1074 EndDialog(hWnd, FALSE);
1075 return(TRUE);
1077 return(FALSE);
1079 return FALSE;
1083 /***********************************************************************
1084 * CommDlgExtendError [COMMDLG.26]
1086 DWORD CommDlgExtendError(void)
1088 return CommDlgLastError;
1092 /***********************************************************************
1093 * GetFileTitle [COMMDLG.27]
1095 int GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
1097 int i, len;
1098 printf("GetFileTitle(%p %p %d); \n", lpFile, lpTitle, cbBuf);
1099 if (lpFile == NULL || lpTitle == NULL) return -1;
1100 len = strlen(lpFile);
1101 if (len == 0) return -1;
1102 if (strchr(lpFile, '*') != NULL) return -1;
1103 if (strchr(lpFile, '[') != NULL) return -1;
1104 if (strchr(lpFile, ']') != NULL) return -1;
1105 len--;
1106 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':') return -1;
1107 for (i = len; i >= 0; i--) {
1108 if (lpFile[i] == '/' ||
1109 lpFile[i] == '\\' ||
1110 lpFile[i] == ':') {
1111 i++;
1112 break;
1115 printf("\n---> '%s' ", &lpFile[i]);
1116 len = min(cbBuf, strlen(&lpFile[i]) + 1);
1117 strncpy(lpTitle, &lpFile[i], len + 1);
1118 if (len != cbBuf)
1119 return len;
1120 else
1121 return 0;