Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. wm_create problems

wm_create problems

Scheduled Pinned Locked Moved C / C++ / MFC
helpgraphicsgame-devquestionlearning
13 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    super_matt
    wrote on last edited by
    #1

    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

    S J Y 3 Replies Last reply
    0
    • S super_matt

      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

      S Offline
      S Offline
      super_matt
      wrote on last edited by
      #2

      sorry, just to add on, i have also used GWL_USERDATA instead of DWL_USER if that makes a difference, thanks

      1 Reply Last reply
      0
      • S super_matt

        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

        J Offline
        J Offline
        Jason Henderson
        wrote on last edited by
        #3

        Try this article.[^]

        "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

        S 2 Replies Last reply
        0
        • J Jason Henderson

          Try this article.[^]

          "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

          S Offline
          S Offline
          super_matt
          wrote on last edited by
          #4

          Thanks 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

          1 Reply Last reply
          0
          • J Jason Henderson

            Try this article.[^]

            "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

            S Offline
            S Offline
            super_matt
            wrote on last edited by
            #5

            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.

            J 1 Reply Last reply
            0
            • S super_matt

              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.

              J Offline
              J Offline
              Jason Henderson
              wrote on last edited by
              #6

              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

              A 1 Reply Last reply
              0
              • S super_matt

                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

                Y Offline
                Y Offline
                yndfcd
                wrote on last edited by
                #7

                Add this line to your code wc.style = CS_GLOBAL; //initial other fields RegisterClassEx(&wc);

                S 1 Reply Last reply
                0
                • J Jason Henderson

                  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

                  A Offline
                  A Offline
                  Anonymous
                  wrote on last edited by
                  #8

                  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:

                  J 1 Reply Last reply
                  0
                  • Y yndfcd

                    Add this line to your code wc.style = CS_GLOBAL; //initial other fields RegisterClassEx(&wc);

                    S Offline
                    S Offline
                    super_matt
                    wrote on last edited by
                    #9

                    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

                    Y 1 Reply Last reply
                    0
                    • A Anonymous

                      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:

                      J Offline
                      J Offline
                      Jason Henderson
                      wrote on last edited by
                      #10

                      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

                      S 1 Reply Last reply
                      0
                      • J Jason Henderson

                        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

                        S Offline
                        S Offline
                        super_matt
                        wrote on last edited by
                        #11

                        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

                        J 1 Reply Last reply
                        0
                        • S super_matt

                          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

                          J Offline
                          J Offline
                          Jason Henderson
                          wrote on last edited by
                          #12

                          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

                          1 Reply Last reply
                          0
                          • S super_matt

                            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

                            Y Offline
                            Y Offline
                            yndfcd
                            wrote on last edited by
                            #13

                            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.

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups