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
Second tab
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;
}