How is it possible to make an openfile dialog box, where spaces are allowed in the path? Thanks.
Printable View
How is it possible to make an openfile dialog box, where spaces are allowed in the path? Thanks.
That depends probably on what toolkit you're using to make the dialog box in the first place, I guess. I'm not an expert on the various different kinds, or on any in particular, but most of them don't have trouble with spaces, to the best of my understanding.
This is the code I am using:
Code:void Opendialog(HWND hwnd){
OPENFILENAME ofn;
TCHAR buf[60];
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize=sizeof(ofn);
ofn.lpstrFile=buf;
ofn.lpstrFile[0]='\0';
ofn.hwndOwner=hwnd;
ofn.nMaxFile=sizeof(buf);
ofn.lpstrFilter=TEXT("All Files(*.*)\0*.*\0");
ofn.nFilterIndex=1;
ofn.lpstrInitialDir=NULL;
ofn.lpstrFileTitle=NULL;
ofn.Flags= OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if(GetOpenFileName(&ofn))
Loadfile(ofn.lpstrFile);
}
void Loadfile(LPSTR file){
HANDLE hfile;
DWORD dwsize;
DWORD dw;
LPBYTE Ipbuffer=NULL;
hfile=CreateFile(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
dwsize=GetFileSize(hfile, NULL);
Ipbuffer=(LPBYTE)HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, dwsize+1);
ReadFile(hfile, (LPWSTR)Ipbuffer, dwsize, &dw, NULL);
CloseHandle(hfile);
Ipbuffer[dwsize]=0;
SetWindowText(ghwndedit, (const char *)Ipbuffer);
HeapFree(GetProcessHeap(), 0, Ipbuffer);
}
> ofn.lpstrFilter=TEXT("All Files(*.*)\0*.*\0");
needs a second '\0'
ofn.lpstrFilter=TEXT("All Files(*.*)\0*.*\0\0");
Sorry for coming back after too long, but it didn't work.
Edit: Anyway, solved. CommDlgExtendedError showed error 12291, which means that lpstrFile buffer is too small. In other words, problem was the inadequate space allocated for the path and not the space characters in it.