October 18th, 2002, 04:14 PM
I've been looking around on MSDN and the internet and can't find how to draw bitmaps with GDI(not plus). All I want to know is the syntax for drawing a bitmap(from a resource or external file) to a device context at a given coordinate. Thanks for any help.
October 18th, 2002, 11:33 PM
October 19th, 2002, 01:07 PM
Yeah I found that much but how do I load and get a device context to a bitmap file or resource?
October 19th, 2002, 02:17 PM
You can load the image with LoadImage(), if loading from file, or LoadBitmap(), if loading from resource. Next, you need to get the device context for your current window, which you can obtain with GetDC(). After that, you have to create a compatible device context with GetCompatibleDC() and use BitBlt() to draw to it. The code would go something like this:
Please note that this code is off the top of my head and I did not test it. However, it ought to be pretty close to what you need. Don't forget to check MSDN for more information on the functions. Hope this helps! :D
HDC hDC, hDCBmp;
hBitmap = LoadBitmap(...) or (HBITMAP)LoadImage(...);
hDC = GetDC(hWnd);
hDCBmp = CreateCompatibleDC(hDC);
GetObject(hBitmap, sizeof(BITMAP), &bmp);
BitBlt(hDC,100,100, bmp.bmWidth,bmp.bmHeight, hDCBmp, 0,0, SRCCOPY);
October 19th, 2002, 04:47 PM
Thank you, i'll try it later.
October 23rd, 2002, 01:56 AM
This code snippet is a memory leak. The hBitmap will never be released as it is still selected into the HDC.
You can not delete a GDI object while it is selected into a HDC.
You must catch the returns of SelectObject() .
Before the function exits you must restore the HDC to its original resources and delete the created ones.
October 23rd, 2002, 06:42 AM
yeah thanks I noticed that too. I had found the LoadBitmap function in MSDN before but it said that it was depricated and I was wondering what is supposed to replace it?
October 23rd, 2002, 11:16 PM
The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.