Original Post
I''m some what new to direct x. I''m trying to build a class to handle UI functions, direct draw in paticular. I wrote
a small function in a class to try to work out how to load a bitmap. I have compared my work with other code that
loads bitmaps and they look the same. Everything compiles and all the error checking I did doesn''t show any problems, but when I run the program the screen stays blank even odder is that when I pusk escape exit the program I get the image on the screen right befor it exits and ONLY when I exit. I''m going to put the header file and the function up here. IF you know what I''m doing wrong please tell me.
//header file
#include
#include
#include "resource.h"
class DSApp {
private:
LPDIRECTDRAW7 pDD;
LPDIRECTDRAWSURFACE7 pDDPrimary;
LPDIRECTDRAWSURFACE7 pDDBackbuffer;
DDSURFACEDESC2 surdic;
DDSCAPS2 ddscaps;
WNDCLASSEX DSAppClass;
HWND DSWnd;
MSG msg;
HINSTANCE hInstance;
public:
DSApp();
~DSApp();
void CreateDSWindow(short int, short int, char);
void Run(void);
void ShutDown(void);
void ShowBitmap(void);
};
// now the function
void DSApp::ShowBitmap(void) {
HBITMAP daydream;
BITMAP bm;
HDC DCImage;
HDC hdc;
HRESULT mine;
daydream =(HBITMAP)LoadImage(GetModuleHandle(NULL), "daydream.bmp", IMAGE_BITMAP,
0, 0, LR_LOADFROMFILE);//LoadBitmap(hInstance, "daydream.bmp");
if(daydream == NULL) {
MessageBox((HWND) NULL, "Error loading bitmap", "Error", MB_OK);
}
if(GetObject(daydream, sizeof(bm), &bm) == 0) {
MessageBox((HWND) NULL, "Error getting bitmap", "Error", MB_OK);
}
ZeroMemory(&surdic, sizeof(surdic));
surdic.dwSize = sizeof(surdic);
surdic.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; //| DDSD_WIDTH | DDSD_HEIGHT;
surdic.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
surdic.dwWidth = bm.bmWidth;
surdic.dwHeight = bm.bmHeight;
surdic.dwBackBufferCount = 1;
mine = pDD->CreateSurface(&surdic,&pDDPrimary , NULL);
ZeroMemory( &ddscaps, sizeof( ddscaps ) );
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
mine = pDDPrimary->GetAttachedSurface(&ddscaps, &pDDBackbuffer);
DCImage = CreateCompatibleDC(NULL);
if(!DCImage) {
MessageBox((HWND) NULL, "Error Loading bitmap into HDC", "Error", MB_OK);
}
SelectObject(DCImage, daydream);
if(FAILED(pDDPrimary->GetSurfaceDesc(&surdic))) {
MessageBox((HWND) NULL, "Error Getting surface description", "Error", MB_OK);
}
if(FAILED(pDDPrimary->GetDC(&hdc))) {
MessageBox((HWND) NULL, "Error getting image hdc", "Error", MB_OK);
}
if(BitBlt(hdc, 0, 0, surdic.dwWidth, surdic.dwHeight, DCImage, 0, 0, SRCCOPY) == FALSE) {
MessageBox((HWND) NULL, "Error Bliting bitmap", "Error", MB_OK);
}
}
I took out most of the error handleing and only showing the header and function to save space.
When all else fails, nuke them.