WxIcon

From WxWiki
Jump to navigation Jump to search

wxIcon

Note also that a Win32 .bmp will *not* correctly '.LoadFile()' into a WxBitmap ('unrecognized file format'), but *will* correctly load into a wxIcon (v 2.4.x).

Win32 .bmp load fine into samples/DialogEd, but not into IDE. Then again, the DialogEd sample is broken in 2.4.0, so what did you expect? (I don't understand this, is this still true? -ARN, 29th of June 2005)

On linux, XPM's are often used for icons with wxICON. The argument to pass to wxICON is the name of the xpm structure (look inside the xpm file) with `_xpm' appended to it. On Windows, wxICON takes the name of a resource which you need to link into your executable.

See also: Icon collections: Graphics

OSX - Create wxIcon from .icns file

On OSX one might find it useful to be able to create a wxIcon from an .icns file (for the same reasons you might want to do this from a .ico file on windows) It does not appear that there is any direct way to do this in wxWidgets currently, the below snippet of code is what I have used to achieve this. (Error handling etc. should be added as needed)

#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <Carbon/Carbon.h>
#include "wx/mac/private.h"
wxString sIconPath = wxT("MyIcon.icns");
wxIcon* pIcon = new wxIcon();
FSRef fsref;
if(FSPathMakeRef((UInt8*)(sIconPath.utf8_str().data(),&fsref,NULL)>=0)
{
	IconRef IconRef = NULL;
	RegisterIconRefFromFSRef('ANYT','HING', &fsref, &IconRef);
	pIcon->SetRefData(new wxIconRefData((WXHICON) IconRef));
}

misc SetIcon woes

Another issue I'm seeing with 2.4.0 is that SetIcon() won't work in some instances. No precise data on this one yet:

  • 2 back-to-back invocations of wxICON() will generate 2 Icons, both with the content (image) of the 2nd invocation, but with the correct pos & size,
  • in all instances, SetIcon() fails quietly,
  • occasionally, you get a zero-sized Icon on the screen (title shifted left),
  • SetIcon on a Frame works; on a Dialog, fails; on a View, fails; on a ChildFrame, fails.
                                                       aZhnaZg 6/1/03