gpt4 book ai didi

c++ - DirectX 窗口媒体键无响应

转载 作者:太空宇宙 更新时间:2023-11-04 12:42:52 24 4
gpt4 key购买 nike

我正在使用自定义游戏引擎制作游戏,当您选择它创建的窗口时,它不允许您使用媒体键,例如更改音量或播放/暂停音乐或任何与窗口有关的事情,例如获取 Windows 开始菜单和 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;
}

最佳答案

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

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

我建议你看看Braynzarsoft's tutorials .我链接的教程涉及设置窗口以及如何制作基本的 Windows 消息系统。

了解其基础知识后,您可以根据需要完善您的帖子以获取更多信息。

关于c++ - DirectX 窗口媒体键无响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53268876/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com