| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #ifdef _WIN32
- #include <windows.h>
- #include "internal.h"
- #include "pltf/pltf.h"
- #define PLTF_KEYS_X(lower, upper) \
- case PLTF_KEY_##upper: \
- if (pltf_state.key_##lower##_cb != NULL) { \
- pltf_state.key_##lower##_cb(action); \
- } \
- break;
- static void handle_key(const WPARAM key, const PltfKeyAction action) {
- const PltfKey pltf_key = vk_to_pltf_key(key);
- if (pltf_state.key_cb != NULL) {
- pltf_state.key_cb(pltf_key, action);
- }
- }
- #undef PLTF_KEYS_X
- LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
- WinState* pState = NULL;
- if (uMsg == WM_CREATE) {
- CREATESTRUCT* pCreate = (CREATESTRUCT*) lParam;
- pState = (WinState*) pCreate->lpCreateParams;
- SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) pState);
- } else {
- LONG_PTR ptr = GetWindowLongPtr(hwnd, GWLP_USERDATA);
- pState = (WinState*) ptr;
- }
- switch (uMsg) {
- // case WM_LBUTTONDOWN: {
- // printf("State: msg: %s, num: %d\n", pState->msg, pState->num);
- //
- // printf("lParam: %llx\n", lParam);
- // int mouse_x = GET_X_LPARAM(lParam);
- // printf("mouse_x: %x\n", mouse_x);
- // int mouse_y = GET_Y_LPARAM(lParam);
- // printf("mouse_y: %x\n", mouse_y);
- // printf("x: %d y: %d\n", mouse_x, mouse_y);
- //
- // return 0;
- // }
- // case WM_CREATE: {
- // return 0;
- // }
- case WM_KEYDOWN:
- handle_key(wParam, PLTF_KEY_DOWN);
- return 0;
- case WM_KEYUP:
- handle_key(wParam, PLTF_KEY_UP);
- return 0;
- case WM_CLOSE:
- // if (MessageBox(hwnd, L"Really quit?", L"My Application", MB_OKCANCEL) == IDOK) {
- // }
- PostMessage(hwnd, WM_DESTROY, 0, 0);
- return 0;
- }
- return DefWindowProc(hwnd, uMsg, wParam, lParam);
- }
- #endif // _WIN32
|