Front Office Football Central

Front Office Football Central (https://forums.operationsports.com/fofc//index.php)
-   FOFC Archive (https://forums.operationsports.com/fofc//forumdisplay.php?f=27)
-   -   OT: MFC related Programming Question (https://forums.operationsports.com/fofc//showthread.php?t=28066)

sabotai 07-17-2004 05:55 PM

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?

GoldenEagle 07-17-2004 06:03 PM

I am studying GDI functions right now. If I come across anything, I will let you know.

Marc Vaughan 07-17-2004 06:53 PM

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

sabotai 07-17-2004 07:01 PM

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.

gstelmack 07-17-2004 09:48 PM

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?

sabotai 07-17-2004 09:55 PM

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.


All times are GMT -5. The time now is 01:28 AM.

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