Jump to content
  • Advertisement
Sign in to follow this  
Servant of the Lord

Graphics in Win32

This topic is 4451 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 my program, I've got just about everything finished(thanks to helpful GD'ers), but I can't figured out how to get graphics on the screen. I've viewed several tutorials and browesed the web for answers, somewhat, as well as checked MSDN on various occasions, but I can't get it to work. Either it doesn't compile, or it doesn't paint it at run time. Could someone explain to me how it is done, or point me in the direction of more tutorials to view? I would prefer to know how to apply HBITMAPS after loading them from a resource file, as that's easiest for me to organize. Many thanks,

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I don't think you've tried going through the samples. On win32, there are over a million of them. You've got to stop relying on other people to do your work and learn to use google.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
I don't think you've tried going through the samples. On win32, there are over a million of them. You've got to stop relying on other people to do your work and learn to use google.


I have, but it just hasn't been working, the tutorials I went to I just couldn't understand. Hence why, I asked for help OR more tutorials so I could view those.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Now you are lying. Anyway if you can't figure out how to make basic API calls even with copious amounts of information on the internet I'm afraid this is the end of the ride for you.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Now you are lying. Anyway if you can't figure out how to make basic API calls even with copious amounts of information on the internet I'm afraid this is the end of the ride for you.


Where am I lying? Did I not just repeat what I said in my previous post? If you read it closely, I said, and I quote, "I've viewed several tutorials and browesed the web for answers, somewhat, as well as checked MSDN on various occasions, but I can't get it to work. Either it doesn't compile, or it doesn't paint it at run time. Could someone explain to me how it is done, or point me in the direction of more tutorials to view?"

I have been trying to do it myself alot already. And have already got the majority of the application going, through the use of theForger's tutorials and MSDN. I asked for help on a few things I didn't understand and got response, which I inputed myself. I'm not copying my code here and asking for people to make my programs for me, I'm wanting to know how it's done, that I can do it myself.

Do you know of a tutorial that could help me? I already know how to make it paint at the correct moments with WM_PAINT notifcation, and how to load HBITMAPS into the resource or during runtime, but I can't get them to display correctly. I know of BitBlt, but it's these HDC's and SelectObjects that throw me.

Share this post


Link to post
Share on other sites
For instance, here's the code snippet from theForger's tutorial, but I get errors in compilation when I alter it for my own use.

    case WM_PAINT:
{
BITMAP bm;
PAINTSTRUCT ps;

HDC hdc = BeginPaint(hwnd, &ps);

HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall);

GetObject(g_hbmBall, sizeof(bm), &bm);

BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);

EndPaint(hwnd, &ps);
}
break;






This line:
HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall);

Gives me some error about invalid conversions from void* to HBITMAP_* in the second parameter, when I use my own HBITMAP in it. I checked MSDN, and it tells me I can't use SelectObject() unless the HBITMAP was created in a specific way.

Quote:
From MSDN
The specified object must have been created by using one of the following functions. Object Functions:
 
Bitmap - CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap,
CreateDIBitmap, CreateDIBSection
(Bitmaps can be selected for memory DCs only, and for only one DC at a time.)


I'm not creating my bitmaps that way, I'm loading them from a resource like this:
HBITMAP MyBitmap = LoadBitmap(GetModuleHandle(NULL),MAKEINTRESOURCE(BITMAP_BLANK));

So I checked for tutorials on using resourced bitmaps in bitblting, but I can't find one.

Share this post


Link to post
Share on other sites
My tutorials are written in C. Since you're using C++ you'll have to abide by stricter type rules. That's why this line

HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall);

gives a compile error. SelectObject() returns and HGDIOBJ. You have to cast this to an HBITMAP.

As for the MSDN on SelectObject(), that article is incorrect. LoadBitmap() or LoadImage() work just fine with BitBlt().

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!