GDI+ and DirectX

Started by
1 comment, last by Kasooi 19 years ago
I'm having a bit of a problem here... I'm trying to use GDI+ to load in .jpg images. What I'm doing is creating an off-screen surface:
int PlainSurface(LPDIRECTDRAWSURFACE *lpSource, int width, int height)
{
	DDSURFACEDESC ddsd;	// DirectDraw surface descriptor

	// set size parameter
	memset(&ddsd,0,sizeof(ddsd));
	ddsd.dwSize	= sizeof(ddsd);

	// set the flags
	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;

	// set dimensions of the new surface
	ddsd.dwWidth = width;
	ddsd.dwHeight = height;

	// what kind of offscreen surface
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;

	// Create the surface and check for error
	if(lpdd->CreateSurface(&ddsd, lpSource, NULL)!=DD_OK)
	{ /* error */ }

	return 0;
}

Now according to what I've learned, that should make an off-screen plain surface. It returns no errors so I'm supposing it is fine. My second part was to load the bitmap into that surface:
VOID image(const WCHAR *filename, IDirectDrawSurface *lpSurface)
{

lpSurface->GetDC(&hdc);
Graphics graphics(hdc);
Bitmap bitmap(filename);

graphics.DrawImage(&bitmap, 0, 0, bitmap.GetWidth(), bitmap.GetHeight());
lpSurface->ReleaseDC(hdc);
}

This is where I think I made mistakes. Then to combine the two,
int BitmapLoader(const WCHAR *filename, LPDIRECTDRAWSURFACE lpSurface, int width, int height) {
	PlainSurface(&lpSurface, width, height);
	image(filename, lpSurface);

	return 0;
}

Whenever I try to blt that from the surface to the primary, it never shows up. I'm not quite sure what I'm doing wrong though [sad]
Advertisement
First of all, are you using DirectX to create the window and then GDI to try to draw to it. If so, two things could be happening. I know in OpenGL, you have to set up the pixel format for your window in the intialization. You can specify how many bits for color, depth buffer, stencil buffer, and what is supported, usually if it is with a back buffer as well, etc... If DirectX needs to init this as well, then make sure to include the flag for GDI drawing as well. I'm not sure what the flag is because I never use it. The other problem is that if you are using only the main surface, no back buffer, then GDI must be setup to draw to the main surface, whereas if you are using a back buffer as well, GDI must be setup to draw to the back buffer. If you draw to the front, then when you flip the buffers, it gets erased by whatever is on the back buffer.


Quote:Original post by kburkhart84
First of all, are you using DirectX to create the window and then GDI to try to draw to it. If so, two things could be happening. I know in OpenGL, you have to set up the pixel format for your window in the intialization. You can specify how many bits for color, depth buffer, stencil buffer, and what is supported, usually if it is with a back buffer as well, etc... If DirectX needs to init this as well, then make sure to include the flag for GDI drawing as well. I'm not sure what the flag is because I never use it. The other problem is that if you are using only the main surface, no back buffer, then GDI must be setup to draw to the main surface, whereas if you are using a back buffer as well, GDI must be setup to draw to the back buffer. If you draw to the front, then when you flip the buffers, it gets erased by whatever is on the back buffer.


I initialized DirectX and am using GDI+ to draw to it. I set up all of the height, width, bits, etc.

And I haven't done any flipping just yet. Its a still surface right now.

Okay, I think I may know the problem, the flag I'm using is DDSCL_FULLSCREEN which stops GDI from drawing to it.
Is there any way to have my application full screen and allow GDI to draw to it?

This topic is closed to new replies.

Advertisement