-
displaying graphic
I know how to display a graphic on my window using a resource file, but now I want to display a bitmap from the hard drive...like non-resource. Im sure I could find an API for it but I thought I'd ask you guys first before waisting hours and hours on msdn :cool:
-
You can use LoadImage :-)
-
heh this is why I asked...I'd find that within about 6 hours on msdn :p
thanks mike I'll give that one a shot :)
-
msdn is so damned confusing! :mad: if you have a few minutes to spair could you write an example line? :confused:
-
I have approximately 0 minutes spare, since I'm at work and then have to get straight back to do a concert *sigh*.
The perils of being musical :p
-
Im lucky if I can stay with the beat of the music playing on my computer :p thanks and have fun! :D
-
I have time to spare:
Load a bmp file to a bitmap handle:
Code:
HBITMAP hBmp = LoadImage(NULL, "myfile.bmp", IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_LOADFROMFILE);
Then you can draw the bitmap using DrawState, or you can use it as a brush pattern or insert it into a device context...
If you have
#define STRICT
before you include windows.h you'll have to add
(HBITMAP)
before the LoadImage call.
-
I got an error:
initializing' : cannot convert from 'void *' to 'struct HBITMAP__ *'
and how would I put this on the screen? could BitBlt do it? I haven't been getting BitBlt to work :(
-
I told you. If you have #define STRICT before including windows.h (or if you are using MFC), you need to write it like this:
HBITMAP hBmp = (HBITMAP)LoadImage(...
Write it like this even if you don't have the define, because it doesn't hurt and will correct the failure.
I told you the second thing too.
a) DrawState
Code:
DrawState(hdc, NULL, NULL, MAKELONG(hBmp, 0), 0, x, y, 0, 0, DST_BITMAP | DSS_NORMAL);
b) select it into a dc, you can then use BitBlt
Code:
// get width and height of bitmap for blt operation
BITMAP bmp;
GetObject((HGDIOBJ)hBmp, sizeof(BITMAP), &bmp);
HDC hMemDC = CreateCompatibleDC(hdc);
SelectObject(hMemDC, (HGDIOBJ)hBmp);
BitBlt(hdc, x, y, bmp.bmWidth, bmp.bmHeight, hMemDC, 0, 0, SRCCOPY);
-
perfect! :D thanks cornedbee! :D