windowswinapiwinapp

WINAPI showing/hiding controls on TabControl


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.


Solution

  • 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.