一个非常厉害的库,值得学习。
关于Dear Imgui处理窗口过程相关的笔记
//通过窗口过程来实现鼠标与imgui的交互
LRESULT __stdcall dWndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
//初始化相关逻辑
if (!settings.ImGuiInitialized)
return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam);
//当游戏窗口改变时,imgui窗口也改变
if (uMsg == WM_SIZE) {
WaitForSingleObject(DirectX::hRenderSemaphore, INFINITE);
if (pRenderTargetView) {
pRenderTargetView->Release();
pRenderTargetView = nullptr;
}
ReleaseSemaphore(DirectX::hRenderSemaphore, 1, NULL);
}
/*让imgui接收窗口过程,不传递给游戏(但是好像失败了,网上搜原因可能是因为
部分Unity游戏设计时对于接收鼠标和键盘输入使用了Input类,导致窗口过程中无法
通过此方法拦截,可以通过逆向来找到Input函数,然后通过hook来拦截)*/
if (ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam))
return true;
KeyBinds::WndProc(uMsg, wParam, lParam);
//当窗口显示时显示原始鼠标指针,用来与窗口交互
if (KeyBinds::IsKeyPressed(settings.KeyBinds.Toggle_Menu))
{
settings.bShowMenu = !settings.bShowMenu;
if (settings.bShowMenu) {
while (ShowCursor(TRUE) < 0);
ClipCursor(NULL);
}
else {
while (ShowCursor(FALSE) >= 0);
}
}
return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam);
}