|
|

楼主 |
发表于 2008-7-22 06:19:00
|
显示全部楼层
Re:棘手的DX9框架问题(MFC)
我把代码发上来,帮忙看看错在哪里...
//H头文件(DX.h)
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance();
HRESULT Render();
};
class CMainWindow : public CFrameWnd
{
public:
CMainWindow();
protected:
DECLARE_MESSAGE_MAP();
};
//CPP文件 (DX.CPP)
#include <afxwin.h>
#include "d3d9.h"
#include "d3d.h"
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
#include "DX.h"
CMyApp myApp;
LPDIRECT3DDEVICE9 pd3dDevice;
LPDIRECT3D9 pD3D = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;
BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMainWindow;
d3dpp.BackBufferWidth = 800;
d3dpp.BackBufferHeight = 600;
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
pD3D->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
m_pMainWnd->m_hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&pd3dDevice
);
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
CMyApp::Render();
pD3D->Release();
return true;
}
HRESULT CMyApp::Render()
{
pd3dDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,255),1.0f,0);
if( SUCCEEDED(pd3dDevice->BeginScene()) )
{
pd3dDevice->EndScene();
}
return S_OK;
}
BEGIN_MESSAGE_MAP(CMainWindow,CFrameWnd)
//...
END_MESSAGE_MAP()
CMainWindow::CMainWindow()
{
Create(NULL,"The Hello Application",WS_OVERLAPPEDWINDOW,CRect(0,0,800,600));
} |
|