| 44 | } |
| 45 | |
| 46 | LRESULT WndClass::SetupWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) |
| 47 | { |
| 48 | // use create parameter passed in from CreateWindow() to store window class pointer at WinAPI side |
| 49 | if (msg == WM_NCCREATE) |
| 50 | { |
| 51 | // extract ptr to window class instance from creation data |
| 52 | const CREATESTRUCTW* const pCreate = reinterpret_cast<CREATESTRUCTW*>(lParam); |
| 53 | auto const pWnd = static_cast<Window*>(pCreate->lpCreateParams); |
| 54 | // Set handle into instance |
| 55 | pWnd->SetHandle(hWnd); |
| 56 | // set WinAPI-managed user data to store ptr to window instance |
| 57 | { |
| 58 | SetLastError(0); |
| 59 | const auto ret = SetWindowLongPtrW(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pWnd)); |
| 60 | if (ret == 0) |
| 61 | { |
| 62 | if (const auto hr = GetLastError(); FAILED(hr)) |
| 63 | { |
| 64 | pmlog_error().hr(hr); |
| 65 | throw Except<Exception>(); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | // set message proc to normal (non-setup) handler now that setup is finished |
| 70 | { |
| 71 | SetLastError(0); |
| 72 | const auto ret = SetWindowLongPtrW(hWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&ThunkWndProc)); |
| 73 | if (ret == 0) |
| 74 | { |
| 75 | if (const auto hr = GetLastError(); FAILED(hr)) |
| 76 | { |
| 77 | pmlog_error().hr(hr); |
| 78 | throw Except<Exception>(); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | // forward message to window instance handler |
| 83 | return pWnd->HandleMessage(msg, wParam, lParam); |
| 84 | } |
| 85 | // if we get a message before the WM_NCCREATE message, handle with default handler |
| 86 | return DefWindowProcW(hWnd, msg, wParam, lParam); |
| 87 | } |
| 88 | |
| 89 | LRESULT WndClass::ThunkWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) |
| 90 | { |
nothing calls this directly
no test coverage detected