If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Laurent Berger
Earned some good credits
Posts: 138 Joined: Tue May 20, 2008 1:03 pm
Post
by Laurent Berger » Fri Jun 29, 2018 12:09 pm
Hi,
I'm trying to get window icon previously by setIcon :
Code: Select all
wxIcon icon;
wxBitmap b(f->ImageAffichee()->Scale(64,64));
icon.CopyFromBitmap(b);
f->SetIcon(icon);
wxIcon ic2 = f->GetIcon();
wxIcon ic2 = f->GetIcon(); gives an empty icon but wxIcon is set. In debugger I don't understand this
https://github.com/wxWidgets/wxWidgets/ ... #L328-L346
flags is 1 and FALLBACK_NEAREST_LARGER is 2 then iconBest cannot be set and I get back nullIcon
How to solve this problem?
My icon is set :
windows 10 64 bits VS2017 wxwidgets master
Attachments
Capture.JPG (49.8 KiB) Viewed 1837 times
L.B.
doublemax
Moderator
Posts: 19160 Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2
Post
by doublemax » Sat Jun 30, 2018 12:43 am
You're setting a 64x64 icon. But GetIcon() will by default look for a 32x32 icon, which does not exist.
It's not clear to my why you use the "redirection" through the frame icon. Why don't you directly use the icon source?
Use the source, Luke!
Laurent Berger
Earned some good credits
Posts: 138 Joined: Tue May 20, 2008 1:03 pm
Post
by Laurent Berger » Sat Jun 30, 2018 7:02 am
icon in upper left corner of window is an image content rescaled. Image can be 3000x3000. I try to get this icon instead of rescaled twice. I think i will have to add this icon to my window class
L.B.
PB
Part Of The Furniture
Posts: 4204 Joined: Sun Jan 03, 2010 5:45 pm
Post
by PB » Sat Jun 30, 2018 8:49 am
BTW, in case you did not know, you can store (also) the same icon with different resolutions using
wxIconBundle . You can then call SetIcons with the resource bundle to set the icon for the frame.
See also
here why SetIcons() may be always superior to using SetIcon()/wxICON.
Laurent Berger
Earned some good credits
Posts: 138 Joined: Tue May 20, 2008 1:03 pm
Post
by Laurent Berger » Sat Jun 30, 2018 12:12 pm
thanks for yours answers
Code: Select all
wxBitmap b1(f->ImageAffichee()->Scale(64, 64));
wxBitmap b2(f->ImageAffichee()->Scale(30, 30));
wxBitmap b3(f->ImageAffichee()->Scale(16, 16));
wxIcon icon;
icon.CopyFromBitmap(b1);
wxIconBundle lotIcons(icon);
icon.CopyFromBitmap(b2);
lotIcons.AddIcon(icon);
icon.CopyFromBitmap(b3);
lotIcons.AddIcon(icon);
f->SetIcons(lotIcons);
get icon :
Code: Select all
wxIconBundle iconBundle = f->GetIcons();
wxIcon icon=iconBundle.GetIcon(wxSize(32, 32), wxIconBundle::FALLBACK_NEAREST_LARGER);
L.B.
PB
Part Of The Furniture
Posts: 4204 Joined: Sun Jan 03, 2010 5:45 pm
Post
by PB » Sat Jun 30, 2018 3:29 pm
Laurent Berger wrote: Code: Select all
wxBitmap b2(f->ImageAffichee()->Scale(30, 30));
Code: Select all
wxIcon icon=iconBundle.GetIcon(wxSize(32, 32), wxIconBundle::FALLBACK_NEAREST_LARGER);
(Assuming the code posted reflects the real code) Is 30 instead of 32 in the first part a typo or intent?
Laurent Berger
Earned some good credits
Posts: 138 Joined: Tue May 20, 2008 1:03 pm
Post
by Laurent Berger » Sat Jun 30, 2018 4:03 pm
PB wrote: Laurent Berger wrote: Code: Select all
wxBitmap b2(f->ImageAffichee()->Scale(30, 30));
Code: Select all
wxIcon icon=iconBundle.GetIcon(wxSize(32, 32), wxIconBundle::FALLBACK_NEAREST_LARGER);
(Assuming the code posted reflects the real code) Is 30 instead of 32 in the first part a typo or intent?
Yes it was. I checked flag wxIconBundle::FALLBACK_NEAREST_LARGER : result is a larger icon but there is a result.
L.B.