-2

What is convenient way of handling showing/hiding of controls on TabControl in Windows API? I have seen examples where was implemented reaction on message WM_NOTIFY/TCN_SELCHANGE and then iterating thru all controls and picking what to show/hide by the code. I would expect Windows have internal a mechanism to handle this like to make a parent or associate the control with specific tab.

odo
  • 23
  • 4
  • 3
    Put the controls for each tab on separate dialog/parent windows, then use the tab events to show/hide each dialog/parent as needed. This is mentioned in the [documentation](https://learn.microsoft.com/en-us/windows/win32/controls/tab-controls#display-area): "*The display area of a tab control is the area in which an application displays the current page. Typically, an application creates a child window or dialog box, setting the window size and position to fit the display area.*" – Remy Lebeau Jan 22 '21 at 17:34

1 Answers1

3

The usual way is to use CreateDialog to create a modeless dialog to contain the child controls for each tab and then assign that modeless dialog's HWND (or some other value that leads to the HWND) to the TCITEM'S lParam.

Then during TCN_SELCHANGE you are handed enough information (the TCITEM's lParam is one of the pieces provided) to simply hide the old tab's modeless dialog and show the new tab's modeless dialog.

I prefer making those modeless dialogs child windows of the tab control itself because it makes calculating position easy using TCM_ADJUSTRECT with no need to use MapWindowPoints.

SoronelHaetir
  • 14,104
  • 1
  • 12
  • 23