Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to enable/disable a groupbox

Status
Not open for further replies.

martijnF

Programmer
Sep 19, 2001
5
NL
Hi there!

I want to enable/disable a group box.

Since a groupbox is in fact a CButton I thought that it would be easy using code like:

GetDlgItem(IDC_GROUPBOX)->EnableWindow(true);
or
CButton* grb = (CButton*) GetDlgItem(IDC_GROUPBOX);
grb->EnableWindow(true);

I even tried a CWnd* in stead of a CButton*, but every time the EnableWindow function returns an error, stating that the groupbox is not a window and thus cannot be enabled/disabled.

I must be doing something terribly wrong...but WHAT????

Regards,

Martijn
 
Maybe doesn't help too much, but both your methods work fine for me... :) Hope that this helped! :)
 
Hi,
It seems to me, that you are trying it wrong time. ( before creation or after destrying of HWND of underlying window )
It is in dialog try it in OnInitDialog.
Maybe this could be the point.
 
The place I call the code above is in a dialog function that is invoked by OnInitDialog...
It must be something else, maybe some weird VC++ setting? B-(

By the way: I don't have the IDC_GROUPBOX mapped to a value or control (in DoDataExchange).

 
Doesn't matter with the code you're using, but that approach works too BTW.

Where is this code "called from OnInitDialog"? :) Hope that this helped! :)
 
I guess you want to know whether I call the code before or after the CDialog::OnInitDialog()...
Here's my OnInitDialog:

BOOL CDataConversionDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//...
SetControlStates(); // <= this function calls the code
return TRUE;
}

void CDataConversionDlg::SetControlStates()
{
UpdateData();
//...
// Disable progress groupbox
GetDlgItem( IDC_GRBPROGRESS )->EnableWindow(false);

return;
}


It's abacadabra to me!


 
What exactly is the error? ASSERT IsWindow() in CWnd::EnableWindow()? :) Hope that this helped! :)
 
The obvious explanation is that your IDC_GRBPROGRESS is incorrect, maybe from another dialog or so? I suggest checking with the actual id in the properties for the control. :) Hope that this helped! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top