Re: [Dev-C++] Loading a bitmap and getting its handle ???
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <A_B...@gm...> - 2005-01-16 03:15:36
|
@Gerson Lara:
Well, for the window this is OK...
But not for the bitmap... It's a little bit more complicated, but you wher=
e on the right way... ;))
Meanwhile I solved the problem:
HBITMAP hbm =3D (HBITMAP)LoadImage( .... );
HDC hdcTarget =3D GetDC( hwndTargetWindow );
HDC hdcBitmap =3D CreateCompatibleDC( hdcTarget );
HBITMAP hbmOld =3D (HBITMAP)SelectObject( hdcBitmap, hbm );
BitBlt( hdcTarget, ...., hdcBitmap, ... , SRCCOPY );
// cleanup
SelectObject( hdcBitmap, hbmOld );
DeleteDC( hdcBitmap );
ReleaseDC( hdcTarget );
Thanks for all responses !!!!!!!!!!!!!
Am 14 Jan 2005 um 21:08 hat Gerson Lara geschrieben:
>
> 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 =3D 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 thin=
k 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 =3D FindWindow("fltk", "AB-Sys")){
> if(hnd_BMP =3D LoadImage(NULL, "F:\\Sources\\DevCpp\\Sys\\out\\Schein-S=
mall.bmp",
> IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)){
> HDC hdc =3D GetDC(hnd_Window);
>
> bool b =3D 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 ha=
ve 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 =3D FindWindow("fltk", "AB-Sys")){
> if(hnd_BMP =3D LoadImage(NULL, "F:\\Sources\\DevCpp\\Sys\\out\\Schein-S=
mall.bmp",
> IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)){
>
> bool b =3D 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=E1zs 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 detail=
s.
> >
> > --
> > Greetings,
> > Bal=E1zs
>
>
>
> Nuevo Correo Yahoo!
>
>
|