/*********************************************************************** * FD31_ScanDir [internal] */ static BOOL FD31_ScanDir(const OPENFILENAMEW *ofn, HWND hWnd, LPCWSTR newPath) { WCHAR buffer[BUFFILE]; HWND hdlg; LRESULT lRet = TRUE; HCURSOR hCursorWait, oldCursor; TRACE("Trying to change to %s\n", debugstr_w(newPath)); if ( newPath[0] && !SetCurrentDirectoryW( newPath )) return FALSE; /* get the list of spec files */ lstrcpynW(buffer, FD31_GetFileType(ofn->lpstrCustomFilter, ofn->lpstrFilter, ofn->nFilterIndex - 1), BUFFILE); hCursorWait = LoadCursorA(0, (LPSTR)IDC_WAIT); oldCursor = SetCursor(hCursorWait); /* list of files */ if ((hdlg = GetDlgItem(hWnd, lst1)) != 0) { WCHAR* scptr; /* ptr on semi-colon */ WCHAR* filter = buffer; TRACE("Using filter %s\n", debugstr_w(filter)); SendMessageW(hdlg, LB_RESETCONTENT, 0, 0); while (filter) { scptr = strchrW(filter, ';'); if (scptr) *scptr = 0; while (*filter == ' ') filter++; TRACE("Using file spec %s\n", debugstr_w(filter)); SendMessageW(hdlg, LB_DIR, 0, (LPARAM)filter); if (scptr) *scptr = ';'; filter = (scptr) ? (scptr + 1) : 0; } } /* list of directories */ strcpyW(buffer, FILE_star); if (GetDlgItem(hWnd, lst2) != 0) { lRet = DlgDirListW(hWnd, buffer, lst2, stc1, DDL_EXCLUSIVE | DDL_DIRECTORY); } SetCursor(oldCursor); return lRet; }
LONG FD31_WMInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam) { int i, n; WCHAR tmpstr[BUFFILE]; LPWSTR pstr, old_pstr; LPOPENFILENAMEW ofn; PFD31_DATA lfs = (PFD31_DATA) lParam; if (!lfs) return FALSE; SetPropA(hWnd, FD31_OFN_PROP, (HANDLE)lfs); lfs->hwnd = hWnd; ofn = lfs->ofnW; TRACE("flags=%lx initialdir=%s\n", ofn->Flags, debugstr_w(ofn->lpstrInitialDir)); SetWindowTextW( hWnd, ofn->lpstrTitle ); /* read custom filter information */ if (ofn->lpstrCustomFilter) { pstr = ofn->lpstrCustomFilter; n = 0; TRACE("lpstrCustomFilter = %p\n", pstr); while(*pstr) { old_pstr = pstr; i = SendDlgItemMessageW(hWnd, cmb1, CB_ADDSTRING, 0, (LPARAM)(ofn->lpstrCustomFilter) + n ); n += lstrlenW(pstr) + 1; pstr += lstrlenW(pstr) + 1; TRACE("add str=%s associated to %s\n", debugstr_w(old_pstr), debugstr_w(pstr)); SendDlgItemMessageW(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr); n += lstrlenW(pstr) + 1; pstr += lstrlenW(pstr) + 1; } } /* read filter information */ if (ofn->lpstrFilter) { pstr = (LPWSTR) ofn->lpstrFilter; n = 0; while(*pstr) { old_pstr = pstr; i = SendDlgItemMessageW(hWnd, cmb1, CB_ADDSTRING, 0, (LPARAM)(ofn->lpstrFilter + n) ); n += lstrlenW(pstr) + 1; pstr += lstrlenW(pstr) + 1; TRACE("add str=%s associated to %s\n", debugstr_w(old_pstr), debugstr_w(pstr)); SendDlgItemMessageW(hWnd, cmb1, CB_SETITEMDATA, i, (LPARAM)pstr); n += lstrlenW(pstr) + 1; pstr += lstrlenW(pstr) + 1; } } /* set default filter */ if (ofn->nFilterIndex == 0 && ofn->lpstrCustomFilter == NULL) ofn->nFilterIndex = 1; SendDlgItemMessageW(hWnd, cmb1, CB_SETCURSEL, ofn->nFilterIndex - 1, 0); lstrcpynW(tmpstr, FD31_GetFileType(ofn->lpstrCustomFilter, (LPWSTR)ofn->lpstrFilter, ofn->nFilterIndex - 1),BUFFILE); TRACE("nFilterIndex = %ld, SetText of edt1 to %s\n", ofn->nFilterIndex, debugstr_w(tmpstr)); SetDlgItemTextW( hWnd, edt1, tmpstr ); /* get drive list */ *tmpstr = 0; DlgDirListComboBoxW(hWnd, tmpstr, cmb2, 0, DDL_DRIVES | DDL_EXCLUSIVE); /* read initial directory */ /* FIXME: Note that this is now very version-specific (See MSDN description of * the OPENFILENAME structure). For example under 2000/XP any path in the * lpstrFile overrides the lpstrInitialDir, but not under 95/98/ME */ if (ofn->lpstrInitialDir != NULL) { int len; lstrcpynW(tmpstr, ofn->lpstrInitialDir, 511); len = lstrlenW(tmpstr); if (len > 0 && tmpstr[len-1] != '\\' && tmpstr[len-1] != ':') { tmpstr[len]='\\'; tmpstr[len+1]='\0'; } } else *tmpstr = 0; if (!FD31_ScanDir(hWnd, tmpstr)) { *tmpstr = 0; if (!FD31_ScanDir(hWnd, tmpstr)) WARN("Couldn't read initial directory %s!\n", debugstr_w(tmpstr)); } /* select current drive in combo 2, omit missing drives */ { char dir[MAX_PATH]; char str[4] = "a:\\"; GetCurrentDirectoryA( sizeof(dir), dir ); for(i = 0, n = -1; i < 26; i++) { str[0] = 'a' + i; if (GetDriveTypeA(str) > DRIVE_NO_ROOT_DIR) n++; if (toupper(str[0]) == toupper(dir[0])) break; } } SendDlgItemMessageW(hWnd, cmb2, CB_SETCURSEL, n, 0); if (!(ofn->Flags & OFN_SHOWHELP)) ShowWindow(GetDlgItem(hWnd, pshHelp), SW_HIDE); if (ofn->Flags & OFN_HIDEREADONLY) ShowWindow(GetDlgItem(hWnd, chx1), SW_HIDE); if (lfs->hook) return (BOOL) FD31_CallWindowProc(lfs, WM_INITDIALOG, wParam, lfs->lParam); return TRUE; }