求解,关于directX全屏的问题

wdl000001 2011-03-28 12:57:45
#pragma comment(lib,"dxerr.lib")
#pragma comment(lib,"dxguid.lib")
#pragma comment(lib,"d3dx9d.lib")
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"winmm.lib")
#pragma comment(lib,"comctl32.lib")

#include<windows.h>
#include<d3d9.h>
#include <tchar.h>
#include<d3dx9core.h>

#define SCREEN_WIDTH 1280
#define SCREEN_HEIGHT 960

//全局变量
LPDIRECT3D9 g_pD3D=NULL;
LPDIRECT3DDEVICE9 g_pd3dDevice=NULL;
LPD3DXFONT g_pFont = NULL;
WCHAR* str=L"DirectX游戏编程!";
RECT clientRect;

LRESULT CALLBACK MsgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);



//初始化
HRESULT InitializeD3D(HWND hWnd)
{
//创建对象
if(NULL==(g_pD3D=Direct3DCreate9(D3D_SDK_VERSION)))
return false;

//设置设备对象
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp,sizeof(d3dpp));
d3dpp.Windowed =0; // program fullscreen, not windowed
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // discard old frames
d3dpp.hDeviceWindow = hWnd; // set the window to be used by Direct3D
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; // set the back buffer format to 32-bit
d3dpp.BackBufferWidth = SCREEN_WIDTH; // set the width of the buffer
d3dpp.BackBufferHeight = SCREEN_HEIGHT; // set the height of the buffer

//创建设备对象
g_pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&g_pd3dDevice);

//创建字体对象
D3DXCreateFont(g_pd3dDevice,25,15,0,0,0,0,0,0,0,L"Arial",&g_pFont);
GetClientRect(hWnd,&clientRect);

return true;

}

VOID Render()
{
g_pd3dDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(100,50,150),1.0f,0);
g_pd3dDevice->BeginScene();
g_pFont->DrawTextW(NULL,str,-1,&clientRect,DT_LEFT|DT_TOP,D3DCOLOR_XRGB(250,250,250));
g_pd3dDevice->EndScene();
g_pd3dDevice->Present(NULL,NULL,NULL,NULL);
}

VOID Cleanup()
{
if(g_pFont!=NULL)g_pFont->Release ();
if(g_pd3dDevice!=NULL)g_pd3dDevice->Release();
if(g_pD3D!=NULL)g_pD3D->Release();

}


//消息处理
LRESULT WINAPI MsgProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
Cleanup();
PostQuitMessage(0);
return 0;

case WM_KEYUP:
switch(wParam)
{
case VK_ESCAPE:
Cleanup();
PostQuitMessage(0);
break;
}
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}




INT WINAPI WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR,INT)
{
HWND hWnd;
WNDCLASSEX wc;

ZeroMemory(&wc, sizeof(WNDCLASSEX));

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = MsgProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
// wc.hbrBackground = (HBRUSH)COLOR_WINDOW; // not needed any more
wc.lpszClassName = L"ClassName";

RegisterClassEx(&wc);

hWnd = CreateWindowEx(NULL,
L"ClassName",
L"Our Direct3D Program",
WS_EX_TOPMOST|WS_POPUP, // fullscreen values
0, 0, // the starting x and y positions should be 0
SCREEN_WIDTH, SCREEN_HEIGHT, // set the window to 640 x 480
NULL,
NULL,
hInstance,
NULL);

if(SUCCEEDED(InitializeD3D(hWnd)))
{
ShowWindow(hWnd,SW_SHOWDEFAULT);
UpdateWindow(hWnd);
}
MSG msg;
ZeroMemory(&msg,sizeof(msg));
while(msg.message !=WM_QUIT)
{
if(PeekMessage(&msg,NULL,0U,0U,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
Render();
}
}
UnregisterClass(L"ClassName",wc.hInstance );
return 0;
}


这个全屏程序,如果切换出去之后再切回程序,程序不会重新渲染,即使再切出程序,桌面也不能正常显示了,为什么啊
...全文
33 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧