Wxwidgets Resource Reads

Source: Internet
Author: User
Tags bool resource wxwidgets

The use of resources under VC, usually the first in the resource.h to define an integer, such as:

#define IDI_LIGHTNING_R 200//program icon

Then define this icon in Resource.rc:

Idi_lightning_r ICON "Icons\\lightning_r.ico"

When you read the icon, you use:

:: LoadIcon (H, Makeintresource (Idi_lightning_r));

Such a form. With wxwidgets also want to certainly do so, the result with

Pmainwnd->seticon (Wxicon (idi_lightning_r));

It doesn't work anyway.

Look at the next wxwidgetes code:

#define WXICON (X) Wxicon (WXT (#X))

Directly converts the Idi_lightning_r to a string, calling the Wxicon constructor.

wxIcon::wxIcon(const wxString& iconfile,
long flags,
int desiredWidth,
int desiredHeight)

{
LoadFile(iconfile, flags, desiredWidth, desiredHeight);
}

Look down LoadFile:

bool wxIcon::LoadFile(const wxString& filename,
long type,
int desiredWidth, int desiredHeight)
{
UnRef();

wxGDIImageHandler *handler = FindHandler(type);

if ( !handler )
{
// load via wxBitmap which, in turn, uses wxImage allowing us to
// support more formats
wxBitmap bmp;
if ( !bmp.LoadFile(filename, type) )
return false;

CopyFromBitmap(bmp);
return true;
}

return handler->Load(this, filename, type, desiredWidth, desiredHeight);
}

Well, look for the handler that reads the icon, and then use it to do the actual operation, the handler of the icon is done by the Wxicoresourcehandler class, see its Load method:

virtual bool Load(wxGDIImage *image,
const wxString& name,
long flags,
int desiredWidth, int desiredHeight)
{
wxIcon *icon = wxDynamicCast(image, wxIcon);
wxCHECK_MSG( icon, false, _T("wxIconHandler only works with icons") );

return LoadIcon(icon, name, flags, desiredWidth, desiredHeight);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.