I make a wrapper around the winapi window, you need to drag wndproc to the class and it is static. In general, WindowProc does not work for some reason .. pwnd null

#pragma once #include "windows.h" class Window { protected: HWND hwnd; public: LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; } static LRESULT CALLBACK internal_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { Window* pWnd; if (message == WM_NCCREATE) { LPCREATESTRUCT cs = reinterpret_cast<LPCREATESTRUCT>(lParam); pWnd = reinterpret_cast<Window*>(cs->lpCreateParams); SetLastError(0); if (!SetWindowLongPtr(hWnd, GWL_USERDATA, reinterpret_cast<LONG_PTR> (pWnd))) { int i = 1; } } else { pWnd = reinterpret_cast<Window*>(GetWindowLongPtr(hWnd, GWL_USERDATA)); } if (pWnd) { return pWnd->WindowProc(message, wParam, lParam); } else { return DefWindowProc(hWnd, message, wParam, lParam); } } Window() { WNDCLASSW windowClass; windowClass.style = CS_DBLCLKS | CS_PARENTDC; windowClass.lpfnWndProc = &internal_WndProc; windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; windowClass.hInstance = GetModuleHandle(NULL); windowClass.hIcon = NULL; windowClass.hCursor = LoadCursor(NULL, (LPTSTR)IDC_IBEAM); windowClass.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(255, 255, 255)); windowClass.lpszMenuName = NULL; windowClass.lpszClassName = L"MainWindowClass"; RegisterClassW(&windowClass); this->hwnd = CreateWindowW(L"MainWindowClass", L"Window", ( WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX), GetSystemMetrics(SM_CXSCREEN) / 2 - 400, GetSystemMetrics(SM_CYSCREEN) / 2 - 300, 800, 600, 0, 0, GetModuleHandle(NULL), 0); ShowWindow(hwnd, 1); UpdateWindow(hwnd); } }; 
  • one
    "pwnd null". Not understood. And how else should it be? Your last CreateWindow argument is 0 . This is your cs->lpCreateParams . They transferred zero - they got zero. Everything is as it should be. - AnT
  • @AnT if I create the main window it should be 0 - Mike Waters
  • Why should there be? - AnT
  • @MikeWaters, CreateWindow - acade
  • @AnT this there need? - Mike Waters

0