Click here to Skip to main content
15,913,722 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to maimize the childframe?? Pin
Tcpip200525-Apr-05 16:59
Tcpip200525-Apr-05 16:59 
GeneralDSP Pin
vtalau24-Apr-05 19:06
vtalau24-Apr-05 19:06 
GeneralRe: DSP Pin
Alexander M.,25-Apr-05 3:13
Alexander M.,25-Apr-05 3:13 
GeneralRe: DSP Pin
vtalau25-Apr-05 6:41
vtalau25-Apr-05 6:41 
GeneralProperly using TCHAR Pin
Ista24-Apr-05 18:30
Ista24-Apr-05 18:30 
GeneralRe: Properly using TCHAR Pin
ThatsAlok24-Apr-05 18:49
ThatsAlok24-Apr-05 18:49 
GeneralRe: Properly using TCHAR Pin
Ista24-Apr-05 18:52
Ista24-Apr-05 18:52 
GeneralTrouble loading bitmap files Pin
Kieroshark24-Apr-05 13:48
Kieroshark24-Apr-05 13:48 
Hey, so I have been trying to load several bitmaps into a program I am writing.

I am using DirectDraw to display the graphics of this program. I want to load a bitmap from a .bmp file, then use the IDirectDrawSurface3::Blt method to display it.


First, according to a tutorial I am doing, I tried to write my own function to load a bitmap.

typedef struct BmpFile <br />
{<br />
	BITMAPFILEHEADER fileHeader;<br />
	BITMAPINFOHEADER infoHeader;<br />
	PALETTEENTRY pallete[256];<br />
	UCHAR *buffer;<br />
} BmpFile, *BmpFilePtr;<br />
<br />
<br />
int GraphicsEngine::LoadBitmapFile(BmpFilePtr bmp, char *fileName)<br />
{<br />
	HANDLE fileHandle = NULL;<br />
<br />
	if ((fileHandle = CreateFile(fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE)<br />
		return 401; // Error code: Could not open file.<br />
<br />
	// Load the bitmap file header.<br />
	if (!(ReadFile(fileHandle, &bmp->fileHeader, sizeof(BITMAPFILEHEADER), NULL, NULL)))<br />
	{<br />
		CloseHandle(fileHandle);<br />
		return GetLastError();<br />
	}<br />
<br />
/* Rest of function commented out - the program never gets to it. */



Whenever I run this, CreateFile appears to successfully load the file, and fileHandle is set to a value. Then the function ReadFile fails. GetLastError returns 998 (which is the code for: Invalid access to memory location. ERROR_NOACCESS). Sigh | :sigh:


I was pretty stumped by this, so I looked around a while, and I found a function called LoadImage().

I looked it up, and came up with the code
HBITMAP hbmp = (HBITMAP)LoadImage(NULL, fileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);

But I have a problem with this, too Dead | X| ; I have no idea how to get the BMP data out of the handle... I'm not using MFC, so I can't use CBitmap. Is there any other way of getting the data, so that I can put it on an IDirectDrawSurface and display it using Blt?

If anyone can help me solve either method of loading a bitmap, or if that's not feasible, instruct me in the use of a third method, I would be greatly appreciative.

Thanks for your help, everyone. Smile | :)

-----

I am a programar
I am a programer
I am a programor

I write code.
GeneralRe: Trouble loading bitmap files Pin
Ista24-Apr-05 18:25
Ista24-Apr-05 18:25 
GeneralRe: Trouble loading bitmap files Pin
Kieroshark25-Apr-05 13:27
Kieroshark25-Apr-05 13:27 
GeneralRe: Trouble loading bitmap files Pin
Ista25-Apr-05 13:31
Ista25-Apr-05 13:31 
GeneralSaving, Opening and possible conflicts Pin
Member 66746824-Apr-05 11:16
Member 66746824-Apr-05 11:16 
GeneralRe: Saving, Opening and possible conflicts Pin
PJ Arends24-Apr-05 11:37
professionalPJ Arends24-Apr-05 11:37 
GeneralRe: Saving, Opening and possible conflicts Pin
Member 66746824-Apr-05 11:46
Member 66746824-Apr-05 11:46 
GeneralRe: Saving, Opening and possible conflicts Pin
PJ Arends24-Apr-05 11:49
professionalPJ Arends24-Apr-05 11:49 
GeneralRe: Saving, Opening and possible conflicts Pin
Member 66746824-Apr-05 19:01
Member 66746824-Apr-05 19:01 
GeneralRe: Saving, Opening and possible conflicts Pin
PJ Arends25-Apr-05 6:58
professionalPJ Arends25-Apr-05 6:58 
QuestionShould I restrict my program's disk activity? Pin
IGx8924-Apr-05 11:01
IGx8924-Apr-05 11:01 
AnswerRe: Should I restrict my program's disk activity? Pin
PJ Arends24-Apr-05 11:12
professionalPJ Arends24-Apr-05 11:12 
GeneralRe: Should I restrict my program's disk activity? Pin
IGx8924-Apr-05 15:57
IGx8924-Apr-05 15:57 
AnswerRe: Should I restrict my program's disk activity? Pin
Michael Dunn24-Apr-05 21:16
sitebuilderMichael Dunn24-Apr-05 21:16 
GeneralProblem with reading an URL Pin
acroitoriu24-Apr-05 9:56
acroitoriu24-Apr-05 9:56 
GeneralRe: Problem with reading an URL Pin
Michael Dunn24-Apr-05 21:19
sitebuilderMichael Dunn24-Apr-05 21:19 
GeneralRe: Problem with reading an URL Pin
acroitoriu25-Apr-05 2:45
acroitoriu25-Apr-05 2:45 
GeneralRe: Problem with reading an URL Pin
Michael Dunn25-Apr-05 6:17
sitebuilderMichael Dunn25-Apr-05 6:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.