fICON


Quick Data

Header file:icon.h
Object name:fICON
Object index:1 of 1 Object

General Description

The fICON class is simply a class to hold a handle to an icon. You can then return the handle to this icon and do things with it. Nice, simple, easy. About the only advantage over manually loading an icon that this class offers would be that the functions provided by this class make this task slighlty easier.


Properties


Name Description

HICON Icon; This member is the Handle to the Icon, which is set when you load an icon. It is automatically destroyed when the class is destroyed. You can get the loaded icon from this function, or you can use the GetIcon() function (which is preferred). You can set this member if you so wish, but please destroy its contents first by calling DeleteObject(Class->Icon);.

Methods


Prototype Description

HICON GetIcon(void); This function returns the handle to the icon, which you can then use to pass along to other functions. Please note that it is preferred that you use this function to return the handle rather than referring to the Icon member of this class.
void LoadIconResource(char* Name, int ID); This function loads an icon from the current programs resources. You can specify either the name of the resource or it's ID number. If you use the ID, then you must pass NULL for Name, and if you use the Name, then you must pass 0 for ID.
void LoadIconResource(HINSTANCE Instance, char* Name, int ID); This function works like the above function except for the fact that it loads the icon from the resources found in the module specifed by Instance. In this way you can load a DLL and then extract an icon from that, by passing along the DLL's HINSTANCE.
void LoadIconFromFile(char* Filename); This function loads an icon from file, from the file specified by Filename. I shouldn't think that this function requires anymore explanation...
void SetIcon(HICON IconToSet); This function sets the icon from a HICON that you may have just had hanging around. Please note that this function will only copy the handle, so if you go and DeleteObject() the original handle, you will lose the Icon. However, once you have passed the handle to this class, you can use that handle again without needing to worry about deleting that icon, as this class will do that for you when it is destroyed.

Sample Code

The following snippet gives a basic idea of how to use this component.


//Create an instance of the object...
fICON TheIcon;

//Load an icon from the resources...
TheIcon.LoadIconResource("MainIcon", 0);
//Or load an icon by an ID number...
TheIcon.LoadIconResource(NULL, 0);

//Now get the icon's handle...
... = TheIcon.GetIcon();

//Of course, you could just load the icon from file...
TheIcon.LoadIconFromFile("C:\Directory\Icon.ico");

//Now, what if you want to get an icon from a DLL?
//You'll have to know what the name/ID is, but if you don't, then
//go and use the ExtractIcon() API.
HINSTANCE DllInstance = LoadLibrary("MyDll.dll");
TheIcon.LoadIconFromResource(DllInstance, "MainIcon", 0);
//And when you are done with the DLL...
FreeLibrary(DllInstance);

Back to indexThe FreeFoote Foundation Classes Documentation