1

I am using the GetOpenFileName() function from Win32 in my C++ application. Everything was fine until I wanted to use Visual Styles:

image

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:

image

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
}
 
//-------------------
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Smok1e
  • 51
  • 1
  • 3
  • and you read comment at the code begin ? – RbMm Nov 27 '21 at 19:38
  • yes, I do not quite understand what delay loading means, but I execute this code at the very beginning of the program, before loading all the GUI components – Smok1e Nov 27 '21 at 19:48
  • *"I am not using a manifest file"* - Is there a reason to avoid this solution? Linking a manifest into the PE image is the most straight forward way to enable Visual Styles. – IInspectable Nov 27 '21 at 20:23
  • @Smok1e "*I used the function from this article*" - are you referring to `ActivateActCtx()`? It would really help if you would provide a [mcve] demonstrating the problem in action. – Remy Lebeau Nov 27 '21 at 23:35
  • @RemyLebeau [Here's](https://pastebin.com/rHMauLPP) 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). #define USE_ACT_CTX to use the activation context. – Smok1e Nov 28 '21 at 11:48
  • I banged on this for a while. But with little to show for it, CreateActCtx() really is the troublemaker. It seems to activate a "be more like XP" appcompat shim and hides the breadcrumb bar. Do favor embedding the manifest, do favor IFileOpenDialog. https://learn.microsoft.com/en-us/windows/win32/shell/common-file-dialog#sample-usage – Hans Passant Nov 28 '21 at 22:09

0 Answers0