使用GET_X_LPARAM和GET_Y_LPARAM宏

This commit is contained in:
Nanako 2025-04-04 15:21:15 +08:00
parent 3999bccf6e
commit bd26423cb6

View File

@ -3,6 +3,7 @@
#include "platform_window/platform_window.h"
#include <windows.h>
#include <windowsx.h>
#define WINDOW_HANDLE static_cast<HWND>(window_handle_)
@ -40,14 +41,14 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// 窗口移动事件
if (uMsg == WM_MOVE) {
if (const auto window = get_window_from_hwnd(hwnd)) { window->on_move(LOWORD(lParam), HIWORD(lParam)); }
if (const auto window = get_window_from_hwnd(hwnd)) { window->on_move(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); }
processed = true;
}
// 窗口大小改变事件
if (uMsg == WM_SIZE) {
if (const auto window = get_window_from_hwnd(hwnd)) {
window->on_resize(LOWORD(lParam), HIWORD(lParam));
window->on_resize(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
}
processed = true;
}
@ -55,8 +56,8 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// 鼠标移动事件
if (uMsg == WM_MOUSEMOVE) {
if (const auto window = get_window_from_hwnd(hwnd)) {
const int x = LOWORD(lParam);
const int y = HIWORD(lParam);
const int x = GET_X_LPARAM(lParam);
const int y = GET_Y_LPARAM(lParam);
const Eigen::Vector2f pos(static_cast<float>(x), static_cast<float>(y));
window->handle_mouse_move(pos);
}
@ -77,8 +78,8 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
const auto x_button = uMsg >= WM_XBUTTONDOWN && uMsg <= WM_XBUTTONDBLCLK;
if (lmr_button || x_button) {
if (const auto window = get_window_from_hwnd(hwnd)) {
const int x = LOWORD(lParam);
const int y = HIWORD(lParam);
const int x = GET_X_LPARAM(lParam);
const int y = GET_Y_LPARAM(lParam);
const Eigen::Vector2f pos(static_cast<float>(x), static_cast<float>(y));
const auto action = platform_event_to_mouse_action(uMsg, wParam);
const auto button = platform_event_to_mouse_button(uMsg, wParam);
@ -95,8 +96,8 @@ LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// 鼠标滚轮事件
if (uMsg == WM_MOUSEWHEEL || uMsg == WM_MOUSEHWHEEL) {
if (const auto window = get_window_from_hwnd(hwnd)) {
const int x = LOWORD(lParam);
const int y = HIWORD(lParam);
const int x = GET_X_LPARAM(lParam);
const int y = GET_Y_LPARAM(lParam);
POINT screen_point = { x, y };
ScreenToClient(hwnd, &screen_point);