![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
Q: Load bitmaps and icons from the programs's resourcesAnswer:This FAQ assumes that you have already bound your bitmaps or icons to your executable. If you need help adding bitmaps or icons to a project, see the FAQ on adding icons, cursors, and bitmaps to a BCB project. BitmapsTBitmap contains two functions called LoadFromResourceID and LoadFromResourceName that allow you to load bitmaps from the program's resources. Use LoadFromResourceID when the ID of your bitmap resource is an integer (the RC file example used numeric ID's). Use LoadFromResourceName when the bitmap's ID is a string. If you used the Image Editor to create a .RES file, you will need LoadFromResourceName because the Image Editor saves the resources using string IDs. Here are some code examples. // Loading a bitmap that uses numeric IDs. Graphics::TBitmap *bmp = new Graphics::TBitmap; bmp->LoadFromResourceID((int)HInstance,IDB_SPLASH); // Loading a bitmap that uses string IDs, like the // ones that the Image Editor creates. Graphics::TBitmap *bmp = new Graphics::TBitmap; bmp->LoadFromResourceName((int)HInstance,"Bitmap1"); // Loading a bitmap into a TImage control // using numeric IDs. Image1->Picture->Bitmap->LoadFromResourceID((int)HInstance,IDB_SPLASH);Note: You can also use API functions to load the bitmaps. Use the API LoadBitmap function and assign the result to the Handle property of TBitmap. Icons TIcon is the VCL class for working with icons. Unlike TBitmap, TIcon does not contain member functions to help you load the icon. You must use the API functions LoadIcon or LoadImage to load the icon into a TIcon object. LoadIcon is simpler to use, but it can only load 32 x 32 icons. If you use LoadIcon to load an icon of any other size, the API will enlarge or shrink the icon image to 32 x 32. LoadImage allows you to load icons of any size, but it takes more arguments. Here are some icon examples. // Load a 32 x 32 icon that uses an integer ID TIcon *icon = new Graphics::TIcon; icon->Handle=LoadIcon(HInstance,MAKEINTRESOURCE(ID_FOLDER_ICON)); // Load a 32 x 32 icon that uses a string ID TIcon *icon = new Graphics::TIcon; icon->Handle=LoadIcon(HInstance,"IconFolder"); // load a system icon TIcon *icon = new Graphics::TIcon; icon->Handle=LoadIcon(HInstance,IDI_EXCLAMATION); // Load a 16 x 16 icon that uses an integer ID TIcon *icon = new Graphics::TIcon; icon->Handle=LoadImage(HInstance, MAKEINTRESOURCE(ID_SMALL_FOLDER), IMAGE_ICON, 16,16, LR_LOADREALSIZE); // Load a 16 x 16 icon that uses a string ID TIcon *icon = new Graphics::TIcon; icon->Handle=LoadImage(HInstance, "SmallFolder"), IMAGE_ICON, 16,16, LR_LOADREALSIZE); //Load an icon directly into a TImage control Image1->Picture->Icon->Handle = LoadIcon(HInstance,IDI_EXCLAMATION); | ||||||
All rights reserved. |