|
Free Educational Resource Center for teachers and students. Includes Interviews, Sourcecode, Free Software, Research Papers, Articles, Tutorials and much more.. |
R E S E A R C H A C T I V I T Y . C O M
Our Fellow Research Center for Ph.D Schollars |
|
| Home About Submit & Earn | Archives: C And C + + Programming » Dev Packages » Interviews » Php Mysql Programming » Windows Programming | |
|
Windows Programming > using static control as image display box in winapi
Using Static Control As Image Display Box ![]() This is a very short tutorial (a kick start), to give you idea of loading adding images to your projects. It is very simple to load image at runtime either from external image file or resources, or even from another dll or ocx file. NOTE: this article to specific to windows BMP files only In following example I will be using a 'STATIC' as our image container, to get rid of painting routine we have to write if we go from scratch. Once you have loaded an image that is kept in a variable of type HBITMAP, it is your responsibility to draw it on surface (client area) when window is repainted by system, that is the reason we are using 'STATIC' type of control that is capable of displaying image over it, and handles the bitmap painting itself. I hope you are familiar with functions CreateWindow and CreateWindowEx, if not then consult msdn, one of these is being used in the supplied complete example. Besides here is the code to create the static that can hold a bitmap in it:
Ok what we have to do first, is 1. load the image, we are now loading image from external file
check if the image was really loaded or not, the HBITMAP variable will be NULL if the imageis NOT loaded.
2. Then if loading image from resource of your application, at runtime: Two conditions basically, a.if you have named the bitmap resource as a string in resources b.if you have assigned an integeral id to your bitmap resurce Assume it was a string "ABC"
Assume it was an integer id 123
Now it is time to assign that bitmap to a static control:, where myBox is the HWND type handle of the static control.
Troubleshooting: You might face unexpected drawn lines over your static control, when you resize it at runtime, to revent this kind of default behavior, change the class style of the static control: SetClassLong(myBox ,GCL_STYLE,CS_HREDRAW | CS_VREDRAW); which will not let the contained bitmap distrubed when resized. And here goes the complete example:
loadimage_winapi.cpp:1245:8 |