请问有没有人遇到SetLayeredWindowAttributes的LWA_COLORKEY之后窗口刷新率由144变为60这个问题?

创建分层窗口之后。

SetLayeredWindowAttributes(hwnd, RGB(0,0,0), 0, LWA_COLORKEY)窗口刷新率由144变为60。

但是如果用SetLayeredWindowAttributes(hwnd, 0, 255,LWA_ALPHA);则窗口的刷新率还是144.但是就不能有透明背景了,背景就是一片大黑。

这两个连着一起使用SetLayeredWindowAttributes(hwnd,RGB(0,0,0), 255, LWA_COLORKEY|LWA_ALPHA))也会变成60。

一个先用,一个后用也会变成60。

发现只要使用了LWA_COLORKEY就会改变刷新率到60。

在测试中又发现如果把窗口改的极小,大概是800*600的样子,设置LWA_COLORKEY就不会改变刷新率,还是144。

由于本人144的显示器,60hz刷新率着实令人蛋疼!

这个问题搞了十几天了,都没解决,希望各位大神能帮帮忙。

也许这对你们来说是一个小问题,但是这个问题对于小白的我真的很伤,有能绕过SetLayeredWindowAttributes,直接在DX中实现透明背景的方案也是可以的。

小白新号没有C币,只能表示万分感谢,默默祝福好人一生平安,全家幸福。

以下是全部代码,是以方框的移动速度来测试刷新率的。

#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment(lib,"d3d9.lib") 
#pragma comment(lib,"d3dx9.lib")

HWND hzwindowhwnd;
IDirect3D9Ex *pd3d = NULL;
LPDIRECT3DDEVICE9EX pdevice = NULL;
ID3DXLine* pd3dline = NULL;
D3DPRESENT_PARAMETERS d3dpp;
D3DDISPLAYMODEEX d3ddpl;

void initd3d() 

{
    Direct3DCreate9Ex(D3D_SDK_VERSION, &pd3d);
    ZeroMemory(&d3dpp, sizeof(d3dpp));

    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;

    d3ddpl.Width = 1778;
    d3ddpl.Height = 1000;
    d3ddpl.RefreshRate = 0;
    d3ddpl.Format = D3DFMT_A8R8G8B8;
    d3ddpl.Size = sizeof(D3DDISPLAYMODEEX);
    d3ddpl.ScanLineOrdering = D3DSCANLINEORDERING_PROGRESSIVE;

    pd3d->CreateDeviceEx(0, D3DDEVTYPE_HAL, hzwindowhwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, NULL, &pdevice);

    D3DXCreateLine(pdevice, &pd3dline);
    pd3dline->SetWidth(2);

    return;
}
void drawbox(float x, float y, float width, float height) 
{
    D3DXVECTOR2 points[5];
    points[0] = D3DXVECTOR2(x, y);
    points[1] = D3DXVECTOR2(x + width, y);
    points[2] = D3DXVECTOR2(x + width, y + height);
    points[3] = D3DXVECTOR2(x, y + height);
    points[4] = D3DXVECTOR2(x, y);

    pd3dline->Draw(points, 5, D3DCOLOR_ARGB(255, 255, 97, 0));
    return;
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT  uMsg, WPARAM wParam, LPARAM lParam)
{
    if (uMsg == 2) {  
    CloseHandle(th2);
    pd3dline->Release();
    pdevice->Release();
    pd3d->Release();
    PostQuitMessage(0);
    return 0; };
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
void begincreatewindows()
{
    WNDCLASSEXW chuankoucs;

    chuankoucs.cbClsExtra = 0;
    chuankoucs.cbSize = sizeof(WNDCLASSEXA);
    chuankoucs.cbWndExtra = 0;
    chuankoucs.hbrBackground = (HBRUSH)GetStockObject(5);
    chuankoucs.hCursor = 0;
    chuankoucs.hIcon = LoadIcon(0, IDI_SHIELD);
    chuankoucs.hIconSm = LoadIcon(0, IDC_WAIT);
    chuankoucs.hInstance = 0;
    chuankoucs.lpfnWndProc = WindowProc;
    chuankoucs.lpszClassName = L"begindraw";
    chuankoucs.lpszMenuName = 0;
    chuankoucs.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;

    RegisterClassExW(&chuankoucs);
    hzwindowhwnd = CreateWindowExW(WS_EX_LAYERED|WS_EX_TRANSPARENT, chuankoucs.lpszClassName, L"Pertect", WS_POPUP, 39, 37, 1778, 1000, 0, 0, 0, 0);

    //这里不管怎么设置,只要设置了LWA_COLORKEY就会变成60hz.
    SetLayeredWindowAttributes(hzwindowhwnd, RGB(0,0,255), 0, LWA_COLORKEY); 
    SetLayeredWindowAttributes(hzwindowhwnd, 0, 255, LWA_ALPHA);

    //这样也会变60hz;
    SetLayeredWindowAttributes(hzwindowhwnd, RGB(0,0,0), 255, LWA_COLORKEY|LWA_ALPHA);

    //如果只设置LWA_ALPHA,却还是144;但是就不能有透明背景了,背景就是一片大黑;
    SetLayeredWindowAttributes(hzwindowhwnd, 0, 255, LWA_ALPHA);


    ShowWindow(hzwindowhwnd, SW_SHOW);
    UpdateWindow(hzwindowhwnd);
    return;
}
int main()
{
    begincreatewindows();
    initd3d();

    float a = 0;
    int i(0);
    while (i<500) 
    {
        pdevice->Clear(0, 0, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,255),1, 0);
        pdevice->BeginScene();
        a = a + 1;
        drawbox(1 + a *2, 1 + a, 100, 52);
        pdevice->EndScene();
        pdevice->PresentEx(0, 0, 0, 0,0);
        i++;    
    }
    MessageBoxExW(0, 0, 0, 0, 0);

    MSG msg;
    while (GetMessage(&msg, nullptr, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }


    return (int)msg.wParam;

}

c++
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐