The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
GDI Question
Discuss GDI Question in the C Programming forum on Dev Shed. GDI Question C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 18th, 2002, 03:14 PM
|
|
Contributing User
|
|
Join Date: Apr 2001
Location: Bensalem PA
Posts: 58
Time spent in forums: < 1 sec
Reputation Power: 13
|
|
|
GDI Question
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, 10:33 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
|

October 19th, 2002, 12:07 PM
|
|
Contributing User
|
|
Join Date: Apr 2001
Location: Bensalem PA
Posts: 58
Time spent in forums: < 1 sec
Reputation Power: 13
|
|
|
Yeah I found that much but how do I load and get a device context to a bitmap file or resource?
|

October 19th, 2002, 01:17 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
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:
Code:
HDC hDC, hDCBmp;
HBITMAP hBitmap;
BITMAP bmp;
hBitmap = LoadBitmap(...) or (HBITMAP)LoadImage(...);
hDC = GetDC(hWnd);
hDCBmp = CreateCompatibleDC(hDC);
GetObject(hBitmap, sizeof(BITMAP), &bmp);
SelectObject(hDCBmp, hBitmap);
BitBlt(hDC,100,100, bmp.bmWidth,bmp.bmHeight, hDCBmp, 0,0, SRCCOPY);
DeleteObject(hBitmap);
DeleteDC(hDCBmp);
ReleaseDC(hDC);
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! 
|

October 19th, 2002, 03:47 PM
|
|
Contributing User
|
|
Join Date: Apr 2001
Location: Bensalem PA
Posts: 58
Time spent in forums: < 1 sec
Reputation Power: 13
|
|
|
Thank you, i'll try it later.
|

October 23rd, 2002, 12:56 AM
|
|
Offensive Member
|
|
Join Date: Oct 2002
Location: in the perfect world
|
|
|
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, 05:42 AM
|
|
Contributing User
|
|
Join Date: Apr 2001
Location: Bensalem PA
Posts: 58
Time spent in forums: < 1 sec
Reputation Power: 13
|
|
|
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, 10:16 PM
|
|
Offensive Member
|
|
Join Date: Oct 2002
Location: in the perfect world
|
|
|
LoadImage()
__________________
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.
Frank Zappa
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|