0

How can I add some elements(window) in my tab?

Use these:

INITCOMMONCONTROLSEX icex;
TCITEMW tie;

WM_CREATE:

icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_TAB_CLASSES;

InitCommonControlsEx(&icex);

Tab = CreateWindowW(WC_TABCONTROLW, NULL, WS_CHILD | WS_VISIBLE, 
            0, 0, 200, 150, hwnd, (HMENU)ID_TABCTRL, NULL, NULL);

CreateWindowW(WC_BUTTONW, L"Add", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
            250, 50, 100, 25, hwnd, (HMENU)BTN_ADD, NULL, NULL);

In BTN_ADD I make two tabs.

case BTN_ADD: {
    tie.mask = TCIF_TEXT;
    tie.pszText = (LPWSTR)L"TAB1";
    SendMessageW(Tab, TCM_GETITEMCOUNT, 0, 0);
    SendMessageW(Tab, TCM_INSERTITEMW, 1, (LPARAM)(LPTCITEM)&tie);

    tie.mask = TCIF_TEXT;
    tie.pszText = (LPWSTR)L"TAB2";
    SendMessageW(Tab, TCM_GETITEMCOUNT, 0, 0);
    SendMessageW(Tab, TCM_INSERTITEMW, 2, (LPARAM)(LPTCITEM)&tie);

    SendMessageW(Tab, TCM_GETITEMCOUNT, 0, 0);
    //Add item in tab
    CreateWindowW(WC_BUTTONW, L"BTN", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
    50, 50, 30, 30, Tab, NULL, NULL, NULL);

    break;
}

But this button added in hwnd (main), and when I open other tab, I continue to see this button. I need add content in a certain tab.

First tab

image

Second tab

image

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
lostsky25
  • 85
  • 1
  • 10
  • 2
    Tab controls are an illusion. They really just consist of the individual tabs, and nothing more. The [documentation](https://learn.microsoft.com/en-us/windows/win32/controls/tab-controls) explains, how to use tab controls. – IInspectable Jan 07 '20 at 17:12
  • Ok, I read the documentation and understand, how it 's works. , thanks. Now I use MoveWindow() and can find out tab number via SendMessageW(Tab, TCM_GETCURFOCUS, 0, 0). – lostsky25 Jan 07 '20 at 19:44
  • Everything is store in case WM_MOUSEACTIVE, but I need some message, which will alow update windows normally. What this message? I can't find in MSDN – lostsky25 Jan 07 '20 at 19:44
  • If everything is stored in WM_MOUSEACTIVE, your code is wrong – user2120666 Jan 07 '20 at 19:52
  • [Tab selection](https://docs.microsoft.com/en-us/windows/win32/controls/tab-controls#tab-selection): *"You must process [TCN_SELCHANGE](https://docs.microsoft.com/en-us/windows/win32/controls/tcn-selchange) to display the incoming page in the display area. This might simply entail changing the information displayed in a child window. More often, each page consists of a child window or dialog box. In this case, an application might process this notification by destroying or hiding the outgoing child window or dialog box and by creating or showing the incoming child window or dialog box."* – IInspectable Jan 07 '20 at 20:04
  • Do you mean `WM_NOTIFY` message? which sent by a common control to its parent window when an event has occurred or the control requires some information. – Strive Sun Jan 08 '20 at 05:19
  • No, I don't use WM_MOUSEACTIVE for everything. Yes, I meant WM_NOTIFY. Messages from tabs are being processed in WM_NOTIFY. – lostsky25 Jan 08 '20 at 14:24

1 Answers1

0

I solved a problem. Understand, that need use a MoveWindow function. These tabs isn't content, but content attachment to window (Tab). I just created Tab via:

        Tab = CreateWindowW(WC_TABCONTROLW, NULL, WS_CHILD | WS_VISIBLE,
            0, 0, TAB_WEIGHT, TAB_HEIGHT, 
            hwnd, (HMENU)ID_TABCTRL, NULL, NULL);

Then I put down a few window (ListBox) on the Tab (which window).

        ListBoxProcesses = CreateWindowEx(WS_EX_CLIENTEDGE, L"ListBox", NULL,
            WS_CHILD | WS_VISIBLE | LBS_STANDARD | LBS_WANTKEYBOARDINPUT,
            0, 50, TAB_WEIGHT - 20, TAB_HEIGHT - 100,
            Tab, (HMENU)ID_LIST, NULL, NULL);

        ListBoxModules = CreateWindowEx(WS_EX_CLIENTEDGE, L"ListBox", NULL,
            WS_CHILD | WS_VISIBLE | LBS_STANDARD | LBS_WANTKEYBOARDINPUT,
            TAB_WEIGHT, 50, TAB_WEIGHT - 20, TAB_HEIGHT - 100,
            Tab, (HMENU)ID_LIST, NULL, NULL);

But there is one feature. First window (ListBoxProcesses) has a horizontal position 0. But second window (ListBoxModules) has TAB_WEIGHT. After I choose other tab, I call a MoveWindow function and its shifts my content.

Btw, yes, I understand that need use WM_NOTIFY message which contains this:

switch (wParam)
        {
        case ID_TABCTRL: {
            switch (SendMessageW(Tab, TCM_GETCURFOCUS, 0, 0))
            {
                case FIRST_PAGE: {

                    MoveWindow(ListBoxProcesses, 0, 50, TAB_WEIGHT - 20, TAB_HEIGHT - 100, TRUE);
                    MoveWindow(ListBoxModules, TAB_WEIGHT, 50, TAB_WEIGHT - 20, TAB_HEIGHT - 100, TRUE);

                    break;
                }
                case SECOND_PAGE: {

                    MoveWindow(ListBoxProcesses, -TAB_WEIGHT, 50, TAB_WEIGHT - 20, TAB_HEIGHT - 100, TRUE);
                    MoveWindow(ListBoxModules, 0, 50, TAB_WEIGHT - 20, TAB_HEIGHT - 100, TRUE);

                    break;
                }
                default:
                    break;
            }
            break;
        }
        default:
            break;
        }

First tab Second tab

lostsky25
  • 85
  • 1
  • 10
  • Maybe you can change the size of first window and second window in `WM_SIZE` in advance. By the way, due to the change of tab control, use `WM_NOTIFY` which contains `TCN_SELCHANGE` and `TCN_SELCHANGING` is a better way. – Strive Sun Jan 09 '20 at 09:51