|

Win32/ FPC - Chapter 10 - by Delax
In the last chapter we used a resource file to link an icon into our application. Right now, only the Windows Explorer uses this icon for anything: it displays the icon next to the name of our executable. Now we use the icon in our application as well.
As you might remember, we defined an icon in our Window Class. Only that we didn't have an icon back then and just choose the default application icon. This time we point to our resource icon.
WinClass.hIcon := LoadIcon(system.MainInstance, makeintresource(1));
LoadIcon() loads an icon resource and makes it accessible to an application. As first parameter we have to define the handle of the application that has the icon stored. The second parameter is either the name of the icon or a resource can be used. But if you want to use a resource then you have to define it with makeintresource(). Remember that this 1 is the ID of our icon inside the resource file as we defined it in the resource script. So basically we load our icon with the ID 1 from our own application.
Because we are using an extended Window Class, we also have to define the hIconSm. This is the icon associated with the Window Class. It can either be set to nil (in which case it uses the icon from hIcon) or just contain the same icon again.
WinClass.hIconSm := LoadIcon(system.MainInstance, makeintresource(1));
And that's it. Our application now shows the icon in the icon bar next to start and it shows it in the top left corner of our window. It's that simple to use resources in an application. And the best thing is: it doesn't get real harder. Get the source code here. You also need the resource file from the last chapter.
Delax/ Sundancer Inc.
[delax@sundancerinc.de]
Back to previous page
|