Sign in to follow this  

bmp's that wont load (-_-)

This topic is 3597 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

i am trying to run a very basic tetris clone and i have finally debugged it all and everything is working....well almost. the code runs fine no compile, linking or any other type of error is reported but all that i get when it opens is a blank window. i think maybe i have missed something when i imported the .bmp im using VC++ express 08 and at the moment all i have done to include the .bmp is add it to the Resource Files folder in the solution explorer...... if any one knows what i have done wrong please help me out, im dying to get this program working. thx in advance nath

Share this post


Link to post
Share on other sites
What functions do you use to load the bitmaps from the resource?

Fr standard GDI functions your bitmap can be any size, the D3DXCreateTextureFromResourceA will usually also be able to load any size.

Did you check the return values of the load functions?

Share this post


Link to post
Share on other sites
this is the load function that i am using for the program.

void bitMapObject::load(HDC hdcCompatible, LPCTSTR lpszFileName)
{
if (hdcMemory)
destroy();
hdcMemory = CreateCompatibleDC (hdcCompatible);
hbmNewBitMap = (HBITMAP)LoadImage(NULL, lpszFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
hbmOldBitMap = (HBITMAP)SelectObject (hdcMemory, hbmNewBitMap);
BITMAP bmp;
GetObject (hbmNewBitMap, sizeof(BITMAP), (LPVOID) &bmp);
iWidth = bmp.bmWidth;
iHeight = bmp.bmHeight;
}

this isnt my own code though im using it to learn from, so i
could easily have looked over something.

Share this post


Link to post
Share on other sites
Yes, you need to import the bmp file into your resources.

This will result in a resource-id (per default IDB_BITMAP1).

Now you need to call LoadImage like this:

(HBITMAP)LoadImage( InstanceHandle, MAKEINTRESOURCE( IDB_BITMAP1 ), IMAGE_BITMAP, 0, 0, 0 );


Don't forget that you now need to #include "resource.h" so the program knows about the IDB_BITMAP1 define.

Share this post


Link to post
Share on other sites
ok i have now tried that but vc++ isnt recognising the header file
"resource.h"

one other thing is that when you say "import the bmp file into your resources"
do you mean put the bmp into the resource file folder via add->new item
or am i meant to do it another way???

Share this post


Link to post
Share on other sites
Make sure that:
1. There actually exists a file called resource.h.
2. resource.h is in a path that is visible to the compiler.

Quote:
do you mean put the bmp into the resource file folder via add->new item

You need to add it to the actual resource file. It should have a .rc extension. There should already be one, just look for it in the Solution Explorer. Double click on it and you should get a Resource View window. You should see Bitmap in the tree. Right click and go to Add Resource...Bitmap...Import... and add your bitmap image.

Share this post


Link to post
Share on other sites
ok that would be where my problem is i have nothing with a .rc extension

im not sure if i did it correctly but i tried to create a new resource script
by right clicking the project folder and going to add...new item but i cant see any option to create a .rc file

what am i missing?

Share this post


Link to post
Share on other sites
Visual C++ 2005 express does not come with a resource editor. I am not sure about the 2008 version though.

You can easily get around this by creating your own "resource.rc" file, and adding it to your project.

Right click project name in solution explorer->Add->Existing Item to add your resource.rc file to your project.

---

On a side note, your bitmap loading routine does not load it from a resource, but from a file. Because of this, a resource script is NOT required if you are using your bitMapObject::load routine. as it is using the LR_LOADFROMFILE flag.

Share this post


Link to post
Share on other sites
While I know you are starting out, there's a useful library called DevIL that you might want to have a look at. Learning how to incorporate it into your project and so forth would be a useful lesson (and how to do that is all described in the documentation). Furthermore, for the simplest things -- loading an image is as easy as passing a filename ;)

Can get a bit more complex than that, but for quick and easy...why not?

~Shiny

Share this post


Link to post
Share on other sites
Hmmm, try writing an exception handler for a start so you actually know if the file is loading and you catch the exception if it isn't. In fact it's good practise to try and catch any sort of aberration so you know straight away where to start looking.

Although from what you said it sounds like it isn't finding it. I use VC 2008 which has no resource editor, but they're only txt files so easy to build. You can load graphics without one however. I hate resource files and create most of my resources on the fly at run time in the code. Even for dialogue boxes etc.

I would suggest the Forgers Tutorial to get you up and running. It can be found at:

www.winprog.org/tutorial/

It was my bible when I did my first few window programs.

m0ng00se

Share this post


Link to post
Share on other sites

This topic is 3597 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this