1

我正在使用自定义游戏引擎制作游戏,当您选择它创建的窗口时,它不允许您使用媒体键,例如更改音量或播放/暂停音乐或与窗口有关的任何操作,例如启动窗口menu 和 alt+tab 的行为很奇怪

感觉就像我的窗口正在“阻止”所有系统特定的键和命令

代码是用 C++ 编写的

这是我用于创建窗口的代码:

bool FrameWork::CreateDXWnd(int x, int y, int width, int height)
{
    HWND hwnd;
    WNDCLASSEX wc;

    m_hInstance = GetModuleHandle(nullptr);

    //setup window class with default setings:
    wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = m_hInstance;
    //wc.hIcon = LoadIcon(nullptr, IDI_WINLOGO);
    wc.hIcon = (HICON)LoadImage(m_hInstance, ".\\Assets\\Icons\\NgineIcon512.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
    wc.hIconSm = wc.hIcon;
    wc.hCursor = LoadCursor(nullptr, IDC_HAND);
    wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wc.lpszMenuName = nullptr;
    wc.lpszClassName = applicationName.c_str();
    wc.cbSize = sizeof(WNDCLASSEX);

    if (!RegisterClassEx(&wc))
    {
        Error(1);
        return false;
    }

    //Style of window
    //int nStyle = WS_OVERLAPPED | WS_SYSMENU | WS_VISIBLE | WS_CAPTION | WS_MINIMIZEBOX;
    int nStyle = WS_OVERLAPPED | WS_SYSMENU | WS_VISIBLE | WS_CAPTION | WS_MINIMIZEBOX;

    SettingsManager::GetInstance()->SetNativeResolution(GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));

    if (SettingsManager::GetInstance()->GetDisplayMode() == FULLSCREEN)
    {
        DEVMODE dmScreenSettings;
        memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
        dmScreenSettings.dmSize = sizeof(dmScreenSettings);
        dmScreenSettings.dmPelsWidth = (unsigned long)SettingsManager::GetInstance()->GetScreenWidth();
        dmScreenSettings.dmPelsHeight = (unsigned long)SettingsManager::GetInstance()->GetScreenHeight();
        dmScreenSettings.dmBitsPerPel = 32;
        dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

        ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
    }
    else
    {

    }
    if ((SettingsManager::GetInstance()->GetDisplayMode() == BORDERLESS))
    {
        hwnd = CreateWindowEx(WS_EX_APPWINDOW, applicationName.c_str(), applicationName.c_str(), WS_POPUP, x, y, SettingsManager::GetInstance()->GetScreenWidth(), SettingsManager::GetInstance()->GetScreenHeight(), nullptr, nullptr, m_hInstance, nullptr);
    }
    else
    {
        hwnd = CreateWindowEx(WS_EX_APPWINDOW, applicationName.c_str(), applicationName.c_str(), nStyle, x, y, SettingsManager::GetInstance()->GetScreenWidth(), SettingsManager::GetInstance()->GetScreenHeight(), nullptr, nullptr, m_hInstance, nullptr);

    }


    if (hwnd == nullptr)
    {
        Error(2);
        Ngine::GetInstance()->Release();
        PostQuitMessage(0);
        return false;
    }

    if (!Ngine::GetInstance()->InitGraphics(hwnd))
    {
        Error(hwnd, 30);
        Ngine::GetInstance()->Release();
        PostQuitMessage(0);
        UnregisterClass(applicationName.c_str(), m_hInstance);
        m_hInstance = nullptr;
        DestroyWindow(hwnd);

        return false;
    }

    Ngine::GetInstance()->GetGraphics()->SetHwnd(hwnd);

    ShowWindow(hwnd, SW_SHOW);
    SetForegroundWindow(hwnd);
    SetFocus(hwnd);

    return true;
}
4

1 回答 1

0

蒂姆。您显示的代码涉及创建窗口,而不是如何处理窗口的输入。要处理输入,您需要在代码中设置消息处理循环。

通常,在游戏引擎中,您将有一个主循环或“游戏循环”,每次通过循环通常会导致绘制一个帧。Game Loop 做的第一件事是处理窗口消息。这使您可以处理典型的 Windows 功能。然后,一旦您没有更多消息要处理,您将继续处理游戏的逻辑和渲染。

我建议您看一下Braynzarsoft 的教程。我链接的教程涉及设置窗口以及如何制作简单的 Windows 消息系统。

一旦您了解了其中的基础知识,您就可以在需要时完善您的帖子以获取更多信息。

于 2018-11-13T19:22:47.510 回答