Click here to Skip to main content
13,251,998 members (67,125 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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?


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 18-Oct-12 3:55am
Updated 18-Oct-12 5:02am
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:

void CMyApplicationDlg::OnBnClickedButtonHideMe()
    // `IDC_BUTTON_HIDE_ME` is the ID of that button
// Or in case you created that button manualy
void CMyApplicationDlg::OnBnClickedAnotherHideMe()
    // `AnotherHideMeButton` is a CButton class

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=""/>[^]

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

void CMyApplicationDlg::OnBnClickedButtonHideMe()
void CMyApplicationDlg::OnBnClickedAnotherHideMe()
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...

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:

I would like to try his solution, but how to change hbrbackground of an existing window?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


found it,

I overrided OnEraseBkgnd() to avoid some flickering.

this blocked the redrawing of the buttons...

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171114.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100