A while ago I tried to create some functions that would automaticly handle classes and their windows for me. But the program would crash when I called CreateWindow(), I found that the problem was dealing with the class. But how so I am unsure of. Now I tried to make another one like it from scratch. Again, the same problem. Does anyone know why the class isn't working with the window? Code below.
Code:// Script by Yarin Licht. // Made September, 2007. #include <windows.h> #include <commctrl.h> struct POD { WNDCLASSEX wincl; int nWide, nHigh; // Got rid of a line char* pszMenu; HWND hwnd; MSG msg; }; HANDLE NewApp(HINSTANCE hInst, char *pszClass, char *pszMenu, WNDPROC wndproc) { POD *poda = new POD[1]; poda[0].hwnd = NULL; ZeroMemory(&poda[0].wincl, sizeof(WNDCLASSEX)); poda[0].wincl.hInstance = hInst; poda[0].wincl.lpszClassName = pszClass; poda[0].wincl.lpfnWndProc = wndproc; poda[0].wincl.style = CS_DBLCLKS; poda[0].wincl.cbSize = sizeof(WNDCLASSEX); poda[0].wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION); poda[0].wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION); poda[0].wincl.hCursor = LoadCursor(NULL, IDC_ARROW); poda[0].wincl.lpszMenuName = pszMenu; poda[0].wincl.cbClsExtra = 0; poda[0].wincl.cbWndExtra = 0; poda[0].wincl.hbrBackground = (HBRUSH)COLOR_3DSHADOW; if(!RegisterClassEx(&poda[0].wincl)) return NULL; return (HANDLE)poda; } #define pod (((POD*)hPod)[0]) int MakeApp(HANDLE hPod, char *pszTitle, int nWide, int nHigh) { int WINDOW_WIDTH = nWide, WINDOW_HEIGHT = nHigh; WINDOW_WIDTH += GetSystemMetrics(SM_CXFIXEDFRAME) * 2; WINDOW_HEIGHT += GetSystemMetrics(SM_CXFIXEDFRAME) + GetSystemMetrics(SM_CYCAPTION); if(pod.wincl.lpszMenuName) WINDOW_HEIGHT += GetSystemMetrics(SM_CYMENU); pod.hwnd = CreateWindowEx(WS_EX_CONTROLPARENT, pod.wincl.pszClassName, pszTitle, WS_OVERLAPPEDWINDOW &~WS_THICKFRAME &~WS_MAXIMIZEBOX, (GetSystemMetrics(SM_CXSCREEN)/2) - (WINDOW_WIDTH/2), (GetSystemMetrics(SM_CYSCREEN)/2) - (WINDOW_HEIGHT/2), WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, pod.wincl.hInstance, 0); if(!pod.hwnd) return FALSE; ShowWindow(pod.hwnd, SW_SHOWNORMAL); return TRUE; } WPARAM RunApp(HANDLE hPod) { while(GetMessage(&pod.msg, NULL, 0, 0)) { TranslateMessage(&pod.msg); if(pod.msg.message == WM_DESTROY) break; DispatchMessage(&pod.msg); } return pod.msg.wParam; } void FreeApp(HANDLE hPod) { if(pod.hwnd) SendMessage(pod.hwnd, WM_DESTROY, 0, 0); UnregisterClass(pod.wincl.pszClassName, pod.wincl.hInstance); delete [ ](POD*)hPod; return; } // End of script file. LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_DESTROY: { PostQuitMessage(0); break; } default: return DefWindowProc(hwnd, message, wParam, lParam); } return TRUE; } int WINAPI WinMain(HINSTANCE hThis, HINSTANCE hPrevInst, LPSTR lpszArgs, int nShow) { HANDLE hApp = NULL; hApp = NewApp(hThis, "TestClass", NULL, WindowProcedure); MakeApp(hApp, "Test App", 300, 300); RunApp(hApp); FreeApp(hApp); return TRUE; } // End of script file.



LinkBack URL
About LinkBacks



