Hiding a control in Windows

stelonix picture stelonix · Jun 8, 2011 · Viewed 18.6k times · Source

I can't figure out how to hide a child window (a control), more specifically a GroupBox and a PushButton. I thought ShowWindow() with SW_HIDE as the second parameter would do the job, but it simply doesn't work. Yet SW_SHOW works just fine. I have the correct window handle for both controls, so that's not the issue.

I googled and all I could find was people asking how to hide dialogs, not controls. Either that or MFC-based applications, which doesn't apply here. I'm using pure Windows API, no MFC.

What am I getting wrong?

EDIT: More info: I'm writing some simple class wrappers for WinApi controls. The WindowsControl class has, along other methods, the following methods for showing and hiding the Control:

void Show() {
    ShowWindow(this->_hWnd,SW_SHOWNOACTIVATE);
}

void Hide() {
    ShowWindow(this->_hWnd,SW_HIDE);
}

Every control inherits from WindowsControl.

This image has the window layout so you understand exactly what I'm doing: http://i.stack.imgur.com/PHQnH.png

When the user clicks inside the "Chipset" Static control, it'll load information for a given Tile (which is stored in an array, but that's irrelevant). Depending on the setting, it'll hide the "Edit bitwall" button on the left and show the empty GroupBox behind it or viceversa. Just to be clear this isn't something wrong with my windows api wrappers, I am getting the correct HWND. Though ShowWindow might not be able to be called from a Window Procedure that isn't the parent's (that'd be weird).

EDIT2: Using C++ with Visual Studio 2008, no MFC, no WTL, no CLR, no .NET

EDIT3: I'll post even more code so it's easier

Inside the static's window procedure, I handle WN_LBUTTONDOWN like this:

case WM_LBUTTONDOWN: {
  ...
  update_tiledata(c, l)


void update_tiledata(GroupBox * c, ListView* l ) {
    ...

   if (chp_copy.Tiles[selectedTile].Pass() == PT_BITWALL) {
          c->Controls(CTL_BTNEDITBIT)->Show();
          c->Controls(CTL_FRPHOLD)->Hide();
   } else {

          c->Controls(CTL_FRPHOLD)->Show();
          c->Controls(CTL_BTNEDITBIT)->Hide();
   }
   update_edits();
}

The ommited code does nothing to affect the classes, as I said before, ShowWindow with SW_HIDE IS getting called, with the correct HWND, but nothing is happening.

Answer

RED SOFT ADAIR picture RED SOFT ADAIR · Jun 8, 2011

A control in a Window or dialog can be hidden using

ShowWindow(hControlWin, SW_HIDE);

In a dialog you can retrive the controls window handle by calling

GetDlgItem(hDlg, < CtrlID >);

Typically you write something like:

ShowWindow(GetDlgItem(hDlg, 2), SW_HIDE);

It would be helpful if you give more information and some code: How did you create the controls? What language, compile and framework did you use?