I am using the GetOpenFileName()
function from Win32 in my C++ application. Everything was fine until I wanted to use Visual Styles:
I am not using a manifest file, I used the function from this article.
When I turned on Visual Styles, the path input line disappeared in the file selection dialog:
Does anyone know how to fix this?
UPDATE: Here's an example I did to reproduce the problem. I compiled it in Visual Studio 2019. Make sure the manifest is turned off in the project properties (Linker> Manifest File> Generate Manifest> NO) and #define USE_ACT_CTX
to use the activation context.
#include <windows.h>
#include <cassert>
//-------------------
int main ()
{
#ifdef USE_ACT_CTX
wchar_t dir[MAX_PATH] = L"";
GetSystemDirectoryW (dir, MAX_PATH);
ACTCTXW context =
{
sizeof (context),
ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_SET_PROCESS_DEFAULT | ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID,
L"shell32.dll",
0,
0,
dir,
(LPCWSTR) 124
};
HANDLE context_handle = CreateActCtxW (&context);
assert (context_handle != INVALID_HANDLE_VALUE);
ULONG_PTR cookie = 0;
assert (ActivateActCtx (context_handle, &cookie));
#endif
OPENFILENAMEW ofn = {};
wchar_t filename[MAX_PATH] = L"";
ofn.lStructSize = sizeof (ofn);
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = L"DLL\0*.DLL\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = nullptr;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = nullptr;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
GetOpenFileNameW (&ofn);
#ifdef USE_ACT_CTX
ReleaseActCtx (context_handle);
#endif
}
//-------------------