Link to home
Start Free TrialLog in
Avatar of Anjeneya Murthy
Anjeneya MurthyFlag for India

asked on

Unable to hide controls using GetDlgItem(IDC_STATIC_NOTE)->ShowWindow(SW_HIDE)

I have a dialog that is derived from our specific base class that is inturn derived from CDialog class
This dialog contains a combobox with combobox items in it (string)
There is a group box, labels, checkbox and a text box as well (I will call them grouped controls for this discussion)
If I select an item in index 0 from combo box, the Grouped controls are shown and if I select an item in index 1 from combo box, the group controls should be hidden
I have used the code to show or hide the controls as
void MyDerivedClass::HideMyControls(bool hide)
{
	int param = (false == hide)? SW_SHOW : SW_HIDE;
	
	CWnd* pCtrl = GetDlgItem(IDC_ENABLE_TP_DIRECTORY);	
	CRect myRect;
	pCtrl->GetClientRect(myRect);	

	GetDlgItem(IDC_STATIC_NOTE)->ShowWindow(param);//This is label control
	GetDlgItem(IDC_STATIC_DIR_NAME)->ShowWindow(param);//This is label control
	GetDlgItem(IDC_EDIT_TP_DIRECTORY)->ShowWindow(param);//This is text control
	GetDlgItem(IDC_STATIC_TP_GRPBOX)->ShowWindow(param);//This is label control
	InvalidateRect(myRect);	
	UpdateWindow();
}

Open in new window

The issue is the controls are still seen on the screen even after the above method is called with true parameter. If I move some other window on top of the (supposed to be) hidden controls, then it is actually disappears. So this seems to be a refresh issue. My assumption is that the InvalidateRect and UpdateWindow should have taken care of repainitng this. but is not happening.
Tried with InvalidateRect(NULL) to paint the whole screen, but still no use.

Could you please suggest how I can hide the controls? any clean way of doing this?

Note: when the controls are (supposed to be) hidden but are still seen on the screen, I will not be able to perform any action on those controls (like setting checkbox or typing in the text box).
So I believe that the controls are marked as hidden but not painted.
Avatar of Zoppo
Zoppo
Flag of Germany image

Hi yamurthy,

what kind of windows is it, just a 'normal' window, CWnd-derived, or a dialog, CDialog-derived?

Do you have implemented message handler for messages which may affect painting like i.e. OnPaint, OnCtlColor, OnEraseBkgnd? Do you somewhere lock/unlock drawing using CWnd::SetRedraw()? Do you somewhere change the window-region (SetWindowRgn)? Does the window have one of the styles WS_CLIPCHILDREN or WS_EX_TRANSPARENT set?

Is there anything else in your code where you think it's probably unusual, i.e. some message handlers/virtual functions, where the appropriate base class function is not called.

ZOPPO
Avatar of Anjeneya Murthy

ASKER

This is CDialog Derived. We have not implemented/handled any of the above messages. As far as I see from the code, we are not using SetRedraw method.
No we are not changing the window region!
Rechecked and I dont see WS_CLIPCHILDREN or WS_EX_TRANSPARENT set.

I do see a method in our derived class from CDialog with a comment telling the dialog is not being refreshed for some unknown reason and so they have written a virtual method to first hide and then un hide the window. For them it has worked and I tried the same, it does not work!!

Very strange :(
Yes, it's indeed strange. There must be something unusual since the dialog doesn't behave as CDialog-derived dialogs usually do.

One thing I don't understand: you mentioned a 'virtual' function - where is this implemented? If CDialog is the base class of your dialog I don'T understand it. Or do you have a CDialog-derived class as base class of your dialog?

BTW: Without seeing some code it's extremely hard to give further hints, do you think you coupd probably post some, i.e. the header file and the message map of the involved class(es)?

ZOPPO
I have a base class that is derived from CDialog. The virtual function is in the base class.
SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Issue was not solved, closed with my workaround.
Zoppo has spent his time in assisting me and so marking his comment as assisting.