Ok, so you have your image in your resources.... That needs a slight change in procedure as we now need to load the image from your application instance instead of a disk file.
First step all the way back to your program entry point...
Make a global variable from the hInstance parameter. Generally I put this, the main window handle and other frequently used bits. into a small global.h header that I include in all project source files.
Code:// global.h
#ifndef PROJ_GLOBAL
#define PROJ_GLOBAL
HINSTANCE gInst;
HWND hMain;
// other globals here
#endif // PROJ_GLOBAL
Despite the common prohibition against global variables, this is far better than the time wasting alternative of having to rediscover the program's instance handle in 750 different places in your code.Code:// program .c file...
#include "global.h"
// entry point
INT CALLBACK WindMain(HINSTANCE hInst, HINSTANCE pInst, LPSTR CLine,INT CShow)
{ gInst = hInst;
// and the rest
return 0; }
Now for the image problem....
Which you would call as...Code:// top of dialog.c
#include "global.h"
// and to load the image
BOOL SetStaticImg(HWND Dlg, INT Item, INT ImageFile)
{ HANDLE img;
img = LoadImage(gInst, MAKEINTRESOURCE(ImageFile), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
if (!img)
return FALSE;
SendDlgItemMessage(Dlg,Item,SCM_SETIMAGE,IMAGE_BITMAP,(LPARAM)img);
return TRUE; }
What necessitates all that change is that with the image in the resources it is actually part of your program. You need to tell LoadImage where to look (first parameter) as well as the resource ID of the image...Code:If (! SetStaticImg(HDialog,IDC_STATIC, IDB_BITMAP) )
Beep(1000,250);
Yes, the Beep is a diagnostic you will want to take out later. It will screech at you if it fails to load the image.
Novacain also makes a good point that with this construct, if you are setting that image more than once, you should free the previous image from the static control... So...
Like I said... you may need to do more work on this.Code:BOOL SetStaticImg(HWND Dlg, INT Item, INT ImageFile)
{ HANDLE img; // new image
HANDLE pimg; // previous image
img = LoadImage(gInst, MAKEINTRESOURCE(ImageFile), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
if (!img)
return FALSE;
pimg = (HANDLE) SendDlgItemMessage(Dlg,Item,SCM_SETIMAGE,IMAGE_BITMAP,(LPARAM)img);
if (pimg)
DeleteObject(pimg);
return TRUE; }