//----------------------------------------------------------------------------- // MainWndProc // // The window procedure for the main window, deals with the different types // of messages received // ---------------------------------------------------------------------------- LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { // If the message is WM_NCCREATE, associate Window pointer with this window // Note: WM_NCCREATE is not the first message that this WndProc will process // What happens here is that we assigned some extra space for the window which // was of size of a pointer to a MainWnd object. Now in the WM_NCREATE message the // lParam method is actually the class structure used to make the window i.e. // CREATESTRUCT. In this stucture is a pointer to a MainWnd object. SetWindowLong in // this usage sets the extra window data to this which can only be done on creation if (msg == WM_NCCREATE) { LPCREATESTRUCT cs = (LPCREATESTRUCT) lParam; SetWindowLong(hWnd, GWL_USERDATA, (long) cs->lpCreateParams); } // get the MainWnd structure and pass the data to that MainWnd* w = (MainWnd *) GetWindowLong(hWnd, GWL_USERDATA); if (w) return w->WndProc(hWnd, msg, wParam, lParam); else return DefWindowProc(hWnd, msg, wParam, lParam); } // --- MainWndProc ----------------------------------------------------------