2

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.

stelonix
  • 656
  • 1
  • 5
  • 23

2 Answers2

8

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?

RED SOFT ADAIR
  • 11,294
  • 10
  • 48
  • 83
  • What is this->_hWnd in your code? Is this the hwnd of the control or of its parent window? Did you try SW_SHOW instead of SW_SHOWNOACTIVATE? – RED SOFT ADAIR Jun 08 '11 at 19:45
  • _hWnd is the control's HWND. The parent's is also in the class as _parent. Also, I was first trying with SW_SHOW and it didn't work, so I switched to SW_SHOWNOACTIVATE. – stelonix Jun 08 '11 at 20:01
  • As far as i can tell the calls you make are correct by themselves - They are used in all windows applications. So there must be a problem somewhere else. You got to debug this. – RED SOFT ADAIR Jun 09 '11 at 09:29
  • If I resize the main window, the button will be hidden. Does that help? – stelonix Jun 14 '11 at 11:19
  • Just to add: I just made the button's parent the main window, and now SW_HIDE does work, so this seems to be an issue with GroupBoxes. – stelonix Jun 14 '11 at 11:57
1

I think the function call you want is EnableWindow I have used this before to disable a button on a form. You will need to get an handle to the Window (object) first though so you might want to use EnumChildWindows to iterate through all the controls to find the one you want.

Matt Wilko
  • 25,893
  • 10
  • 85
  • 132