Archived

This topic is now archived and is closed to further replies.

Gilzu

Q about DirectDraw in windowed mode...

Recommended Posts

i''m making an SDI app and want to have a surface as my edit board. anyway, i created a normal SDI thingy with CFormView as a child window and my oncreate func for the child win looks like:
  
int CMapEditorView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CFormView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	lpDD			=	NULL;
	lpDDSPrimary	=	NULL;

	// Create the DDraw7 object.

	if ( FAILED( DirectDrawCreateEx(NULL, (VOID**)&lpDD, IID_IDirectDraw7, NULL) ) ) {
		MessageBox("Failed to create DDraw device","DDraw",MB_OK);
		return FALSE;
	}

	// Set Cooperative Level

	if ( FAILED( lpDD->SetCooperativeLevel( AfxGetMainWnd()->GetSafeHwnd() , DDSCL_NORMAL) ) ){
		MessageBox("Failed to set cooperatve level","DDraw",MB_OK);
		return FALSE;
	}

	ZeroMemory( &ddsd, sizeof( ddsd ) );
	ddsd.dwSize = sizeof( ddsd );

	ddsd.dwFlags = DDSD_CAPS;
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

	// Create the primary surface using the description in

	// ddsd.

	if ( FAILED( lpDD->CreateSurface( &ddsd, &lpDDSPrimary, NULL ) ) ){
		MessageBox("Failed to create DDraw surface","DDraw",MB_OK);
		return FALSE;
	}

		
	return 0;
}
  
but the screen surface hadnt shown up. how do i attach the screen to the child view and let it show? Gil

Share this post


Link to post
Share on other sites
You need to make a secondary buffer and attach a DD7 clipper object using the hWnd of the target render window. And then blit it onto the primary buffer (in the OnPaint event for instance).

Magmai Kai Holmlor
- Not For Rent

Share this post


Link to post
Share on other sites

Hi Gilzu,
thanks for your post.
I am also very interested in implenting
ddraw in a windowed mfc app.I see your
code in this threat and it helps me alot.
Maybe you can tell me how you release the
direct draw surfaces and the ddraw object.
I mean the blabla->release stuff.
Where do you put the closing code
for direct draw.

Thanks in advance!

Bye

Zackie62

Share this post


Link to post
Share on other sites
quote:

Where do you put the closing code
for direct draw.


In the destructor of the object that created it is usually a decent spot.
    
CMyClass::~CMyClass()
{
if(m_pDD7)
m_pDD7->Release();
}


Alternatively, you can use a ATL template smartpointer and it will do this automatically.

  
#include "ATLBase.h"

CComPtr<IDirectDraw7> m_spDD7;


Magmai Kai Holmlor
- Not For Rent

Edited by - Magmai Kai Holmlor on November 3, 2001 12:34:41 PM

Edited by - Magmai Kai Holmlor on November 3, 2001 12:35:11 PM

Share this post


Link to post
Share on other sites
nice.

now what ive noticed, is that the clipper copies a rectangle
from the fullscreen mode, meaning, that when i draw a rect in (50,50,100,100)
and ill move the window, the rectangle coordinates remain absolute to
the screen. meaning that in relation to the screen it wont move.
any ideas how to overcome this problem?

Gil

p.s.
Zackie62: cool, np

Share this post


Link to post
Share on other sites

Hi Gilzu,
I have another question for you!
Where do you put the declarations?
I mean:
LPDIRECTDRAW7 lpdd;
LPDIRECTDRAWSURFACE7 lpddsprimary;
etc.

Thanks in advance!

Bye,
Zackie62

P.S.:Do you use the appwizard to create your app?

Share this post


Link to post
Share on other sites
if youll follow ms guidelines,
on your documentView classed (the class which you derive your document CView)
you should put all things related to whats in it, which in your case is all
the DDraw interfaces (lpDD, lpDDSPrimary and so on).
and in your CDocument derived class you put everything related to your saved document
and data.
when you wanna draw the document, use GetDocument() func to get the related
view data.

Gil

Share this post


Link to post
Share on other sites
Hi Gilzu,
I try to use ddraw and mfc together but
I don`t get it to work.
So I would be very happy if you could send
me the sourcecode of your working app.

Thanks in advance!

Bye,
Zackie62

Share this post


Link to post
Share on other sites