OPENFILENAME Structure Not Acting How I want.
Feb 20, 2011 at 5:34pm UTC
1 2 3 4 5 6 7 8
OPENFILENAME ofn = {0};
char caFileName [MAX_PATH] = {0};
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
ofn.lpstrFilter = "All Files (*.*)\0*.*\=" ;
ofn.lpstrFile = caFileName;
ofn.nMaxFile = MAX_PATH;
GetOpenFileName (&ofn);
This isn't acting how I want it to, it created the dialog, but I can't select a folder which is what I want to do. Can anyone help with this? Thank you :D
Feb 20, 2011 at 6:13pm UTC
You'll need to use these two functions:
SHBrowseForFolder :
http://msdn.microsoft.com/en-us/library/bb762115(v=vs.85).aspx
SHGetPathFromIDList :
http://msdn.microsoft.com/en-us/library/bb762194(v=vs.85).aspx
Here's an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
BROWSEINFO bi = { 0 };
bi.lpszTitle = _T("Pick a Directory" );
LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );
if ( pidl != 0 )
{
// get the name of the folder
TCHAR path[MAX_PATH];
if ( SHGetPathFromIDList ( pidl, path ) )
{
_tprintf ( _T("Selected Folder: %s\n" ), path );
}
// free memory used
IMalloc * imalloc = 0;
if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
{
imalloc->Free ( pidl );
imalloc->Release ( );
}
}
Feb 21, 2011 at 3:09am UTC
Eh, when I try to use that example I get a load of errors:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
||=== PSP Hacking Environment, Release ===|
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h||In function `LRESULT nsWindowProcedure::nsCWP::CWP_3(HWND__*, UINT, WPARAM, LPARAM)':|
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|148|error: `BROWSEINFO' was not declared in this scope|
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|148|error: expected `;' before "bi"|
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|149|error: `bi' was not declared in this scope|
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|149|error: `_T' was not declared in this scope|
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|150|error: `LPITEMIDLIST' was not declared in this scope|
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|150|error: expected `;' before "pidl"|
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|151|error: `pidl' was not declared in this scope|
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|154|error: `SHGetPathFromIDList' was not declared in this scope|
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|154|error: `_tprintf' was not declared in this scope|
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|154|warning: unused variable '_tprintf' |
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|154|warning: unused variable 'SHGetPathFromIDList' |
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|156|error: `SHGetMalloc' was not declared in this scope|
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|156|warning: unused variable ' SHGetMalloc'|
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|148|warning: unused variable ' BROWSEINFO'|
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|149|warning: unused variable ' bi'|
C:\Users\-LeetGamer-\Desktop\C++ Projects\PSP Coding Environment\Window Procedures.h|150|warning: unused variable ' LPITEMIDLIST'|
||=== Build finished: 10 errors, 6 warnings ===|
=/ I guess I missed something? :D
Feb 21, 2011 at 5:24am UTC
You probably aren't including a required header.
Feb 21, 2011 at 6:24am UTC
That's what I think too, but I tried googling some examples and can't find one that uses header files so I don't know what to include :(
Feb 21, 2011 at 6:39am UTC
The header is mentioned on the page Null linked to:
#include <Shlobj.h>
Feb 21, 2011 at 8:10am UTC
I see, I have failed :P thanks it works.
Feb 21, 2011 at 4:12pm UTC
One more thing-the lpstrFilter member has to be a double null terminated one. After \= u should put \0 also.
Topic archived. No new replies allowed.