Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Can't create dialog box...

I'm trying to create just a dialog box in my program, meaning no other windows but my dialog box. Problem is, that the code I wrote doesn't work, and I see no mistakes in it. Can anyone help me?
[italic][blue]
wAre
Beginner Programmmer
[/blue][/italic]

Comments

  • pingpongpingpong Posts: 937Member
    Pass 'NULL' to the second parameter of the function call at line 62.

    : I'm trying to create just a dialog box in my program, meaning no other windows but my dialog box. Problem is, that the code I wrote doesn't work, and I see no mistakes in it. Can anyone help me?
    : [italic][blue]
    : wAre
    : Beginner Programmmer
    : [/blue][/italic]
    :
    :

  • wArewAre Posts: 46Member
    You propably answered to wrong message, but my problem remains. I still can't get my app working. So, if anyone has a woring sample, or knows where I could find one, I'd be gratefull...

    : Pass 'NULL' to the second parameter of the function call at line 62.
    :
    : : I'm trying to create just a dialog box in my program, meaning no other windows but my dialog box. Problem is, that the code I wrote doesn't work, and I see no mistakes in it. Can anyone help me?
    : : [italic][blue]
    : : wAre
    : : Beginner Programmmer
    : : [/blue][/italic]
    : :
    : :
    :
    :

    [italic][blue]
    wAre
    Beginner Programmmer
    [/blue][/italic]


  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : You propably answered to wrong message, but my problem remains. I still can't get my app working. So, if anyone has a woring sample, or knows where I could find one, I'd be gratefull...
    :
    : : Pass 'NULL' to the second parameter of the function call at line 62.
    : :
    : : : I'm trying to create just a dialog box in my program, meaning no other windows but my dialog box. Problem is, that the code I wrote doesn't work, and I see no mistakes in it. Can anyone help me?
    : : : [italic][blue]
    : : : wAre
    : : : Beginner Programmmer
    : : : [/blue][/italic]
    : : :
    : : :
    : :
    : :
    :
    : [italic][blue]
    : wAre
    : Beginner Programmmer
    : [/blue][/italic]
    :
    :
    :
    [blue]Please, post some code... how we can help you without the code?..[/blue]
  • wArewAre Posts: 46Member
    #include
    #include"Resource.h"

    BOOL CALLBACK DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );

    int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow )
    {
    MSG msg;
    HWND hDlg;

    hDlg = CreateDialog( hInst, MAKEINTRESOURCE( IDD_DIALOG ), NULL, DialogProc );
    if( hDlg == NULL ) {
    return 0;
    }

    ShowWindow( hDlg, SW_SHOWNORMAL );

    while( GetMessage( &msg, NULL, 0, 0 ) ) {
    TranslateMessage( &msg );
    DispatchMessage( &msg );
    }

    return 1;
    }

    BOOL CALLBACK DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
    {
    switch( uMsg ) {
    case WM_INITDIALOG:
    SetFocus( hwndDlg );
    return TRUE;
    break;
    case WM_COMMAND:
    if( wParam == IDC_EXIT ) {
    EndDialog( hwndDlg, TRUE );
    return( TRUE );
    }
    break;
    default:
    return DefDlgProc( hwndDlg, uMsg, wParam, lParam );
    }

    return FALSE;
    }



    : : You propably answered to wrong message, but my problem remains. I still can't get my app working. So, if anyone has a woring sample, or knows where I could find one, I'd be gratefull...
    : :
    : : : Pass 'NULL' to the second parameter of the function call at line 62.
    : : :
    : : : : I'm trying to create just a dialog box in my program, meaning no other windows but my dialog box. Problem is, that the code I wrote doesn't work, and I see no mistakes in it. Can anyone help me?
    : : : : [italic][blue]
    : : : : wAre
    : : : : Beginner Programmmer
    : : : : [/blue][/italic]
    : : : :
    : : : :
    : : :
    : : :
    : :
    : : [italic][blue]
    : : wAre
    : : Beginner Programmmer
    : : [/blue][/italic]
    : :
    : :
    : :
    : [blue]Please, post some code... how we can help you without the code?..[/blue]
    :

    [italic][blue]
    wAre
    Beginner Programmmer
    [/blue][/italic]


  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [code]
    : #include
    : #include"Resource.h"
    :
    : BOOL CALLBACK DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
    :
    : int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow )
    : {
    : MSG msg;
    : HWND hDlg;
    :
    : hDlg = CreateDialog( hInst, MAKEINTRESOURCE( IDD_DIALOG ), NULL, DialogProc );
    : if( hDlg == NULL ) {
    : return 0;
    : }
    :
    : ShowWindow( hDlg, SW_SHOWNORMAL );
    :
    : while( GetMessage( &msg, NULL, 0, 0 ) ) {
    : TranslateMessage( &msg );
    : DispatchMessage( &msg );
    : }
    :
    : return 1;
    : }
    :
    : BOOL CALLBACK DialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
    : {
    : switch( uMsg ) {
    : case WM_INITDIALOG:
    : SetFocus( hwndDlg );
    : return TRUE;
    : break;
    : case WM_COMMAND:
    : if( wParam == IDC_EXIT ) {
    : EndDialog( hwndDlg, TRUE );
    : return( TRUE );
    : }
    : break;
    : default:
    : return DefDlgProc( hwndDlg, uMsg, wParam, lParam );
    : }
    :
    : return FALSE;
    : }
    :
    [/code]
    [blue]Unfortunately, a lot of stuff messed up...

    1. [b]DefDlgProc()[/b] used only for one purpose: to provide additional handling for the CUSTOM dialog class and you do not register any additional window classes.

    2. You create a modeless dialog, so you need to call [b]IsDialogMessage()[/b] in your message loop and it is not there. Also, there is no need for modeless dialog, if you having the dialog as your main window.

    3. Modeless dialog (which you created) does not end with [b]EndDialog()[/b] - only [b]DestroyWindow()[/b] must be used.

    4. Why did you set focus to your own dialog in WM_INITDIALOG? The WM_INITDIALOG is used to fill the dialog controls with data...
    ======================
    Well, if this code is from a book - get a better book.
    I suggest Petzold's "Programming Windows".
    ======================
    This code sample should work better:
    ======================
    [code]
    : #include
    : #include"Resource.h"
    :
    : BOOL CALLBACK MyDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
    :
    : int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow )
    : {
    : DialogBox( hInst, MAKEINTRESOURCE( IDD_DIALOG ), NULL, MyDialogProc );
    : return 0;
    : }
    :
    : BOOL CALLBACK MyDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
    : {
    : switch( uMsg ) {
    : case WM_INITDIALOG:
    // fill your controls here
    // also, you can move a dialog to the new place on screen
    : break;
    : case WM_COMMAND:
    : if(( wParam == IDC_EXIT || (wParam==IDCANCEL)) {
    : EndDialog( hwndDlg, wParam );
    : }
    : break;
    : default:
    : return FALSE; // Message NOT processed, let Windows do it!
    : }
    : return TRUE; // Message processed
    : }
    :
    [/code]
    [/blue]

Sign In or Register to comment.