CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2011
    Posts
    2

    DialogBox() returning -1 and GetLastError()=0 ?

    Hello, I have a dialog box designed in Visual C++ 2010 SP1 resource editor and its id is IDD_DIALOG4. When I try to create it using DialogBox() API, the function returns -1 and GetLastError() returns 0. Note: WM_INITDIALOG is not being called.
    Can anybody help me?

    // main.cpp
    Code:
    void showDlg(HINSTANCE hInstance, HWND hwndParent)
    {
    	int dlgRet = DialogBoxA( hInstance, MAKEINTRESOURCE(IDD_DIALOG4), hwndParent, (DLGPROC)MyDlgProc );
    	if(dlgRet==-1)
    	{
    		msgbox("error on creating dlg: %08X", GetLastError());
    		return;
    
    	}
    }
    
    // Dialog procedure
    LRESULT CALLBACK MyDlgProc( HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam )
    {
    	switch( Msg )
    	{
    		case WM_INITDIALOG:
    			msgbox("WM_INITDIALOG");
    			return TRUE;
    		break;
    		case WM_COMMAND:
    			switch( wParam )
    			{
    				case IDC_BUTTON_COPY:
    					msgbox("IDC_BUTTON_COPY");
    					return TRUE;
    				break;
    				case IDCANCEL: // close
    					EndDialog( hWndDlg, 0 );
    					return TRUE;
    				break;
    			}
    			return TRUE;
    		break;
    		case WM_CLOSE:
    			EndDialog( hWndDlg, 0 );
    			return TRUE;
    		break;
    		default:
    			return FALSE;
    	}
    }

    // main.rc
    Code:
    IDD_DIALOG4 DIALOGEX 0, 0, 317, 151
    STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "Result"
    FONT 8, "MS Shell Dlg", 400, 0, 0x1
    BEGIN
        PUSHBUTTON      "Close",IDCANCEL,260,130,50,14
        LTEXT           "Text1:",IDC_STATIC1,15,16,69,8
        LTEXT           "Text2",IDC_STATIC_SIGN_TEXTSTYLE,92,17,62,8
        PUSHBUTTON      "Copy to clipboard",IDC_BUTTON_COPY,7,54,69,9
        CONTROL         "<a>SysLink2</a>",IDC_SYSLINK2,"SysLink",WS_TABSTOP,90,37,60,14
        CONTROL         "",IDC_RICHEDIT_CODESTYLEWITHFP,"RichEdit20A",ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_NOHIDESEL | WS_BORDER | WS_TABSTOP,7,65,303,59
    END

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: DialogBox() returning -1 and GetLastError()=0 ?

    Code:
        CONTROL         "<a>SysLink2</a>",IDC_SYSLINK2,"SysLink",WS_TABSTOP,90,37,60,14
    InitCommonControlsEx is required before DialogBox.
    Best regards,
    Igor

  3. #3
    Join Date
    Jul 2011
    Posts
    2

    Re: DialogBox() returning -1 and GetLastError()=0 ?

    Igor, thanks for the help, it's working now.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured