Re: [Dev-C++] Loading a bitmap and getting its handle ???
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Gerson L. <ja...@ya...> - 2005-01-14 20:09:03
|
Hello.
As far as I know. there is no problem with making casts between Handles, put, they are not just pointers, I think there is some struct involved. So I recomend, not the simple casting, but the use of other API's functions. For example:
HDC GetDC(HWND);
instead of (HDC)hnd_Window, do this:
HDC hdc = GetDC(hnd_Window); and use it in the call to BitBlt.
In the case of the bitmap, try using HBITMAP instead of a HANDLE, I think a Handle is more like a long integer o somethig like that... I'm no sure about this.
But I'm sure thet HBITMAP corresponds to "HANDLE to BITMAP", son you'll be able to use it without casting in the call to BitBlt.
Your code may look like this:
void wndAnfang::drawSchein(){
HWND hnd_Window;
HBITMAP hnd_BMP;
if(hnd_Window = FindWindow("fltk", "AB-Sys")){
if(hnd_BMP = LoadImage(NULL, "F:\\Sources\\DevCpp\\Sys\\out\\Schein-Small.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)){
HDC hdc = GetDC(hnd_Window);
bool b = BitBlt(hdc, 0, 0, 300, 300, hnd_BMP, 0, 0, SRCCOPY);
DeleteObject(hnd_BMP);
ReleaseDC(hdc, hnd_Window);// this is important, only one trhead can have the DC of a window
// I'm not sure about the second parameter, but I'm sure about the name of the function.
message("%d %d %d",b,hnd_Picture,hnd_Schein);
}
}
}
I hope this may Help.
I'm working at this time with bitmaps an that stuff, but I'm no expert, so please, keep me up to date about your proyect, I can learn from you and I'm willing to help you.
Gerson.
A_B...@gm... wrote:
Thank you for the hint !!! :)
But now I have an other problem...
I get two different types of handles (HWND and HANDLE).
BitBlt needs for source and destination the handle type HDC.
So the only way to get this code to run seems to cast the two handles to HDC.
But BitBlt returns False and nothing is drawn to the window!
void wndAnfang::drawSchein(){
HWND hnd_Window;
HANDLE hnd_BMP;
if(hnd_Window = FindWindow("fltk", "AB-Sys")){
if(hnd_BMP = LoadImage(NULL, "F:\\Sources\\DevCpp\\Sys\\out\\Schein-Small.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)){
bool b = BitBlt((HDC)hnd_Window, 0, 0, 300, 300, (HDC)hnd_BMP, 0, 0, SRCCOPY);
DeleteObject(hnd_BMP);
message("%d %d %d",b,hnd_Picture,hnd_Schein);
}
}
}
Am 10 Jan 2005 um 13:51 hat OROSZI Balázs geschrieben:
>
> If you want to load a bitmap from a file (.bmp), then you have to look
> for an image library or write your own loader, as the Win32 API doesn't
> support loading bitmaps from files directly.
>
> It can load bitmaps from resources though. See LoadBitmap() for details.
>
> --
> Greetings,
> Balázs
---------------------------------
|