views:

1013

answers:

3

How can I make the command button in my VC++ 6.0 dialog visible or invisible on load?

A: 

What do you mean by 'commnad button' exactly ?

Anyway, you need to obtain the handle of the button then call ShowWindow function:

BOOL prevState = ShowWindow( itemHandle, SW_HIDE );
arul
+2  A: 

From the resource editor once you select the button, you can see its properties in the properties window. Here you can set the visible property to true / false. (assuming this functionality is present in 6.0 - i use 2003 now and cannot remember if this used to be present in 6.0)

Add CButton variable

If you want to dynamically change the buttons visibility during load, add a variable for your button using the MFC class wizard. (you are lucky to have this - this wizard seems to have been removed from Visual Studio .NET)

Override CDialog InitDialog

Next override the initdialog function of your dialog box and then once the base InitDialog function has been successfully called, set the buttons showwindow property to SW_HIDE / before showing the dialog box.

Code

BOOL CMyDialog::OnInitDialog() 
   {
   CDialog::OnInitDialog();

   if (ConditionShow)
       m_MyButton.ShowWindow(SW_SHOW);
   else
       m_MyButton.ShowWindow(SW_HIDE);

   return TRUE;
   }
const int cmdShow = ConditionShow ? SW_SHOW : SW_HIDE;m_MyButton.ShowWindow(cmdShow);
Vincent Robert
A: 

You can also do it without adding a CButton variable - just call

In the OnInitDialog method of the window containing the button/control, put in code:

CWnd *wnd = GetDlgItem (YOUR_RESOURCE_NAME_OF_THE_BUTTON) wnd->ShowWindow(SW_SHOW) or SW_HIDE

Tim