我本想把 ImGui 创建窗口部分交由别的语言进行创建,可创建后的效果不理想.
无论我进行怎样的按键/鼠标操作都无法使UI"动起来".不知是哪里出了问题.
// C++代码中创建窗口部分
windowClass.cbSize = sizeof(WNDCLASSEXA);
windowClass.style = CS_CLASSDC;
windowClass.lpfnWndProc = WindowProcess;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = GetModuleHandleA(0);
windowClass.hIcon = 0;
windowClass.hCursor = 0;
windowClass.hbrBackground = 0;
windowClass.lpszMenuName = 0;
windowClass.lpszClassName = className;
windowClass.hIconSm = 0;
RegisterClassExA(&windowClass);
window = CreateWindowEx(WS_EX_TOPMOST | WS_EX_LAYERED | WS_EX_TOOLWINDOW,
className,
windowName,
WS_POPUP,
CW_USEDEFAULT,
CW_USEDEFAULT,
WIDTH,
HEIGHT,
NULL,
NULL,
GetModuleHandle(NULL),
NULL);
UpdateWindow(window);
ShowWindow(window, SW_SHOWDEFAULT);
SetLayeredWindowAttributes(window, 0, 255, LWA_ALPHA);
// 消息循环部分
if (ImGui_ImplWin32_WndProcHandler(window, message, wideParameter, longParameter))
return true;
switch (message)
{
case WM_SIZE: {
if (gui::device != NULL && wideParameter != SIZE_MINIMIZED)
{
gui::presentParameters.BackBufferWidth = LOWORD(longParameter);
gui::presentParameters.BackBufferHeight = HIWORD(longParameter);
gui::ResetDevice();
}
}return 0;
case WM_SYSCOMMAND: {
if ((wideParameter & 0xfff0) == SC_KEYMENU)
return 0;
}break;
case WM_DESTROY: {
PostQuitMessage(0);
}return 0;
case WM_LBUTTONDOWN: {
gui::position = MAKEPOINTS(longParameter);
}return 0;
case WM_MOUSEMOVE: {
if (wideParameter == MK_LBUTTON)
{
const auto points = MAKEPOINTS(longParameter);
auto rect = ::RECT{ };
GetWindowRect(gui::window, &rect);
rect.left += points.x - gui::position.x;
rect.top += points.y - gui::position.y;
if (gui::position.x >= 0 &&
gui::position.x <= gui::WIDTH &&
gui::position.y >= 0 && gui::position.y <= 19)
SetWindowPos(
gui::window,
HWND_TOPMOST,
rect.left,
rect.top,
0, 0,
SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOZORDER);
}
}return 0;
}
return DefWindowProcW(window, message, wideParameter, longParameter);