This commit is contained in:
EmsiaetKadosh
2025-01-14 22:33:05 +08:00
parent 4f455ca6ad
commit 2b7f05d928
14 changed files with 257 additions and 40 deletions
+75 -29
View File
@@ -1,47 +1,85 @@
#include "hbp.h"
#include "InteractManager.h"
#include "includes.h"
LRESULT __stdcall WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
_LIKELY
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);// Paint caption
BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
break;
}
_LIKELY
case WM_NCHITTEST: {
POINT point = { GET_X_LPARAM(lParam), (GET_Y_LPARAM(lParam)) };
ScreenToClient(hwnd, &point);
const int xPos = point.x;
const int yPos = point.y;
if (xPos < 30) {
if (yPos < 30) return HTTOPLEFT;
if (renderer.getHeight() - yPos < 30) return HTBOTTOMLEFT;
return HTLEFT;
}
if (renderer.getWidth() - xPos < 30) {
if (yPos < 30) return HTTOPRIGHT;
if (renderer.getHeight() - yPos < 30) return HTBOTTOMRIGHT;
return HTBOTTOM;
}
if (yPos < 30) return HTTOP;
if (renderer.getHeight() - yPos < 30) return HTBOTTOM;
if (yPos < 240) return HTCAPTION;
LRESULT lr = 0;
BOOL r = DwmDefWindowProc(hwnd, uMsg, wParam, lParam, &lr);
DwmDefWindowProc(hwnd, uMsg, wParam, lParam, &lr);
return HTCLIENT;
}
case WM_KEYDOWN: interactManager.update(static_cast<int>(wParam), true);
case WM_KEYDOWN:
interactManager.update(static_cast<int>(wParam), true);
break;
case WM_KEYUP: interactManager.update(static_cast<int>(wParam), false);
case WM_KEYUP:
interactManager.update(static_cast<int>(wParam), false);
break;
case WM_SYSKEYDOWN: interactManager.update(static_cast<int>(wParam), true);
case WM_SYSKEYDOWN:
interactManager.update(static_cast<int>(wParam), true);
break;
case WM_SYSKEYUP: interactManager.update(static_cast<int>(wParam), false);
case WM_SYSKEYUP:
interactManager.update(static_cast<int>(wParam), false);
break;
case WM_LBUTTONDOWN: interactManager.update(VK_LBUTTON, true);
case WM_LBUTTONDOWN:
interactManager.update(VK_LBUTTON, true);
break;
case WM_RBUTTONDOWN: interactManager.update(VK_RBUTTON, true);
case WM_RBUTTONDOWN:
interactManager.update(VK_RBUTTON, true);
break;
case WM_LBUTTONUP: interactManager.update(VK_LBUTTON, false);
case WM_LBUTTONUP:
interactManager.update(VK_LBUTTON, false);
break;
case WM_RBUTTONUP: interactManager.update(VK_RBUTTON, false);
case WM_RBUTTONUP:
interactManager.update(VK_RBUTTON, false);
break;
case WM_MOUSEMOVE: interactManager.updateMouse(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
case WM_MOUSEMOVE:
interactManager.updateMouse(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
break;
case WM_MBUTTONDOWN: if (wParam & 0x10) interactManager.update(VK_MBUTTON, true);
case WM_MBUTTONDOWN:
if (wParam & 0x10) interactManager.update(VK_MBUTTON, true);
break;
case WM_MBUTTONUP: interactManager.update(VK_MBUTTON, false);
case WM_MBUTTONUP:
interactManager.update(VK_MBUTTON, false);
break;
case WM_MOUSEWHEEL: interactManager.update(VK_MBUTTON, true);
case WM_MOUSEWHEEL:
interactManager.update(VK_MBUTTON, true);
interactManager.update(VK_MBUTTON, true);
break;
case WM_COMMAND: std::wcout << L"WM_COMMAND" << std::endl;
case WM_MOUSEHOVER:
// case WM_NCMOUSEHOVER:
interactManager.mouseHover();
break;
case WM_MOUSELEAVE:
// case WM_NCMOUSELEAVE:
interactManager.mouseLeave();
break;
case WM_COMMAND:
std::wcout << L"WM_COMMAND" << std::endl;
break;
case WM_DWMCOMPOSITIONCHANGED: {
MARGINS margins{
@@ -50,10 +88,11 @@ LRESULT __stdcall WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
.cyTopHeight = 0,
.cyBottomHeight = 0
};
HRESULT hr = RemoveDefaultCaption(hwnd, &margins);
RemoveDefaultCaption(hwnd, &margins);
break;
}
case WM_NCCALCSIZE: if (wParam == 1) {
case WM_NCCALCSIZE:
if (wParam == 1) {
NCCALCSIZE_PARAMS* pncsp = reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);
pncsp->rgrc[0].left = pncsp->rgrc[0].left + 0;
pncsp->rgrc[0].top = pncsp->rgrc[0].top + 0;
@@ -61,15 +100,19 @@ LRESULT __stdcall WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
pncsp->rgrc[0].bottom = pncsp->rgrc[0].bottom - 0;
return 0;
}
case WM_SIZE: switch (wParam) {
case WM_SIZE: {
renderer.resize(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
switch (wParam) {
case SIZE_RESTORED:
case SIZE_MINIMIZED:
case SIZE_MAXIMIZED:
case SIZE_MAXSHOW:
case SIZE_MAXHIDE:
default: break;
default:
break;
}
break;
}
case WM_ACTIVATE: {
constexpr MARGINS margins{
.cxLeftWidth = 0,
@@ -81,20 +124,22 @@ LRESULT __stdcall WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
}
break;
_UNLIKELY
case WM_DESTROY: PostQuitMessage(0);
case WM_DESTROY:
PostQuitMessage(0);
return 0;
_UNLIKELY
case WM_CREATE: SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);// Force post NCCALCSIZE
case WM_CREATE:
SetWindowPos(hwnd, nullptr, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);// Force post NCCALCSIZE
break;
default:
break;
default: break;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
int __stdcall wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
AllocConsole();
freopen("CONOUT$", "w", stdout);
WNDCLASSEX wc = { 0 };
ShowConsoleIO();
WNDCLASSEX wc = {};
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
@@ -111,8 +156,9 @@ int __stdcall wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCm
MainInstance = hInstance;
MainWindowHandle = CreateWindowExW(0, wc.lpszClassName, wc.lpszClassName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr, hInstance, nullptr);
ShowWindow(MainWindowHandle, nCmdShow);
Initialize();
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(109));
InteractManager::initialize();
Renderer::initialize();
HACCEL hAccelTable = LoadAcceleratorsW(hInstance, MAKEINTRESOURCE(109));
MSG msg = { nullptr };
while (GetMessageW(&msg, nullptr, 0, 0)) {
if (!TranslateAcceleratorW(msg.hwnd, hAccelTable, &msg)) {