Window toolbar doesn't show button icons if initialized after GetOpenFileNameA

David L 161 Reputation points
2022-07-09T15:53:56.22+00:00

Hello

I have a WIN32 C program that has 2 modes and for each mode, the main window toolbar is different.

I initialize my toolbar with "CreateWindowEx(0, TOOLBARCLASSNAME...)" and all the "ImageList_xxx()" and "SendMessage(hwTB, TB_XXX...)" functions.

To switch to the other toolbar, I "DestroyWindow()" and "ImageList_Destroy()" before initializing as before the new one. It perfectly works until I first use "GetOpenFileNameA()".

scree163.png

scree164.png

After this "GetOpenFileNameA", if I switch, the new toolbar is created with all the buttons, their tooltips and sending the right messages to the window proc, but there is no icon on them.

scree165.png

If "GetOpenFileNameA" returns FALSE (cancel is pressed or the dialog is closed with the upper right [x]) it continues to show the icons.

I have checked that "GetOpenFileNameA" is responsible for this strange behaviour as I have tried to "return" the function just before the "GetOpenFileNameA" and everything works as usual and I have also tried to "return" just after the "GetOpenFileNameA" doing nothing as if the function has returned FALSE. If FALSE, it continues to work, if TRUE, it doesn't show the icons anymore.

Any idea why this happens, please?

Thanks

David

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,733 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,850 questions
0 comments No comments
{count} votes

Accepted answer
  1. KingKong-4442 166 Reputation points
    2022-07-09T16:45:48.38+00:00

    GetOpenFileName probably changes the current working directory and you're loading the images using relative path names. Try using absolute path names instead, check the loading function's return code and, in case of failure, call GetLastError to see what went wrong.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. David L 161 Reputation points
    2022-07-09T17:01:25.67+00:00

    Wonderful!
    You are perfectly right.
    Thanks a lot
    David


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.