Click here to Skip to main content
11,630,646 members (74,889 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
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 18-Oct-12 2:55am
Edited 18-Oct-12 4:02am
v2
Comments
Jochen Arndt at 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
good
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
    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:

void CMyApplicationDlg::OnBnClickedButtonHideMe()
{
    this->GetDlgItem(IDC_BUTTON_HIDE_ME)->EnableWindow(FALSE);
}
 
void CMyApplicationDlg::OnBnClickedAnotherHideMe()
{
    this->AnotherHideMeButton->EnableWindow(FALSE);
}
  Permalink  
v3
Comments
Blob_Dlg at 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 at 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?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hello,

found it,

I overrided OnEraseBkgnd() to avoid some flickering.

this blocked the redrawing of the buttons...
  Permalink  

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

  Print Answers RSS


Advertise | Privacy | Mobile
Web03 | 2.8.150723.1 | Last Updated 19 Nov 2012
Copyright © CodeProject, 1999-2015
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