OPENFILENAME Structure Not Acting How I want.

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
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 ( );
        }
    } 
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
You probably aren't including a required header.
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 :(
The header is mentioned on the page Null linked to:

#include <Shlobj.h>
I see, I have failed :P thanks it works.
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.