Winapi ウィンドウに問題があります。フルスクリーン モードで起動する可能性がある (必ずしもそうであるとは限りません) アプリがあります。だから、私がやっていることは次のとおりです。
- ウィンドウを作成
電話
ShowWindow(HWnd, SW_HIDE); UpdateWindow(HWnd);
ファイルから設定を読み取る
D3D レンダラーをリセットし、ウィンドウを調整し、可能であればフルスクリーンに切り替えて、呼び出します
SetWindowPos(HWnd, HWND_NOTOPMOST, posx, posy,sizex, sizey, SWP_SHOWWINDOW); ShowWindow(HWnd, SW_SHOW);
フルスクリーン モードではすべて問題ありませんが、アプリがウィンドウ モードで起動すると、ウィンドウがまったく表示されませんCreateWindowEx
。適切なウィンドウ ハンドルが返され、アプリはバックグラウンドで実行され、すべてが実行されますが、ウィンドウが見つかりません。私は何を忘れていますか?
編集
OK、いくつかの進歩。D3D レンダラーのリセット ルーチンの SetWindowPos が呼び出されていないことが判明しました。それを修正したところ、新しい問題が発生しました。ウィンドウは本来あるべき場所にありますが、完全に透明で、クライアント領域にはカーソル以外は何も表示されません。
フルスクリーンでは、すべて正常に動作します。アプリがフルスクリーンで起動し、ユーザーがウィンドウ表示に切り替えた場合もすべて問題ありません。
edit2
OK、ウィンドウに何もレンダリングされていない理由を特定できました -IDirect3DDevice9::BeginScene
メソッドが を返すD3DERR_INVALIDCALL
ので、D3D レンダラーのリセットに何か問題があるようです。
void VD3D9Renderer::Reset(bool windowed, ulong width, ulong height)
{
for (size_t i=0; i<Fonts.size(); i++)
Fonts[i]->Font->OnLostDevice();
if (FontMgr)
FontMgr->OnLostDevice();
for (VMap<VString, VD3D9Texture*>::iterator it = TextureMap.begin(); it != TextureMap.end(); it++)
{
VD3D9Texture* tex = it->second;
if (tex && tex->IsRenderTarget())
tex->TexturePtr->Release();
}
D3DD->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &BackBufferColor);
D3DD->GetDepthStencilSurface(&BackBufferDepthStencil);
if (BackBufferColor) BackBufferColor->Release();
if (BackBufferDepthStencil) BackBufferDepthStencil->Release();
bool change_fs = (windowed==true && D3DPP.Windowed == FALSE) || (windowed==false && D3DPP.Windowed == TRUE) ? true : false;
D3DPP.Windowed = windowed;
if (width) D3DPP.BackBufferWidth = width;
if (height) D3DPP.BackBufferHeight = height;
D3DD->Reset(&D3DPP);
RECT rc;
rc.left = 0;
rc.top = 0;
rc.right = D3DPP.BackBufferWidth;
rc.bottom = D3DPP.BackBufferHeight;
if (change_fs)
{
if(D3DPP.Windowed)
{
DWORD style = GetWindowLong(HWnd, GWL_STYLE);
DWORD exstyle = GetWindowLong(HWnd, GWL_EXSTYLE);
style = WS_CAPTION | WS_SYSMENU;
exstyle = 0;
int posx = (GetSystemMetrics(SM_CXSCREEN) - (rc.right-rc.left)) >> 1;
int posy = 0;
AdjustWindowRectEx(&rc, style, false, exstyle);
SetWindowLong(HWnd, GWL_STYLE, style);
SetWindowLong(HWnd, GWL_EXSTYLE, exstyle);
if(!SetWindowPos(HWnd, HWND_NOTOPMOST, posx, posy, rc.right, rc.bottom, SWP_SHOWWINDOW))
{
DWORD error = GetLastError();
VLog("Error in SetWindowPos: %u\n", error);
}
ShowWindow(HWnd, SW_SHOW);
}
else
{
DWORD style = GetWindowLong(HWnd, GWL_STYLE);
DWORD exstyle = GetWindowLong(HWnd, GWL_EXSTYLE);
style = WS_POPUP;
exstyle = 0;
int posx = (GetSystemMetrics(SM_CXSCREEN) - (width)) >> 1;
int posy = 0;
SetWindowLong(HWnd, GWL_STYLE, style);
SetWindowLong(HWnd, GWL_EXSTYLE, exstyle);
if(!SetWindowPos(HWnd, HWND_NOTOPMOST, posx, posy, rc.right, rc.bottom, SWP_SHOWWINDOW))
{
DWORD error = GetLastError();
VLog("Error in SetWindowPos: %u\n", error);
}
ShowWindow(HWnd, SW_SHOW);
}
}
else
{
if (rc.right > 0 && rc.bottom > 0)
{
DWORD style = GetWindowLong(HWnd, GWL_STYLE);
AdjustWindowRect(&rc, style, false);
int posx = (GetSystemMetrics(SM_CXSCREEN) - (rc.right-rc.left)) >> 1;
int posy = 0;
if(!SetWindowPos(HWnd, HWND_NOTOPMOST, posx, posy, rc.right, rc.bottom, SWP_SHOWWINDOW))
{
DWORD error = GetLastError();
VLog("Error in SetWindowPos: %u\n", error);
}
//SetWindowPos(HWnd, HWND_NOTOPMOST, posx, posy, rc.right, rc.bottom, SWP_SHOWWINDOW);
ShowWindow(HWnd, SW_SHOW);
}
}
for (VMap<VString, VD3D9Texture*>::iterator it = TextureMap.begin(); it != TextureMap.end(); it++)
{
VD3D9Texture* tex = it->second;
if (tex && tex->IsRenderTarget())
D3DD->CreateTexture(tex->Width, tex->Height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
D3DPOOL_DEFAULT, &tex->TexturePtr, NULL);
}
for (size_t i=0; i<Fonts.size(); i++)
Fonts[i]->Font->OnResetDevice();
if (FontMgr)
FontMgr->OnResetDevice();
ResetDeviceState();
}