Converting HANDLE to HBITMAP?
Hi! I''ve just read some of the topic in the Visual C++ Help and tried to load in some bitmaps.
I''m using LoadImage since it''s the only function that I saw that can easily change between bitmaps in a resource file and loading bitmaps from a file on disk.
The LoadImage function returns a HANDLE type. How do I convert this into HBITMAP to be used with GetObject?
Anyone know of a tutorial on loading bitmaps>
Just cast it.
hBitmap = (HBITMAP)LoadImage...
(I *think* that''s right--I think those GDI functions are so damned cludgy)
hBitmap = (HBITMAP)LoadImage...
(I *think* that''s right--I think those GDI functions are so damned cludgy)
I tried that, and when I do
hBitmap = (HBITMAP)LoadImage
GetObject(hBitmap, SIZEOF(BITMAP), Bitmap)
to get the Bitmap object (as I see in some examples), it gives an error stating I''m using the wrong parameters. So, I suppose casting it had something to do with it...
hBitmap = (HBITMAP)LoadImage
GetObject(hBitmap, SIZEOF(BITMAP), Bitmap)
to get the Bitmap object (as I see in some examples), it gives an error stating I''m using the wrong parameters. So, I suppose casting it had something to do with it...
GetObject? I must say that looks unfamiliar. I think this is how you''d load something with LoadImage:
HBITMAP hBitmap;
hBitmap = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_BITMAP1, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
if(hBitmap == NULL) MessageBox(hWnd, "Error loading bitmap", "LoadImage", MB_OK / MB_ICONERROR);
SelectObject(hDC, hBitmap);
...
DeleteObject(hBitmap);
hBitmap = NULL;
If you''re painting within WM_PAINT, obtain hDC from a call to BeginPaint, otherwise use GetDC(hWnd) (then ReleaseDC(hWnd, hDC)).
HBITMAP hBitmap;
hBitmap = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(IDB_BITMAP1, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
if(hBitmap == NULL) MessageBox(hWnd, "Error loading bitmap", "LoadImage", MB_OK / MB_ICONERROR);
SelectObject(hDC, hBitmap);
...
DeleteObject(hBitmap);
hBitmap = NULL;
If you''re painting within WM_PAINT, obtain hDC from a call to BeginPaint, otherwise use GetDC(hWnd) (then ReleaseDC(hWnd, hDC)).
Thanx for the tip! Well, I found this tutorial on the Net and it''s written there...
I''ll try that out, but just wondering (I haven''t yet explored it yet at the time of this writing thogh. I''ll try later), is it still possible to refer to the exact bits of data of the bitmap using this, i.e. obtain a pointer to the bitmap data?
I''ll try that out, but just wondering (I haven''t yet explored it yet at the time of this writing thogh. I''ll try later), is it still possible to refer to the exact bits of data of the bitmap using this, i.e. obtain a pointer to the bitmap data?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement