abcd
abcd

Reputation:

Setting command button visibility in VC++ 6.0?

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

Upvotes: 1

Views: 14438

Answers (4)

Mahbub Alam
Mahbub Alam

Reputation: 368

Only use

ShowDlgItem(Your_DLG_ITEM_ID,1); // visible = true   
ShowDlgItem(Your_DLG_ITEM_ID,0); // visible = false

Upvotes: 1

Tim
Tim

Reputation: 20360

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

Upvotes: 2

computinglife
computinglife

Reputation: 4391

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;
   }

Upvotes: 3

arul
arul

Reputation: 14084

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 );

Upvotes: 1

Related Questions