Front Office Football Central  

Go Back   Front Office Football Central > Archives > FOFC Archive
Register FAQ Members List Calendar Mark Forums Read Statistics

Reply
 
Thread Tools
Old 07-17-2004, 05:55 PM   #1
sabotai
General Manager
 
Join Date: Oct 2000
Location: The Satellite of Love
OT: MFC related Programming Question

I want to load small bitmap images of flags and display them.

Code:
// Load bitmap file to use HBITMAP hBitmap = (HBITMAP) ::LoadImage(NULL, "Afghanistan.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); // Set left corner control to display flag image m_FlagOne.SetBitmap(hBitmap); // Set right corner control to display flag image m_FlagTwo.SetBitmap(hBitmap);

m_FlagOne and m_FlagTwo are CStatic controls. The above code works fine. I have the Afghanistan.bmp file in the same directory as the .exe (or in the same directory as the code when running from VC++) and the image loads up and displays fine.

The problem comes when I do this:

Code:
// Load bitmap file to use HBITMAP hBitmap = (HBITMAP) ::LoadImage(NULL, "\Flags\Afghanistan.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);

(The two SetBitmap lines for the static controls stayed the same)

I create a subdirectory and place all of the flag images there and try to load one up. The above will not work. So I thought I had to provide the entire line, so to test it I created a directory call Flags at the C:\ and did this:

Code:
// Load bitmap file to use HBITMAP hBitmap = (HBITMAP) ::LoadImage(NULL, "C:\Flags\Afghanistan.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);

And it still won't work.

It would seem stupid to put 100+ flag images into the same directory as the .exe, and I don't want to have to load them all as resourses. Is there a better way to load bitmaps from file and be able to get them from a different directory?

sabotai is offline   Reply With Quote
Old 07-17-2004, 06:03 PM   #2
GoldenEagle
Grizzled Veteran
 
Join Date: Dec 2002
Location: Little Rock, AR
I am studying GDI functions right now. If I come across anything, I will let you know.
__________________
Xbox 360 Gamer Tag: GoldenEagle014
GoldenEagle is offline   Reply With Quote
Old 07-17-2004, 06:53 PM   #3
Marc Vaughan
SI Games
 
Join Date: Oct 2000
Location: Melbourne, FL
I've always used my own bitmap loading/rendering functions so aren't familiar with the ones you're using I'm afraid - first thought is that some string functions expect format information after a backslash character, ie. use of "\n" as a new line character etc. ... if this is the case in LoadImage then you'll need to use:

"C:\\Flags\\"

To define the directory, as if '\' is used as a format specifier the first one will be ignored by the system.

No idea if this will help or not (as I indicated I haven't used that function myself) ...

Marc
Marc Vaughan is offline   Reply With Quote
Old 07-17-2004, 07:01 PM   #4
sabotai
General Manager
 
Join Date: Oct 2000
Location: The Satellite of Love
Nah, didn't work. I have my own class that loads bitmaps too, but I'm not sure how I would use it with the CStatic class, or any other MFC control, so I just did it the way to book said to.
sabotai is offline   Reply With Quote
Old 07-17-2004, 09:48 PM   #5
gstelmack
Pro Starter
 
Join Date: Oct 2000
Location: Cary, NC
Do you care what OS you run on? Try the "CImage" class. But several functions use GDI+, so you may limit what it can run on (XP mainly).

Marc is right, you need to double-up backslashes when specifying strings, otherwise it thinks it's an escape character.

What does GetLastError() say?
__________________
-- Greg
-- Author of various FOF utilities
gstelmack is offline   Reply With Quote
Old 07-17-2004, 09:55 PM   #6
sabotai
General Manager
 
Join Date: Oct 2000
Location: The Satellite of Love
Actually, I just tried it out, and the double slash thing is working now. Thanks for the help. No idea why it didn't work the first time I tried it...probably some stupid mundane detail.

Thanks guys.
sabotai is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT -5. The time now is 01:38 PM.



Powered by vBulletin Version 3.6.0
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.