Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Awwnelson

HDC and HBITMAP

This topic is 5612 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In Win32 API, is there any function that takes a handle to a device context and returns a handle to a bitmap? I''ve created a Blit function that scales and uses transparency, and I wanted to use it with text, but it takes a handle to a bitmap, and TextOut only writes to a device context. any suggestions? thanks.

Share this post


Link to post
Share on other sites
Advertisement
so, will that (creating a DIBSection instead of a DDB) allow me to write to the device context and have it actually affect the bitmap referred to by the handle? Or are you saying I can somehow use the function to get a handle to a bitmap out of the device context?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I think you asking if you can create an HDC to a memory bitmap that you can write to? You would want to create an hdc, possibly create a bitmap, and select a bitmap into the hdc.


hdcBitmap = CreateCompatibleDC(GetDC(hWnd));
hBitmap = CreateCompatibleBitmap(GetDC(hWnd),iWidth,iHeight);
hbOld = (HBITMAP)SelectObject(hdcBitmap,hBitmap);


I used the hdc from your window to create the bitmap to ensure color support (CreateCompatibleDC just greates an hdc to a single pixel monochrome bitmap). Alternatively you could select an existing bitmap, loaded with one of the bitmap loader functions, into the hdc created by CreateCompatibleDC(). You can then use the hdc as normal for any GDI functions and for using various GDI objects (brushes, pens, etc). This coule also be used as a double buffer, blitting it to your main window''s DC on every WM_PAINT message (simply call InvalidateRect at the end of any modification to the hdc to the memory bitmap or something like that).

Share this post


Link to post
Share on other sites
Actually, I''m trying to do the opposite: I want to take a handle to a device context that has bitmap information (because I used TextOut() to ''paint'' some text on it) and get a handle to a bitmap from that device context. I have a function that takes a handle to a bitmap that can blit with scaling and transparency, and I thought it would be nice if I could use that in my DrawText () function. (of course I could just copy the code over into the function, but that wouldn''t be as pretty )

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!