DX9 GetMessage FPS Drop

时间:2018-05-15 05:37:02

标签: directx directx-9

我的程序是游戏的透明叠加层 将其设置为游戏窗口的代码 setwindowtotarget在一个单独的线程中调用 我非常沮丧 此外,当我的fps计数器说我也超过200时,游戏感觉很迟钝

void SetWindowToTarget(){
while(true){
    tWnd = FindWindow(0, tWindowName);
    if (tWnd)
    {
        GetWindowRect(tWnd, &tSize);
        Width = tSize.right - tSize.left;
        Height = tSize.bottom - tSize.top;
        DWORD dwStyle = GetWindowLong(tWnd, GWL_STYLE);
        if(dwStyle & WS_BORDER)
        {
            tSize.top += 23;
            Height -= 23;
        }
        MoveWindow(hWnd, tSize.left, tSize.top, Width, Height, true);
    }
    Sleep(5000);
}

}

此代码使我的fps下拉,然后每隔10秒左右备份

while (GetMessage(&Message, NULL, 0, 0)){
    TranslateMessage(&Message);
    DispatchMessage(&Message);
}

LRESULT CALLBACK WinProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam){
Sleep(17);
switch (Message)
{   
case WM_PAINT:
    Render();
    break;

case WM_CREATE:
    DwmExtendFrameIntoClientArea(hWnd, &Margin);
    break;

case WM_DESTROY:
    PostQuitMessage(1);
    return 0;

default:
    return DefWindowProc(hWnd, Message, wParam, lParam);
    break;
}
return 0;

}

渲染功能:

int Render(){
p_Device->Clear(0, 0, D3DCLEAR_TARGET, 0, 1.0f, 0);
p_Device->BeginScene();

if(tWnd == GetForegroundWindow()){
    g_vCenterScreen.x = Width / 2.f;
    g_vCenterScreen.y = Height / 2.f;
//draw stuff
    }
}

p_Device->EndScene();
p_Device->PresentEx(0, 0, 0, 0, 0);
return 0;

}

0 个答案:

没有答案