Controlling Visibility of Custom Dialog Box Controls

When you create a custom dialog box in an InstallScript or InstallScript MSI project, you may need to control the visibility of certain controls. An example is radio buttons.

Let’s say you have several radio buttons in a custom dialog box. You do not need all of them to be visible all of the time. Sometimes, you just need one, other times two, and so on. As a result, you want to show the ones you need and hide the ones you don’t.

Here are the basic steps involved.

  1. Call CmdGetHwndDlg() to get the handle to the dialog.
  2. Call GetDlgItem() to get the handle of a radio button control.
  3. Call CtrlSetState() to set the state of a radio button (selected or unselected).
  4. Call _WinSubEnableControl() to enable or disable a radio button.
  5. Call _WinSubShowWindow() to show or hide a radio button.
  6. Call CtrlSetText() to set the text for a radio button.

Check out this code sample:

#define RADIO1   1441
#define RADIO2   1442

HWND     hwndDlg,
                  hwndRadio1,
                  hwndRadio2;

STRING   szDlg;

// set name of custom dialog

szDlg = “DialogName”;

// get handle to custom dialog

hwndDlg = CmdGetHwndDlg(szDlg);

// get handles to radio buttons

hwndRadio1 = GetDlgItem(hwndDlg,RADIO1);
hwndRadio2 = GetDlgItem(hwndDlg,RADIO2);

// set radio button 1 to checked, visible, enabled. finally, set radio button text.

CtrlSetState(szDlg,RADIO1,BUTTON_CHECKED);
_WinSubShowWindow(hwndRadio1,1);
_WinSubEnableControl(hwndDlg,RADIO1,1);
CtrlSetText(szDlg,RADIO1,@IDS_TEXT_STRING1);

// set radio button 2 to unchecked, non-visible, disabled. finally, clear radio button text

CtrlSetState(szDlg,RADIO2,BUTTON_UNCHECKED);
_WinSubShowWindow(hwndRadio2,0);
_WinSubEnableControl(hwndDlg,RADIO2,0);
CtrlSetText(szDlg,RADIO2,@IDS_TEXT_STRING2);

The main point to remember is that you won’t always find InstallScript functions to do what you want. At those times you have to use Windows functions.

 

SQL Server Version Detection in InstallShield

2 Comments

  1. oghenez

    on 2nd May, 11 12:05pm

    How do you execute an action when one radio button is selected and execute another action for the other radio button?

  2. Rod_Maupin

    on 2nd May, 11 09:05pm

    I have never had to do that with radio buttons, but here’s how it could work:

    1) Set the Value property for the first radio button to 1.
    2) Set the Value property for the second radio button to 2.
    3) Define a property in the Property Manager called RADIO_OPTION. Set it’s initial value to 1 or whatever you want the default value to be.
    4) Set the Property property for the radio button group to RADIO_OPTION. When the user selects either radio button, RADIO_OPTION will be set to a 1 or a 2.
    5) Click the Behavior node for the dialog. Then click the Next PushButton control.
    6) Define two events for the Next button. The first event is DoAction, the argument is the name of the first custom action to execute, and the condition is RADIO_OPTION=1. The second event is DoAction, the argument is the name of the second custom action to execute, and the condition is RADIO_OPTION=2.
    7) Make sure the order of the events for the Next button is correct. The first event should execute the first custom action. The second event should execute the second custom action. The third event should be the existing call to NewDialog with whatever argument was there.

    Hope that helps.

    Rod

Leave a Comment

Security Code: