I didn't find this example in this forum:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commdlg.h>
#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "comdlg32.lib")
static UINT_PTR CALLBACK OFNHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
if (uiMsg == WM_INITDIALOG) {
HWND hWnd = GetParent(hdlg);
if (hWnd) {
HWND hCtl;
hCtl = GetDlgItem(hWnd, 0x441);
ShowWindow(hCtl, SW_HIDE);
hCtl = GetDlgItem(hWnd, 0x470);
ShowWindow(hCtl, SW_HIDE);
hCtl = GetDlgItem(hWnd, 0x442);
ShowWindow(hCtl, SW_HIDE);
hCtl = GetDlgItem(hWnd, 0x47C);
ShowWindow(hCtl, SW_HIDE);
}
}
return 0;
}
static BOOL FileFolderBrowse(HWND hwnd, TCHAR *szFolder, TCHAR *szTitle)
{
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = TEXT("Folder only\0$$$.$$$\0\0");
ofn.lpstrFile = szFolder;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY
| OFN_ENABLEHOOK | OFN_ENABLESIZING | OFN_DONTADDTORECENT;
ofn.lpstrTitle = szTitle;
ofn.lpfnHook = OFNHookProc;
#if (_WIN32_WINNT >= 0x0500)
ofn.FlagsEx = OFN_EX_NOPLACESBAR;
#endif
lstrcpy(szFolder, "Folder$$$");
if (GetOpenFileName(&ofn)) {
*(szFolder + ofn.nFileOffset) = 0; // strip fake file
return TRUE;
} else
return FALSE;
}
int __cdecl WinMainCRTStartup(void)
{
TCHAR szFolder[MAX_PATH];
if (FileFolderBrowse(0, szFolder, TEXT("Select folder"))) {
MessageBox(0, szFolder, 0, MB_OK);
}
ExitProcess(0);
}