wm_create problems
-
Hello, I am trying to write a simple little oo windowing library for opengl (mainly a wrapper for the c based windowing code); of course i had the standard wndproc callback as a class member problem, but i found a way around that, what i did was simple enough, i made WndProc static, but that meant i couldn't get at class members and then I noticed that the last paramater of CreateWindowEx was passed as the LPARAM of your wndproc callback on WM_CREATE. So, i passed 'this': CreateWindowEx(blah...., this); then in WM_CREATE: SetWindowLong(hWnd, DWL_USER, lParam); then whenever i have a WM_* callback i acces my class through ((MyClass*)GetWindowLong(hWnd, DWL_USER))->junkMyClassPointsTo... but CreateWindowEx is always failing, none of the paramaters are bad, the only thing i can think of is 'this' and i don't know if WndProc-WM_CREATE is called then and if it is what is giving me the problem. if anyone could help me with this, it would be most appreciated. thank you, -Matt
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
Jason Henderson
blog -
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
Jason Henderson
blogThanks for the help, i applied all the stuff that was in that article, and it still didn't work, i also started to use WNDCLASSEX instead of WNDCLASS, but all that has done is stopped me from being able to register my class. i type: RegisterClassEx(&myWndClassEx); and it throws an error, i printed the error with GetLastError, and the code is dec 87 or 0x57 and i don't know what that is or where to find the definition, this is becomming a major dilemna, any more help would be greatly appreciated
-
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
Jason Henderson
blogI've been working really hard on this now and i have finally figured out that my real problem is in CreateWindowEx it is giving a return error of 6, which i found out is 'invalid handle' i think that is pointing at my hinstance, to instantiate my hinstance i call GetModuleHandle(NULL) and that is in a cpp file that is compiled into a static library, if this helps, that's great, i really need a fix for this problem, Thank you very much in advance if you can tell me what to do.
-
I've been working really hard on this now and i have finally figured out that my real problem is in CreateWindowEx it is giving a return error of 6, which i found out is 'invalid handle' i think that is pointing at my hinstance, to instantiate my hinstance i call GetModuleHandle(NULL) and that is in a cpp file that is compiled into a static library, if this helps, that's great, i really need a fix for this problem, Thank you very much in advance if you can tell me what to do.
WinMain should give you an hInstance you can use.
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
Jason Henderson
blog -
Hello, I am trying to write a simple little oo windowing library for opengl (mainly a wrapper for the c based windowing code); of course i had the standard wndproc callback as a class member problem, but i found a way around that, what i did was simple enough, i made WndProc static, but that meant i couldn't get at class members and then I noticed that the last paramater of CreateWindowEx was passed as the LPARAM of your wndproc callback on WM_CREATE. So, i passed 'this': CreateWindowEx(blah...., this); then in WM_CREATE: SetWindowLong(hWnd, DWL_USER, lParam); then whenever i have a WM_* callback i acces my class through ((MyClass*)GetWindowLong(hWnd, DWL_USER))->junkMyClassPointsTo... but CreateWindowEx is always failing, none of the paramaters are bad, the only thing i can think of is 'this' and i don't know if WndProc-WM_CREATE is called then and if it is what is giving me the problem. if anyone could help me with this, it would be most appreciated. thank you, -Matt
-
WinMain should give you an hInstance you can use.
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
Jason Henderson
blogi don't know what is happening now, i have used hInstance AS delivered by winmain, but my createwindowex is stilling failing and when i call getlasterror, i get a code of 0 which apparently means success, this is extraordinarily frustrating, thank you for your help so far, but this is just rediculousl annyoing, thank yuou for any further help :wtf:
-
Add this line to your code wc.style = CS_GLOBAL; //initial other fields RegisterClassEx(&wc);
CS_GLOBAL isn't a field in style, i can't set it to that, it tells me 'CS_GLOBAL': undeclared identifier also, for some reason, i am being told that the paramter is incorrect when i try and register my class
-
i don't know what is happening now, i have used hInstance AS delivered by winmain, but my createwindowex is stilling failing and when i call getlasterror, i get a code of 0 which apparently means success, this is extraordinarily frustrating, thank you for your help so far, but this is just rediculousl annyoing, thank yuou for any further help :wtf:
Can you post some actual code or send it to me?
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
Jason Henderson
blog -
Can you post some actual code or send it to me?
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
Jason Henderson
blogthis is my create window method: bool GLWindow::CreateGLWindow(HINSTANCE hInstance //this is hInstance passed by WinMain) { ofstream emsg ("ERROR.txt"); //this is where i have been putting my errors GLuint PixelFormat; DWORD dwExStyle; DWORD dwStyle; RECT WindowRect; WindowRect.left = (long)0; WindowRect.right = (long)m_aResolution[0]; WindowRect.top = (long)0; WindowRect.bottom = (long)m_aResolution[1]; m_hInstance = hInstance; WNDCLASSEX l_wc = { sizeof(WNDCLASSEX), CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW | CS_OWNDC, (WNDPROC) WndProc, 0, 0, m_hInstance, LoadIcon(NULL, IDI_WINLOGO), LoadCursor(NULL, IDC_ARROW), NULL, NULL, m_StrTitle, LoadIcon(NULL, IDI_WINLOGO), }; if (!RegisterClassEx(&l_wc)) { emsg << GetLastError(); MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } /*********************************my class registers fine, no problem at all*********************/ dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle=WS_OVERLAPPEDWINDOW; AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); if (!(m_hWnd=CreateWindowEx(dwExStyle, m_StrTitle, m_StrTitle, dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, NULL, NULL, m_hInstance, this))) { /************************************************************************************************* this is where the failure is, but the error code that gets printed is zero (which is enumerated as ERROR_SUCCESS) which i don't get at all, i don't know if i am somehow getting the wrong error code or what!! *************************************************************************************************/ emsg << GetLastError(); emsg.close(); this->KillGLWindow(); MessageBox(NULL,"Window Creation Error","ERROR",MB_OK|MB_ICONEXCLAMATION); return false; } ****NOTE: i nocked off the rest of the code because it works, and it doesn't do anything but take up a lot of space in this post. Your help so far has been great, thank you for your continued support -Matthew
-
this is my create window method: bool GLWindow::CreateGLWindow(HINSTANCE hInstance //this is hInstance passed by WinMain) { ofstream emsg ("ERROR.txt"); //this is where i have been putting my errors GLuint PixelFormat; DWORD dwExStyle; DWORD dwStyle; RECT WindowRect; WindowRect.left = (long)0; WindowRect.right = (long)m_aResolution[0]; WindowRect.top = (long)0; WindowRect.bottom = (long)m_aResolution[1]; m_hInstance = hInstance; WNDCLASSEX l_wc = { sizeof(WNDCLASSEX), CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW | CS_OWNDC, (WNDPROC) WndProc, 0, 0, m_hInstance, LoadIcon(NULL, IDI_WINLOGO), LoadCursor(NULL, IDC_ARROW), NULL, NULL, m_StrTitle, LoadIcon(NULL, IDI_WINLOGO), }; if (!RegisterClassEx(&l_wc)) { emsg << GetLastError(); MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } /*********************************my class registers fine, no problem at all*********************/ dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle=WS_OVERLAPPEDWINDOW; AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); if (!(m_hWnd=CreateWindowEx(dwExStyle, m_StrTitle, m_StrTitle, dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, NULL, NULL, m_hInstance, this))) { /************************************************************************************************* this is where the failure is, but the error code that gets printed is zero (which is enumerated as ERROR_SUCCESS) which i don't get at all, i don't know if i am somehow getting the wrong error code or what!! *************************************************************************************************/ emsg << GetLastError(); emsg.close(); this->KillGLWindow(); MessageBox(NULL,"Window Creation Error","ERROR",MB_OK|MB_ICONEXCLAMATION); return false; } ****NOTE: i nocked off the rest of the code because it works, and it doesn't do anything but take up a lot of space in this post. Your help so far has been great, thank you for your continued support -Matthew
From the CreateWindowEx documentation: This function typically fails for one of the following reasons: *an invalid parameter value *the system class was registered by a different module *the WH_CBT hook is installed and returns a failure code *the window procedure fails for WM_CREATE or WM_NCCREATE Check your params and your wndproc.
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
Jason Henderson
blog -
CS_GLOBAL isn't a field in style, i can't set it to that, it tells me 'CS_GLOBAL': undeclared identifier also, for some reason, i am being told that the paramter is incorrect when i try and register my class
In fact it's CS_GLOBALCLASS,I've forgotten a word. When you call CreateWindow or CreateWindowEx,the function will compare the hInstance you passed to it to the hInstance of the WNDCLASSEX hInstance field. Set the style field to CS_GLOBALCLASS tells the function that it should not compare these two values.