• Please review our updated Terms and Rules here

How to obtain selected radio button from resource script dialog box

OzzFan

Member
Joined
Jan 11, 2022
Messages
18
Location
United States
I'm trying to write a "wizard" in Windows 3.1 in C. I've created the three dialog boxes using the Resource Script Editor to create a main menu dialog, a backup menu dialog, and a restore menu dialog. From the main menu dialog the user should select either the Backup radio button or the Restore radio button which determines the next dialog box to appear. When I use the following code, only the Restore option works but not the Backup option. What am I doing wrong?

C:
BOOL CALLBACK MainDlgProc( HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam )
{
    switch( Message) {
        case WM_INITDIALOG:
            return TRUE;

        case WM_COMMAND:
            if ( LOWORD( wParam ) == IDB_BACKUP && NULL == hwndBackupDlg ) {
                hwndBackupDlg = CreateDialog( hInst, MAKEINTRESOURCE( IDD_BACKUPDIALOG ), hwndMainDlg, (DLGPROC)BackupDlgProc );
                return TRUE;
            }
            if ( LOWORD( wParam ) == IDB_RESTORE && NULL == hwndRestoreDlg ) {
                hwndRestoreDlg = CreateDialog( hInst, MAKEINTRESOURCE( IDD_RESTOREDIALOG), hwndMainDlg, (DLGPROC)RestoreDlgProc );
                return TRUE;
            }
            if ( LOWORD( wParam ) == IDB_EXIT ) {
                EndDialog( hwndMainDlg, TRUE );
                hwndMainDlg = NULL;
                return TRUE;
            }
    }// end switch

    return false;
}

The Restore radio button successfully calls up the Restore menu dialog, and the Exit button correctly ends the application (DestroyWindow() is part of a separate loop). I'm assuming this may have something to do with radio buttons usually being part of an array or group? I've given them separate Resource IDs (IDB_BACKUP vs IDB_RESTORE) in the Resource Script Editor though. I'm certain I could get this working using regular buttons but I really want to use radio buttons instead. Anyone here familiar with writing Windows 3.1 applications?
 
Last edited:
When you switch the order of the IF statements for IDB_BACKUP and IDB_RESTORE, does the other radio button start working?

You may need a break for that switch statement as well.
 
I gave that a try and only the same behavior resulted: only the restore radio button worked as before. I also added a break statement per your suggestion but that didn't do anything.

This at least tells me that whatever wParam is returning, it is equal to IDB_RESTORE and never equal to IDB_BACKUP. Maybe I can write up a logging function to determine what wParam actually results in.
 
Yup, also step thru the function with a debugger and see where the conditional statement is branching. Also, I'm not too familiar with Windows API functions, but does the case of TRUE and FALSE matter? It should be a simple boolean value returned, but I've seen case cause screwy and unexpected behavior in C.

I would also check and see if the hwndRestoreDlg and hwndBackupDlg handles are indeed NULL before entering the function. The handles might have been set beforehand and you might not even need that conditional if you plan on re initializing them anyway.
 
In general, a radio button should not be used for triggering a dialog box. Command buttons are made for this.
If you want to use radio buttons the select one of two option, the action should be started with a command button.
If your radio buttons are inside a button group, they could trigger each other (activating one radio button releases the other), so that you might se the result of this chain (activate one, release all others).
You might want to read about the behavior of radio buttons e.g. in Petzold and maybe the Windows GUI style guide which came with the SDK.
 
In general, a radio button should not be used for triggering a dialog box. Command buttons are made for this.
If you want to use radio buttons the select one of two option, the action should be started with a command button.
If your radio buttons are inside a button group, they could trigger each other (activating one radio button releases the other), so that you might se the result of this chain (activate one, release all others).
You might want to read about the behavior of radio buttons e.g. in Petzold and maybe the Windows GUI style guide which came with the SDK.

I had an 'OK' Command Button in the dialog box to be clicked after selecting the radio button but I still couldn't figure out a way to determine which radio button was selected after pressing OK. I guess that's the part I'm struggling with.
 
I was able to figure out how to get the state of the radio buttons by using
C:
SendDlgItemMessage()
like so:

C:
BOOL CALLBACK MainDlgProc( HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam )
{
    switch( Message ) {
        case WM_INITDIALOG:
            return TRUE;

        case WM_COMMAND:
            if ( LOWORD( wParam ) == IDB_OK ) {
                if ( SendDlgItemMessage( hwndMainDlg, IDB_BACKUP, BM_GETSTATE, 0, 0 ) == 1 ) {
                    hwndChildDlg = CreateDialog( hInst, MAKEINTRESOURCE( IDD_BACKUPDIALOG ), hwndMainDlg, (DLGPROC)BackupDlgProc );
                }
                if ( SendDlgItemMessage( hwndMainDlg, IDB_RESTORE, BM_GETSTATE, 0, 0 ) == 1 ) {
                    hwndChildDlg = CreateDialog( hInst, MAKEINTRESOURCE( IDD_RESTOREDIALOG), hwndMainDlg, (DLGPROC)RestoreDlgProc );
                }
                return TRUE;
            }
            if ( LOWORD( wParam ) == IDB_EXIT ) {
                EndDialog( hwndMainDlg, TRUE );
                hwndMainDlg = NULL;
                return TRUE;
            }
    } // end switch

    return FALSE;
}

Where the return value of the function = 0 when not selected, 1 when selected, and if it is a three-state button, 2 is returned when it is grayed out.
 
Back
Top