Advertisement

Big MFC and DX8 Question!!

Started by December 15, 2000 12:23 PM
20 comments, last by thekid 24 years, 1 month ago
Ok I do know what I am doing but This is the first time I have tryed to get dx to work in an MFC Wizard created app.

I think the CView I am using is CEditView I put my dx init code in the default constructor for my View Class I put my begin and end scene code in the OnDraw function and my dx shutdown code in the default destructor.

When I run the app it just does what I does before I add the dx code its pretty much a text editor the window is white and i can type in it not a black dx window like I want.

is that a little better? I do know quite a bit about OO programming but MFC is a little confusing to me tho I have read a book about it it still mystifies me maybe I am missing something?

Thanx.
Why use a CEditView? just use the default CView.
Are you actually blitting the back buffer to the window, and have you got the correct window handle for the view?
Are any of the DX functions failing?
Advertisement
k I changed the View type to CView and I get DX now but the program crashes when I clear is there something i have to do here?
I don''t know what you mean by when you clear. And what is causing the crash?
Ok I have figured out that the program is crashing on my createdevice call here is the setup code I have am I missing something:

if(NULL == (pD3D8 = Direct3DCreate8( D3D_SDK_VERSION ) ) ){
MessageBox(_T("error1"),_T("error"),MB_OK);
return;}

// get the D3D8 display mode
if(FAILED (pD3D8->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &D3Ddm) ) ){
MessageBox(_T("error2"),_T("error"),MB_OK);
return;}


// set the D3D8 display parameters
ZeroMemory(&D3Dpp,sizeof(D3Dpp));
D3Dpp.Windowed = TRUE;
D3Dpp.hDeviceWindow = CView::m_hWnd;
D3Dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
D3Dpp.BackBufferFormat = D3Ddm.Format;

// now create the D3D8 device
if(FAILED (pD3D8->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,CView::m_hWnd ,D3DCREATE_SOFTWARE_VERTEXPROCESSING, &D3Dpp, &pD3Ddevice8 ) ) ){
MessageBox(_T("error3"),_T("error"),MB_OK);
return;}
I think you''re supposed to use GetSafeHwnd (or something like that - don''t have the docs up) instead of using m_hWnd. And CView is the base class, not your derived view class.
Advertisement
It still isnt working I Tried both GetSafeHwnd and myderived class but it still will not give me a device. do I need to set any thing in the precreatewindow function or do I need to get a target surface or something?
Where are you calling the CreateDevice from. The window should be open before you do this.
here is my code:

int CGEditorV1View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;

// TODO: Add your specialized creation code here

// get D3D8
if(NULL == (pD3D8 = Direct3DCreate8( D3D_SDK_VERSION ) ) ){
MessageBox(_T("error1"));return 0;}

// get the D3D8 display mode
if(FAILED (pD3D8->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &D3Ddm) ) ){
MessageBox(_T("error2"));return 0;}

// set the D3D8 display parameters
ZeroMemory(&D3Dpp,sizeof(D3Dpp));
D3Dpp.Windowed = TRUE;
D3Dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
D3Dpp.BackBufferFormat = D3Ddm.Format;

if(!CGEditorV1View::m_hWnd)
MessageBox(_T("error4"));

// now create the D3D8 device
if(FAILED (pD3D8->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, CGEditorV1View::m_hWnd ,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &D3Dpp, &pD3Ddevice8 ) ) ){
MessageBox(_T("error3"));return 0;}

return 1;
}


this code doesnt seem to be working my base class is CView btw

hello? can anyone help me I really need to solve this!

This topic is closed to new replies.

Advertisement