Click here to Skip to main content
16,016,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a dialog based app.

In the main dialog I want to show or hide some buttons, according to some option settings in my program.

I declare a control value for my button: ctrl_button.
to show or hide the button I call ctrl_button.ShowWindow(SW_HIDE); or SW_SHOW

followed by Invalidate();

however this does not seem to work.


I do the same in a child dialog and this works properly.
If I call parent->Invalidate(); from the child, the button in the main will hide!!!
Also when I minimize-maximize the dialog the button will hide...

But when I call Invalidate() in the main nothing happens.
The button is still shown on the screen, but is not clickable.

I tried several solutions involving UpdateWindow, RedrawWindow,...

Someone has an idea?

Thanks


PS a strange thing occurs:
I set the button default to invisible.
ShowWindow(SW_SHOWS) the button
but afterwards ShowWindow(SW_HIDE) does not hide it again
Posted
Updated 18-Oct-12 4:02am
v2
Comments
Jochen Arndt 18-Oct-12 11:35am    
I hope you did not want to hide or disable the button that has the focus. That would not work. To hide/disable such a button, you must set the focus to another one using GotoDlgCtrl() before doing so. Note also that you must return FALSE from OnInitDialog() when removing the focus from the default button.

Let's say I added some button named `Hide Me` in my dialog and I set the ID to IDC_BUTTON_HIDE_ME. Now, all I need to hide it is to double click on that button and write:

C++
void CMyApplicationDlg::OnBnClickedButtonHideMe()
{
    // `IDC_BUTTON_HIDE_ME` is the ID of that button
    this->GetDlgItem(IDC_BUTTON_HIDE_ME)->ShowWindow(SW_HIDE);
}

// Or in case you created that button manualy
void CMyApplicationDlg::OnBnClickedAnotherHideMe()
{
    // `AnotherHideMeButton` is a CButton class
    this->AnotherHideMeButton->ShowWindow(SW_HIDE);
}


Quote:
In the main dialog I want to show or hide some buttons, according to some option settings in my program.


Just a simple note, If these options are optional like the proxy settings in this DropBox dialog:

<img src="https://community.mcafee.com/servlet/JiveServlet/showImage/2-200568-16528/dropbox1.JPG"/>[^]

It's a good idea to use enable and disable instead of hide and show:

C++
void CMyApplicationDlg::OnBnClickedButtonHideMe()
{
    this->GetDlgItem(IDC_BUTTON_HIDE_ME)->EnableWindow(FALSE);
}

void CMyApplicationDlg::OnBnClickedAnotherHideMe()
{
    this->AnotherHideMeButton->EnableWindow(FALSE);
}
 
Share this answer
 
v3
Comments
Blob_Dlg 19-Oct-12 3:37am    
Thank you Barakat,

But I allready tried that.
The solution as you describe works in my child dialog.
But not in the main.

I want to hide/show buttons to keep it simple for the user.
It seems easier to me if you only see 2 clickable buttons instead of 10 buttons and 8 of them are grayed...

Greetings
Blob_Dlg 19-Nov-12 7:15am    
Still no luck in hiding main window buttons

IsWindowVisible returns 0, indicating the buttons are not visible, but still they are visible on the screen, only when I minimize the dialog and reopen, it will hide the buttons.


I found some one having the same issue:
http://www.cplusplus.com/forum/windows/64274/

I would like to try his solution, but how to change hbrbackground of an existing window?
Hello,

found it,

I overrided OnEraseBkgnd() to avoid some flickering.

this blocked the redrawing of the buttons...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900