Thread: Problem creating a Dialog Box

  1. #1
    Darkness Prevails Dark_Phoenix's Avatar
    Join Date
    Oct 2006
    Location
    Houston, Texas
    Posts
    174

    Problem creating a Dialog Box

    This is giving me an error 'Invalid Window Handle' but I can't figure out why.

    Code:
    LRESULT CALLBACK MainWinProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
        switch (Msg)
        {
            case WM_CREATE:
            {
                char str[80];
                if (DialogBoxParam(GetModuleHandle(NULL),
                                   MAKEINTRESOURCE(IDD_NEWUSER),
                                   hWnd,
                                   NewUserDlgProc,
                                   (LPARAM)str) <= 0)
                {
                    ShowWinError();
                }
            }
            break;
     
            case WM_CLOSE:
            DestroyWindow(hWnd);
            break;
     
            case WM_DESTROY:
            PostQuitMessage(0);
            break;
     
            default:
            return DefWindowProc (hWnd, Msg, wParam, lParam);
        }
        return 0;
    }
    I am tring to opn a dialog for the user to enter a user name and have the dialog pass that back to the main window

    The call to DialogBoxParam is throwing the invalid handle error. Any ideas?
    Last edited by Dark_Phoenix; 05-30-2009 at 07:20 AM.
    Using Code::Blocks and Windows XP

    In every hero, there COULD be a villain!

  2. #2
    Darkness Prevails Dark_Phoenix's Avatar
    Join Date
    Oct 2006
    Location
    Houston, Texas
    Posts
    174
    OK, I figured it out... forgot to put a break in my DialogProc. Anyway, here is what I have... It works but I want to know if it is right?

    Code:
    LRESULT CALLBACK MainWinProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
        switch (Msg)
        {
            case WM_CREATE:
            {
                std::string str;
                DialogBoxParam(GetModuleHandle(NULL),
                               MAKEINTRESOURCE(IDD_NEWUSER),
                               hWnd,
                               NewUserDlgProc,
                               (LPARAM)&str);
            }
            BringWindowToTop(hWnd);
            break;
    
            case WM_CLOSE:
            DestroyWindow(hWnd);
            break;
    
            case WM_DESTROY:
            PostQuitMessage(0);
            break;
    
            default:
            return DefWindowProc (hWnd, Msg, wParam, lParam);
        }
    
        return 0;
    }
    
    
    BOOL CALLBACK NewUserDlgProc(HWND hDialog, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
        static std::string *str;
        switch (Msg)
        {
            case WM_INITDIALOG:
            str = (std::string*)lParam;
            break;
    
            case WM_COMMAND:
            switch (LOWORD(wParam) )
            {
                case IDB_OK:
                {
                    char chStr[80];
                    GetDlgItemText(hDialog, IDE_EDIT, chStr, 80);
                    *str = chStr;
                    SendMessage(hDialog, WM_CLOSE, NULL, NULL);
                }
                break;
            }
            break;
    
            case WM_CLOSE:
            EndDialog(hDialog, (LPARAM)str);
            break;
    
            default:
            return FALSE;
        }
        return TRUE;
    }
    Using Code::Blocks and Windows XP

    In every hero, there COULD be a villain!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Dialog Box
    By KonArtis in forum Windows Programming
    Replies: 3
    Last Post: 01-04-2005, 02:28 PM
  2. the open box problem
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 02-28-2003, 05:53 AM
  3. dialog box
    By JaWiB in forum Windows Programming
    Replies: 0
    Last Post: 02-21-2003, 10:24 PM
  4. Dialog box
    By DeanaM in forum Windows Programming
    Replies: 3
    Last Post: 10-16-2002, 12:04 PM
  5. Dialog Box Problem....
    By minime6696 in forum Windows Programming
    Replies: 2
    Last Post: 01-08-2002, 08:24 PM