Monday, August 07, 2006
« The Microsoft Interview | Main | Geek Dinner - August 22nd, 2006 »

I wrote this function a long time ago, but stumbled across it again today when I needed the functionality.

I've been updating a custom installer wherein I needed the ability to programmatically enable/disable a control on the dialog.  Unfortunately, there is no mechanism built-in (I'm using InstallShield X) that provides this functionality.

This simple function takes a dialog box name (which is a string), the id of the control (an integer), and the desired enabled/disabled state (a boolean):

prototype void SetCtrlEnabled(STRING, NUMBER, BOOL);

function void SetCtrlEnabled(szDialogName, ctlId, enabled)
   HWND hWndDlg, hWndItem;
begin
   hWndDlg = CmdGetHwndDlg( szDialogName );
   hWndItem = GetDlgItem( hWndDlg, ctlId );
   if ( IsWindow(hWndItem) ) then
      EnableWindow( hWndItem, enabled );
   endif;
end;

You can call this function with the following code:

#define DIALOG_MYCUSTOMDIALOG "MyCustomDialog"
#define RES_CTL_TXTSAMPLE     1000

SetCtrlEnabled( DIALOG_MYCUSTOMDIALOG, RES_CTL_TXTSAMPLE, TRUE );

Monday, August 07, 2006 1:32:00 PM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |  Comments [1]  |  Trackback