Thread: What's wrong with my Win32 Wrapper code?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Recursively calling your class member function window procedure (WinMsgHandler) by default is not a good idea; replace the default of the switch statment with a call to DefWindowProc instead:
    Code:
    LRESULT CALLBACK CWindow::WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        switch(uMsg)
        {
            case WM_CREATE:
                MessageBox(NULL, "Create", "test", MB_OK);
                break;
            case WM_CLOSE:
                /*default system processing of WM_CLOSE involves a call to DestroyWindow
                  so if you intercept this message, do the same*/
                DestroyWindow(hwnd);
                PostQuitMessage(0);
                break;
            default:
                //return CWindow::WinMsgHandler(hwnd, uMsg, wParam, lParam);
                DefWindowProc(hwnd,uMsg,wParam,lParam);
        }
        return 0;
    }
    You might want to read up on GetMessage, too; there's a possibility of that function returning -1, a result which will break your code.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  2. #2
    Registered User
    Join Date
    Feb 2005
    Posts
    4
    Ken Fitlike, thanks for the tips.

    I haven't change the GetMessage() while loop, I find that CreateWindow() is the one that fails, m_hwnd returns 0! I replace "(void *)this" with "NULL", CreateWindow() works! why!? what's wrong?

    I checked my CWindow::RegisterWindow(), no problems there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's wrong with this code?
    By Luciferek in forum C++ Programming
    Replies: 4
    Last Post: 06-21-2008, 12:02 PM
  2. need example code for a win32 window
    By deian in forum Windows Programming
    Replies: 18
    Last Post: 09-29-2007, 06:33 AM
  3. What is wrong with my code? My first program......
    By coreyt1111 in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 02:03 PM
  4. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  5. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 06:32 PM