Transparent part of Icons becomes black on ToolBar on Windows

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Hermann
In need of some credit
In need of some credit
Posts: 2
Joined: Sun Apr 29, 2018 12:25 pm

Transparent part of Icons becomes black on ToolBar on Windows

Postby Hermann » Sun Apr 29, 2018 12:51 pm

Hi

I want to use the default wxArtProvider to fill the tools on a wxToolBar with icons as provided by the system.
This is the code I came up with (minimal example):

Code: Select all

#include <wx/wx.h>
#include <wx/artprov.h>
#include <wx/sysopt.h>
class App : public wxApp {
  virtual bool OnInit() {
      wxSystemOptions::SetOption("msw.remap", 2); // according to http://docs.wxwidgets.org/trunk/classwx_tool_bar.html
      wxFrame *frame = new wxFrame(NULL, wxID_ANY, "Transparencytest");
      wxToolBar* toolBar = frame->CreateToolBar(wxTB_HORIZONTAL, wxID_ANY);
      toolBar->AddTool(wxID_ANY, wxT("&Open"), wxArtProvider::GetBitmap(wxART_FOLDER_OPEN, wxART_TOOLBAR));
      toolBar->Realize();
      frame->Show(true);
      return true;
    }
};
wxIMPLEMENT_APP(App);

As you can see in the attached image, the transparent parts of the system provided bitmap become black, although transparency (using an alpha channel, even) was enabled explicitly by the wxSystemOptions::SetOption call.

I am on Windows 10, building against wxWidgets 3.1.1 with TGM GCC 5.1.0 (64bit). Using pre-compiled DLLs or linking against static libraries I compiled myself makes no difference.
On Ubuntu 16.04, building against wxWidgets 3.0.2 (GTK2), the toolbar looks perfectly fine (with transparency).

Various other forum topics
viewtopic.php?f=1&t=1932
viewtopic.php?f=1&t=40485
viewtopic.php?f=1&t=23160
viewtopic.php?f=23&t=10686
mention this issue with (embedded) PNGs, but I am not using custom embedded images.

What am I missing here?

Kind Regards
Attachments
Windows10.png
Windows10.png (2.02 KiB) Viewed 229 times

PB
Part Of The Furniture
Part Of The Furniture
Posts: 1587
Joined: Sun Jan 03, 2010 5:45 pm

Re: Transparent part of Icons becomes black on ToolBar on Windows

Postby PB » Sun Apr 29, 2018 2:19 pm

Works fine for me, regardless of setting the system option.
tt.png
tt.png (2.83 KiB) Viewed 223 times


This is odd, I am running GIT master but I am not aware of any recent changes regarding the toolbar or transparency. I am also using MSVC but that should make no difference.

I have also noticed that my toolbar is flat while yours is not. Do you have a theme manifest embedded in the test app?

I will try with official 3.1.1 soon.

Edit
Still worked for me even with the official 3.1.1 release, where I used your code to replace the content of file minimal.cpp in the bundled minimal sample. Can you test it the same way, i.e., using the sample makefile?

New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 252
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: Transparent part of Icons becomes black on ToolBar on Windows

Postby New Pagodi » Sun Apr 29, 2018 2:40 pm

Like PB said, this appears to be a manifest issue. Try adding an rc file containing at least the line:

Code: Select all

#include "wx/msw/wx.rc"


That will include the standard wxwidgets manifest file in your project.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 1587
Joined: Sun Jan 03, 2010 5:45 pm

Re: Transparent part of Icons becomes black on ToolBar on Windows

Postby PB » Sun Apr 29, 2018 2:41 pm

I just tried with Code::Blocks, MingW-w64 and the project generated by C:: B; the code stops working and starts looking as yours when I comment out this line in the resource.rc file

Code: Select all

#include "wx/msw/wx.rc"


MSVC embeds the manifest automatically, so it works even without including wxWidgets resource file. I guess the reason why the file open icon still gets loaded even when the wxWidgets resource file is not embedded is because this icon is retrieved with MS Windows' function SHGetStockIconInfo() and not from the application resource.

Edit:That is how the resource file is linked with MinGW, output from C::B build (32-bit)
windres.exe -IL:\Dev\Desktop\Lib\wxWidgets-GIT\include -IL:\Dev\Desktop\Lib\wxWidgets-GIT\lib\gcc_lib\mswu -J rc -O coff -i F:\Dev\Desktop\!MyProgs\wx31test\resource.rc -o obj\Release\resource.res

i686-w64-mingw32-g++.exe -Wall -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -DwxUSE_UNICODE -O2 -IL:\Dev\Desktop\Lib\wxWidgets-GIT\include -IL:\Dev\Desktop\Lib\wxWidgets-GIT\lib\gcc_lib\mswu -c F:\Dev\Desktop\!MyProgs\wx31test\wx31testApp.cpp -o obj\Release\wx31testApp.o

i686-w64-mingw32-g++.exe -LL:\Dev\Desktop\Lib\wxWidgets-GIT\lib\gcc_lib -o bin\Release\wx31test.exe obj\Release\wx31testApp.o obj\Release\resource.res -s -mthreads -lwxmsw31u_core -lwxbase31u -lwxpng -lwxzlib -lwxjpeg -lwxtiff -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lcomctl32 -lwsock32 -lodbc32 -lshlwapi -lversion -luxtheme -loleacc -mwindows

Hermann
In need of some credit
In need of some credit
Posts: 2
Joined: Sun Apr 29, 2018 12:25 pm

Re: Transparent part of Icons becomes black on ToolBar on Windows

Postby Hermann » Sun Apr 29, 2018 8:01 pm

Thanks to both of you. =D>

The answer to my original question
Hermann wrote:What am I missing here?

indeed is
A resource file containing at least

Code: Select all

#include "wx/msw/wx.rc"

.

Culprit was that I started this project on Linux, developed with portability in mind, but completely forgot about the quirks of Windows programs. Apparently, C::B 13.12 template for wxWidgets project does not include a resource file. I understand one would not want additional files in a project you would never need. On Windows, I opened the very same project file and everything worked flawlessly as expected. Everything but the transparency on the tool bar.


Return to “Platform Related Issues”

Who is online

Users browsing this forum: No registered users and 3 guests