Release 941030
[wine/multimedia.git] / misc / commdlg.c
blobaa1614bd85679f2915d1bd304e7272b3bd68f317
1 /*
2 * COMMDLG functions
4 * Copyright 1994 Martin Ayotte
5 */
6 static char Copyright[] = "Copyright Martin Ayotte, 1994";
8 /*
9 #define DEBUG_OPENDLG
10 #define DEBUG_OPENDLG_DRAW
13 #include "stdio.h"
14 #include "dialog.h"
15 #include "win.h"
16 #include "user.h"
17 #include "message.h"
18 #include "heap.h"
19 #include "commdlg.h"
20 #include "dlgs.h"
22 #define OPENFILEDLG2 11
23 #define SAVEFILEDLG2 12
26 extern HINSTANCE hSysRes;
27 static DWORD CommDlgLastError = 0;
29 static HBITMAP hFolder = 0;
30 static HBITMAP hFolder2 = 0;
31 static HBITMAP hFloppy = 0;
32 static HBITMAP hHDisk = 0;
33 static HBITMAP hCDRom = 0;
35 int DOS_GetDefaultDrive(void);
36 void DOS_SetDefaultDrive(int drive);
37 char *DOS_GetCurrentDir(int drive);
38 int DOS_ChangeDir(int drive, char *dirname);
40 BOOL FileDlg_Init(HWND hWnd, DWORD lParam);
41 BOOL OpenDlg_ScanFiles(HWND hWnd, WORD nDrive, LPSTR newPath, LPSTR fileSpec);
42 BOOL OpenDlg_ScanDir(HWND hWnd, WORD nDrive, LPSTR newPath, LPSTR fileSpec);
43 LPSTR OpenDlg_GetFileType(LPCSTR types, WORD index);
44 LPSTR OpenDlg_ExtractCurDir(LPSTR FullPath, short MaxLen);
45 BOOL FileOpenDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
46 BOOL FileSaveDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
47 BOOL ColorDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
48 BOOL PrintDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
49 BOOL PrintSetupDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
50 BOOL ReplaceTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
51 BOOL FindTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
53 /***********************************************************************
54 * GetOpenFileName [COMMDLG.1]
56 BOOL GetOpenFileName(LPOPENFILENAME lpofn)
58 HANDLE hDlgTmpl;
59 HANDLE hResInfo;
60 HINSTANCE hInst;
61 WND *wndPtr;
62 BOOL bRet;
63 printf("GetOpenFileName(%08X); !\n", lpofn);
64 if (lpofn == NULL) return FALSE;
65 printf("GetOpenFileName // Flags=%08X !\n", lpofn->Flags);
66 printf("GetOpenFileName // nMaxFile=%d lpstrFile='%s' !\n",
67 lpofn->nMaxFile, lpofn->lpstrFile);
68 printf("GetOpenFileName // lpstrInitialDir='%s' !\n", lpofn->lpstrInitialDir);
69 printf("GetOpenFileName // lpstrFilter=%08X !\n", lpofn->lpstrFilter);
70 printf("GetOpenFileName // nFilterIndex=%d !\n", lpofn->nFilterIndex);
71 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
72 hDlgTmpl = lpofn->hInstance;
74 else {
75 if (lpofn->Flags & OFN_ENABLETEMPLATE) {
76 printf("GetOpenFileName // avant FindResource hInstance=%04X lpTemplateName='%s' !\n",
77 lpofn->hInstance, lpofn->lpTemplateName);
78 hInst = lpofn->hInstance;
79 hResInfo = FindResource(hInst,
80 (LPSTR)lpofn->lpTemplateName, RT_DIALOG);
82 else {
83 printf("GetOpenFileName // avant FindResource hSysRes=%04X !\n", hSysRes);
84 hInst = hSysRes;
85 hResInfo = FindResource(hInst, MAKEINTRESOURCE(OPENFILEDLG2), RT_DIALOG);
87 if (hResInfo == 0) {
88 CommDlgLastError = CDERR_FINDRESFAILURE;
89 return FALSE;
91 printf("GetOpenFileName // apres FindResource hResInfo=%04X!\n", hResInfo);
92 hDlgTmpl = LoadResource(hInst, hResInfo);
94 if (hDlgTmpl == 0) {
95 CommDlgLastError = CDERR_LOADRESFAILURE;
96 return FALSE;
98 printf("GetOpenFileName // apres LoadResource hDlgTmpl=%04X!\n", hDlgTmpl);
99 wndPtr = WIN_FindWndPtr(lpofn->hwndOwner);
100 bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
101 lpofn->hwndOwner, (WNDPROC)FileOpenDlgProc, (DWORD)lpofn);
103 /* strcpy(lpofn->lpstrFile, "SETUP.TXT"); */
104 /* strcpy(lpofn->lpstrFileTitle, "SETUP.TXT");*/
106 lpofn->nFileOffset = 0;
107 lpofn->nFileExtension = strlen(lpofn->lpstrFile) - 3;
108 bRet = TRUE;
110 printf("GetOpenFileName // return lpstrFile='%s' !\n", lpofn->lpstrFile);
111 return bRet;
115 /***********************************************************************
116 * GetSaveFileName [COMMDLG.2]
118 BOOL GetSaveFileName(LPOPENFILENAME lpofn)
120 HANDLE hDlgTmpl;
121 HANDLE hResInfo;
122 HINSTANCE hInst;
123 WND *wndPtr;
124 BOOL bRet;
125 printf("GetSaveFileName(%08X); !\n", lpofn);
126 if (lpofn == NULL) return FALSE;
127 printf("GetSaveFileName // Flags=%08X !\n", lpofn->Flags);
128 printf("GetSaveFileName // nMaxFile=%d lpstrFile='%s' !\n",
129 lpofn->nMaxFile, lpofn->lpstrFile);
130 printf("GetSaveFileName // lpstrInitialDir='%s' !\n", lpofn->lpstrInitialDir);
131 printf("GetSaveFileName // lpstrFilter=%08X !\n", lpofn->lpstrFilter);
132 if (lpofn->Flags & OFN_ENABLETEMPLATEHANDLE) {
133 hDlgTmpl = lpofn->hInstance;
135 else {
136 if (lpofn->Flags & OFN_ENABLETEMPLATE) {
137 printf("GetSaveFileName // avant FindResource lpTemplateName='%s' !\n",
138 lpofn->lpTemplateName);
139 hInst = lpofn->hInstance;
140 hResInfo = FindResource(hInst,
141 (LPSTR)lpofn->lpTemplateName, RT_DIALOG);
143 else {
144 printf("GetSaveFileName // avant FindResource !\n");
145 hInst = hSysRes;
146 hResInfo = FindResource(hInst, MAKEINTRESOURCE(SAVEFILEDLG2), RT_DIALOG);
148 if (hResInfo == 0) {
149 CommDlgLastError = CDERR_FINDRESFAILURE;
150 return FALSE;
152 hDlgTmpl = LoadResource(hInst, hResInfo);
154 if (hDlgTmpl == 0) {
155 CommDlgLastError = CDERR_LOADRESFAILURE;
156 return FALSE;
158 wndPtr = WIN_FindWndPtr(lpofn->hwndOwner);
159 bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
160 lpofn->hwndOwner, (WNDPROC)FileSaveDlgProc, (DWORD)lpofn);
161 printf("GetSaveFileName // return lpstrFile='%s' !\n", lpofn->lpstrFile);
162 return bRet;
166 /***********************************************************************
167 * ChooseColor [COMMDLG.5]
169 BOOL ChooseColor(LPCHOOSECOLOR lpChCol)
171 HANDLE hDlgTmpl;
172 HANDLE hResInfo;
173 WND *wndPtr;
174 BOOL bRet;
175 hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(COLORDLG), RT_DIALOG);
176 hDlgTmpl = LoadResource(hSysRes, hResInfo);
177 wndPtr = WIN_FindWndPtr(lpChCol->hwndOwner);
178 bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
179 lpChCol->hwndOwner, (WNDPROC)ColorDlgProc, (DWORD)lpChCol);
180 return bRet;
184 /***********************************************************************
185 * FileOpenDlgProc [COMMDLG.6]
187 BOOL FileOpenDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
189 int n;
190 LPSTR ptr;
191 LPSTR fspec;
192 char str[512];
193 char C2[128];
194 WORD wRet;
195 HBRUSH hBrush;
196 HDC hMemDC;
197 HBITMAP hBitmap;
198 BITMAP bm;
199 WND *wndPtr;
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=%08X\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 int OldDrive;
635 static char OldPath[512];
636 static char CurPath[512];
637 static LPOPENFILENAME lpofn;
639 switch (wMsg) {
640 case WM_INITDIALOG:
641 #ifdef DEBUG_OPENDLG
642 printf("FileSaveDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
643 #endif
644 if (!FileDlg_Init(hWnd, lParam)) return TRUE;
645 SendDlgItemMessage(hWnd, cmb1, CB_RESETCONTENT, 0, 0L);
646 lpofn = (LPOPENFILENAME)lParam;
647 ptr = (LPSTR)lpofn->lpstrFilter;
648 strcpy(CurPath, lpofn->lpstrInitialDir);
649 while((n = strlen(ptr)) != 0) {
650 #ifdef DEBUG_OPENDLG
651 printf("FileSaveDlgProc // file type '%s' !\n", ptr);
652 #endif
653 SendDlgItemMessage(hWnd, cmb1, CB_ADDSTRING, 0, (DWORD)ptr);
654 ptr += ++n;
655 #ifdef DEBUG_OPENDLG
656 printf("FileSaveDlgProc // file spec '%s' !\n", ptr);
657 #endif
658 n = strlen(ptr);
659 ptr += ++n;
661 SendDlgItemMessage(hWnd, edt1, WM_SETTEXT, 0, (DWORD)str);
662 SendDlgItemMessage(hWnd, cmb1, CB_SETCURSEL,
663 lpofn->nFilterIndex - 1, 0L);
664 DlgDirListComboBox(hWnd, "", cmb2, 0, 0xC000);
665 nDrive = 2; /* Drive 'C:' */
666 SendDlgItemMessage(hWnd, cmb2, CB_SETCURSEL, nDrive, 0L);
667 sprintf(str, "%c:\\%s", nDrive + 'A', DOS_GetCurrentDir(nDrive));
668 fspec = OpenDlg_GetFileType(lpofn->lpstrFilter,
669 lpofn->nFilterIndex);
670 #ifdef DEBUG_OPENDLG
671 printf("FileSaveDlgProc // WM_INITDIALOG fspec #%d = '%s' !\n",
672 lpofn->nFilterIndex, fspec);
673 #endif
674 if (!OpenDlg_ScanDir(hWnd, nDrive, str, fspec)) {
675 printf("OpenDlg_ScanDir // ChangeDir Error !\n");
677 else {
678 strcpy(CurPath, str);
680 ShowWindow(hWnd, SW_SHOWNORMAL);
681 return (TRUE);
683 case WM_SHOWWINDOW:
684 if (wParam == 0) break;
685 if (!(lpofn->Flags & OFN_SHOWHELP)) {
686 ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE);
688 if (lpofn->Flags & OFN_HIDEREADONLY) {
689 ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE);
691 return TRUE;
693 case WM_MEASUREITEM:
694 GetObject(hFolder2, sizeof(BITMAP), (LPSTR)&bm);
695 lpmeasure = (LPMEASUREITEMSTRUCT)lParam;
696 lpmeasure->itemHeight = bm.bmHeight;
697 #ifdef DEBUG_OPENDLG_DRAW
698 printf("FileSaveDlgProc WM_MEASUREITEM Height=%d !\n", bm.bmHeight);
699 #endif
700 return TRUE;
702 case WM_DRAWITEM:
703 #ifdef DEBUG_OPENDLG_DRAW
704 printf("FileSaveDlgProc // WM_DRAWITEM w=%04X l=%08X\n", wParam, lParam);
705 #endif
706 if (lParam == 0L) break;
707 lpdis = (LPDRAWITEMSTRUCT)lParam;
708 #ifdef DEBUG_OPENDLG_DRAW
709 printf("FileSaveDlgProc // WM_DRAWITEM lpdis->CtlID=%04X\n", lpdis->CtlID);
710 #endif
711 if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst1)) {
712 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
713 SelectObject(lpdis->hDC, hBrush);
714 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
715 ptr = (LPSTR) lpdis->itemData;
716 if (ptr == NULL) break;
717 TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
718 ptr, strlen(ptr));
720 if ((lpdis->CtlType == ODT_LISTBOX) && (lpdis->CtlID == lst2)) {
721 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
722 SelectObject(lpdis->hDC, hBrush);
723 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
724 ptr = (LPSTR) lpdis->itemData;
725 if (ptr == NULL) break;
726 if (strcmp(ptr, "[.]") == 0) {
727 hBitmap = hFolder2;
728 ptr = CurPath;
730 else
731 hBitmap = hFolder;
732 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
733 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
734 lpdis->rcItem.top, ptr, strlen(ptr));
735 hMemDC = CreateCompatibleDC(lpdis->hDC);
736 SelectObject(hMemDC, hBitmap);
737 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
738 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
739 DeleteDC(hMemDC);
741 if ((lpdis->CtlType == ODT_COMBOBOX) && (lpdis->CtlID == cmb2)) {
742 hBrush = SelectObject(lpdis->hDC, GetStockObject(LTGRAY_BRUSH));
743 SelectObject(lpdis->hDC, hBrush);
744 FillRect(lpdis->hDC, &lpdis->rcItem, hBrush);
745 ptr = (LPSTR) lpdis->itemData;
746 if (ptr == NULL) break;
747 switch(ptr[2]) {
748 case 'a':
749 case 'b':
750 hBitmap = hFloppy;
751 break;
752 default:
753 hBitmap = hHDisk;
755 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
756 TextOut(lpdis->hDC, lpdis->rcItem.left + bm.bmWidth,
757 lpdis->rcItem.top, ptr, strlen(ptr));
758 hMemDC = CreateCompatibleDC(lpdis->hDC);
759 SelectObject(hMemDC, hBitmap);
760 BitBlt(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
761 bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);
762 DeleteDC(hMemDC);
764 break;
766 case WM_COMMAND:
767 switch (wParam) {
768 case lst1:
769 if (HIWORD(lParam) == LBN_DBLCLK ||
770 HIWORD(lParam) == LBN_SELCHANGE) {
771 #ifdef DEBUG_OPENDLG
772 printf("FileSaveDlgProc // LBN_SELCHANGE on lst1 !\n");
773 #endif
774 wRet = SendDlgItemMessage(hWnd, lst1, LB_GETCURSEL, 0, 0L);
775 SendDlgItemMessage(hWnd, lst1, LB_GETTEXT, wRet, (DWORD)C2);
777 if (HIWORD(lParam) == LBN_DBLCLK) {
778 #ifdef DEBUG_OPENDLG
779 printf("FileSaveDlgProc // LBN_DBLCLK on lst1 !\n");
780 #endif
781 return SendMessage(hWnd, WM_COMMAND, IDOK, 0L);
783 break;
784 case lst2:
785 if (HIWORD(lParam) == LBN_DBLCLK) {
786 #ifdef DEBUG_OPENDLG
787 printf("FileSaveDlgProc // LBN_DBLCLK on lst2 !\n");
788 #endif
789 wRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
790 fspec = OpenDlg_GetFileType(lpofn->lpstrFilter, wRet + 1);
791 C2[0] = '\0';
792 wRet = SendDlgItemMessage(hWnd, lst2, LB_GETCURSEL, 0, 0L);
793 SendDlgItemMessage(hWnd, lst2, LB_GETTEXT, wRet, (DWORD)C2);
794 if (C2[0] == '[') {
795 C2[strlen(C2) - 1] = '\0';
796 sprintf(str, "%s\\%s", CurPath, &C2[1]);
797 if (!OpenDlg_ScanDir(hWnd, nDrive, str, fspec)) {
798 printf("FileSaveDlgProc // ChangeDir Error !\n");
800 else {
801 strcpy(CurPath, str);
805 break;
806 case cmb1:
807 if (HIWORD(lParam) == CBN_SELCHANGE) {
808 wRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
809 fspec = OpenDlg_GetFileType(lpofn->lpstrFilter, wRet + 1);
810 printf("FileSaveDlgProc // new fspec #%d = '%s' !\n", wRet, fspec);
811 if (!OpenDlg_ScanFiles(hWnd, nDrive, CurPath, fspec)) {
812 printf("OpenDlg_ScanFile // Change FileType Error !\n");
815 break;
816 case cmb2:
817 #ifdef DEBUG_OPENDLG
818 printf("FileSaveDlgProc // combo #2 changed !\n");
819 #endif
820 wRet = SendDlgItemMessage(hWnd, cmb1, CB_GETCURSEL, 0, 0L);
821 if (wRet == (WORD)LB_ERR) return 0;
822 fspec = OpenDlg_GetFileType(lpofn->lpstrFilter, wRet + 1);
823 wRet = SendDlgItemMessage(hWnd, cmb2, CB_GETCURSEL, 0, 0L);
824 if (wRet == (WORD)LB_ERR) return 0;
825 printf("FileSaveDlgProc // combo #2 CB_GETCURSEL=%d !\n", wRet);
826 SendDlgItemMessage(hWnd, cmb2, CB_GETLBTEXT, wRet, (DWORD)C2);
827 nDrive = C2[2] - 'a';
828 #ifdef DEBUG_OPENDLG
829 printf("FileSaveDlgProc // new drive selected=%d !\n", nDrive);
830 #endif
831 sprintf(str, "%c:\\%s", nDrive + 'A', DOS_GetCurrentDir(nDrive));
832 #ifdef DEBUG_OPENDLG
833 printf("FileSaveDlgProc // new drive , curPath='%s' !\n", str);
834 #endif
835 if (!OpenDlg_ScanDir(hWnd, nDrive, str, fspec)) {
836 printf("FileSaveDlgProc // Change Drive Error !\n");
838 else {
839 strcpy(CurPath, str);
841 break;
842 case chx1:
843 #ifdef DEBUG_OPENDLG
844 printf("FileSaveDlgProc // read-only toggled !\n");
845 #endif
846 break;
847 case pshHelp:
848 #ifdef DEBUG_OPENDLG
849 printf("FileSaveDlgProc // pshHelp pressed !\n");
850 #endif
851 break;
852 case IDOK:
853 strcpy(lpofn->lpstrFile, "titi.txt");
854 if (lpofn->lpstrFileTitle != NULL) {
855 strcpy(lpofn->lpstrFileTitle, "titi.txt");
857 EndDialog(hWnd, TRUE);
858 return(TRUE);
859 case IDCANCEL:
860 EndDialog(hWnd, FALSE);
861 return(TRUE);
863 return(FALSE);
865 return FALSE;
869 /***********************************************************************
870 * ColorDlgProc [COMMDLG.8]
872 BOOL ColorDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
874 switch (wMsg) {
875 case WM_INITDIALOG:
876 printf("ColorDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
877 ShowWindow(hWnd, SW_SHOWNORMAL);
878 return (TRUE);
880 case WM_COMMAND:
881 switch (wParam) {
882 case IDOK:
883 EndDialog(hWnd, TRUE);
884 return(TRUE);
885 case IDCANCEL:
886 EndDialog(hWnd, FALSE);
887 return(TRUE);
889 return(FALSE);
891 return FALSE;
895 /***********************************************************************
896 * FindTextDlg [COMMDLG.11]
898 BOOL FindText(LPFINDREPLACE lpFind)
900 HANDLE hDlgTmpl;
901 HANDLE hResInfo;
902 WND *wndPtr;
903 BOOL bRet;
904 hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(FINDDLG), RT_DIALOG);
905 if (hResInfo == 0) {
906 CommDlgLastError = CDERR_FINDRESFAILURE;
907 return FALSE;
909 hDlgTmpl = LoadResource(hSysRes, hResInfo);
910 if (hDlgTmpl == 0) {
911 CommDlgLastError = CDERR_LOADRESFAILURE;
912 return FALSE;
914 wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
915 bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
916 lpFind->hwndOwner, (WNDPROC)FindTextDlgProc, (DWORD)lpFind);
917 return bRet;
921 /***********************************************************************
922 * ReplaceTextDlg [COMMDLG.12]
924 BOOL ReplaceText(LPFINDREPLACE lpFind)
926 HANDLE hDlgTmpl;
927 HANDLE hResInfo;
928 WND *wndPtr;
929 BOOL bRet;
930 hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(REPLACEDLG), RT_DIALOG);
931 if (hResInfo == 0) {
932 CommDlgLastError = CDERR_FINDRESFAILURE;
933 return FALSE;
935 hDlgTmpl = LoadResource(hSysRes, hResInfo);
936 if (hDlgTmpl == 0) {
937 CommDlgLastError = CDERR_LOADRESFAILURE;
938 return FALSE;
940 wndPtr = WIN_FindWndPtr(lpFind->hwndOwner);
941 bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
942 lpFind->hwndOwner, (WNDPROC)ReplaceTextDlgProc, (DWORD)lpFind);
943 return bRet;
947 /***********************************************************************
948 * FindTextDlgProc [COMMDLG.13]
950 BOOL FindTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
952 switch (wMsg) {
953 case WM_INITDIALOG:
954 printf("FindTextDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
955 ShowWindow(hWnd, SW_SHOWNORMAL);
956 return (TRUE);
958 case WM_COMMAND:
959 switch (wParam) {
960 case IDOK:
961 EndDialog(hWnd, TRUE);
962 return(TRUE);
963 case IDCANCEL:
964 EndDialog(hWnd, FALSE);
965 return(TRUE);
967 return(FALSE);
969 return FALSE;
973 /***********************************************************************
974 * ReplaceTextDlgProc [COMMDLG.14]
976 BOOL ReplaceTextDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
978 switch (wMsg) {
979 case WM_INITDIALOG:
980 printf("ReplaceTextDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
981 ShowWindow(hWnd, SW_SHOWNORMAL);
982 return (TRUE);
984 case WM_COMMAND:
985 switch (wParam) {
986 case IDOK:
987 EndDialog(hWnd, TRUE);
988 return(TRUE);
989 case IDCANCEL:
990 EndDialog(hWnd, FALSE);
991 return(TRUE);
993 return(FALSE);
995 return FALSE;
999 /***********************************************************************
1000 * PrintDlg [COMMDLG.20]
1002 BOOL PrintDlg(LPPRINTDLG lpPrint)
1004 HANDLE hDlgTmpl;
1005 HANDLE hResInfo;
1006 WND *wndPtr;
1007 BOOL bRet;
1008 printf("PrintDlg(%08X) // Flags=%08X\n", lpPrint->Flags);
1009 if (lpPrint->Flags & PD_PRINTSETUP)
1010 hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(PRINTSETUPDLG), RT_DIALOG);
1011 else
1012 hResInfo = FindResource(hSysRes, MAKEINTRESOURCE(PRINTDLG), RT_DIALOG);
1013 if (hResInfo == 0) {
1014 CommDlgLastError = CDERR_FINDRESFAILURE;
1015 return FALSE;
1017 hDlgTmpl = LoadResource(hSysRes, hResInfo);
1018 if (hDlgTmpl == 0) {
1019 CommDlgLastError = CDERR_LOADRESFAILURE;
1020 return FALSE;
1022 wndPtr = WIN_FindWndPtr(lpPrint->hwndOwner);
1023 if (lpPrint->Flags & PD_PRINTSETUP)
1024 bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
1025 lpPrint->hwndOwner, (WNDPROC)PrintSetupDlgProc, (DWORD)lpPrint);
1026 else
1027 bRet = DialogBoxIndirectParam(wndPtr->hInstance, hDlgTmpl,
1028 lpPrint->hwndOwner, (WNDPROC)PrintDlgProc, (DWORD)lpPrint);
1029 return bRet;
1033 /***********************************************************************
1034 * PrintDlgProc [COMMDLG.21]
1036 BOOL PrintDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
1038 switch (wMsg) {
1039 case WM_INITDIALOG:
1040 printf("PrintDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
1041 ShowWindow(hWnd, SW_SHOWNORMAL);
1042 return (TRUE);
1044 case WM_COMMAND:
1045 switch (wParam) {
1046 case IDOK:
1047 EndDialog(hWnd, TRUE);
1048 return(TRUE);
1049 case IDCANCEL:
1050 EndDialog(hWnd, FALSE);
1051 return(TRUE);
1053 return(FALSE);
1055 return FALSE;
1059 /***********************************************************************
1060 * PrintSetupDlgProc [COMMDLG.22]
1062 BOOL PrintSetupDlgProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
1064 switch (wMsg) {
1065 case WM_INITDIALOG:
1066 printf("PrintSetupDlgProc // WM_INITDIALOG lParam=%08X\n", lParam);
1067 ShowWindow(hWnd, SW_SHOWNORMAL);
1068 return (TRUE);
1070 case WM_COMMAND:
1071 switch (wParam) {
1072 case IDOK:
1073 EndDialog(hWnd, TRUE);
1074 return(TRUE);
1075 case IDCANCEL:
1076 EndDialog(hWnd, FALSE);
1077 return(TRUE);
1079 return(FALSE);
1081 return FALSE;
1085 /***********************************************************************
1086 * CommDlgExtendError [COMMDLG.26]
1088 DWORD CommDlgExtendError(void)
1090 return CommDlgLastError;
1094 /***********************************************************************
1095 * GetFileTitle [COMMDLG.27]
1097 int GetFileTitle(LPCSTR lpFile, LPSTR lpTitle, UINT cbBuf)
1099 int i, len;
1100 printf("GetFileTitle(%08X %08X %d); \n", lpFile, lpTitle, cbBuf);
1101 if (lpFile == NULL || lpTitle == NULL) return -1;
1102 len = strlen(lpFile);
1103 if (len == 0) return -1;
1104 if (strchr(lpFile, '*') != NULL) return -1;
1105 if (strchr(lpFile, '[') != NULL) return -1;
1106 if (strchr(lpFile, ']') != NULL) return -1;
1107 len--;
1108 if (lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':') return -1;
1109 for (i = len; i >= 0; i--) {
1110 if (lpFile[i] == '/' ||
1111 lpFile[i] == '\\' ||
1112 lpFile[i] == ':') {
1113 i++;
1114 break;
1117 printf("\n---> '%s' ", &lpFile[i]);
1118 len = min(cbBuf, strlen(&lpFile[i]) + 1);
1119 strncpy(lpTitle, &lpFile[i], len + 1);
1120 if (len != cbBuf)
1121 return len;
1122 else
1123 return 0;