samedi 25 juin 2016

Win32 API - window procedure change

My program structure Image My programming scene changed. so I make parent class Scene and child class Title, SelectStage. I think SetWindowLongPtr function changes message procedure, sometimes its success but usually fail. error message occur message loop. Exception 0xC000041D: An unhandled exception was encountered during a user callback I use CallWindowProc for SetWindowLongPtr and SendMessage for PostMessage but same problem. why occur this problem? Main Procedure LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CREATE: gSceneType = TITLE; gScene = new Title(g_hInstance, 800, 600); return 0; case WM_SCENE_CHANGED: switch (wParam) { case WM_SCENE_TITLE: delete gScene; gScene = new Title(g_hInstance, 800, 600); break; case WM_SCENE_SELECTSTAGE: delete gScene; gScene = new SelectStage(g_hInstance, 800, 600, 5); break; } return 0; case WM_DESTROY: PostQuitMessage(0); return 0; default: if (gScene) return gScene->MsgProc(hWnd, msg, wParam, lParam); else return DefWindowProc(hWnd, msg, wParam, lParam); } } MsgProc in Title Class LRESULT Title::MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_KEYDOWN: switch (wParam) { case VK_SPACE: SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)GetProp(hWnd, L"PROP_WNDPROC")); PostMessage(hWnd, WM_SCENE_CHANGED, WM_SCENE_SELECTSTAGE, NULL); break; } return 0; } return Scene::MsgProc(hWnd, msg, wParam, lParam); } MsgProc in Scene Class LRESULT Scene::MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, msg, wParam, lParam); }

Aucun commentaire:

Enregistrer un commentaire