Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to hide various controls on a Windows MFC Dialog Box App. I am using:

m_MyVariable.ShowWindow(SW_HIDE);

This will hide the parts of the control that are underneath another control, but the parts in the clear are still visible.

What I have tried:

Setting the control's "visible" property to FALSE. This starts the control off as hidden, but when I use ShowWindow(SW_SHOW), the control is visible and I can't hide it after that.

I made a new project with just 2 buttons and one group box, and this works as expected. I tried to compare Styles and ExStyles to see if anything was different, but I don't see anything.
Posted
Comments
Shao Voon Wong 19-Mar-24 7:04am    
I just tried m_Ctrl.ShowWindow(SW_HIDE); to hide an EditBox. It works for me. I suspect your control is not created correctly.
Dave G11. 19-Mar-24 9:59am    
I have a "sanity check" simple project that works as expected too. I can't see what is different between the 2 projects. It is many controls that are behaving incorrectly - MfcButtons, Static Text, Static Group Boxes. I suspect it is something on the dialog box level. The background is white instead of light grey, and I never intentionally changed it.
Shao Voon Wong 19-Mar-24 19:36pm    
Please search for "m_MyVariable.ShowWindow(SW_SHOW);" in your codebase. There might be some of these calls that undo your "m_MyVariable.ShowWindow(SW_HIDE);".
Dave G11. 19-Mar-24 20:11pm    
No, that's not it. I know the fact that the dialog box is white and I can't change it is a big clue.
Shao Voon Wong 19-Mar-24 21:28pm    
The color of your dialog box is a different problem. Is it a custom-drawn control you are trying to hide?

1 solution

I usually disable the window also when hiding it. Make sure you do that and you might need to invalidate the control you are hiding so that it is redrawn.
 
Share this answer
 
Comments
merano99 17-Mar-24 4:18am    
+5, exactly that should help
Dave G11. 18-Mar-24 9:57am    
Hi Rick,

Thanks for responding. I tried setting EnableWindow(FALSE) and Invalidate(), both for the control and the main dialog box, but that is not working either.

Is there perhaps something on the dialog box level, like SHOW_HIDDEN or a transparency setting?

Thanks,
Dave G.
Dave G11. 18-Mar-24 11:05am    
I have another clue. The background of my dialog box is pure white when I run the program. In Visual Studio, in the graphics editor, the dialog box background color is light grey.
Possibly related, I have been switching display resolutions. My development machine is 3840 x 2400. The target machine for the app is 1920 x 1080. I forced my development machine to 1920 x 1080 to see what the graphics will look like on the target machine.
Rick York 19-Mar-24 16:17pm    
I don't think that is very likely. I would guess that you have an OnEraseBkgnd message handler that isn't doing what it should.

I do this kind of thing quite often. So often that I wrote a little function do this. It is called HideDisable and it disables the window and hides it. I don't have it invalidate anything because it is almost always called in OnInitDialog and that causes the entire dialog to be redrawn when it completes. In code where controls are dynamically hidden the entire dialog is invalidated so everything is redrawn.
Dave G11. 20-Mar-24 10:47am    
YES!! Thank-you Rick! I had at some point modified the OnEraseBkgnd function.

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