0
votes

I can't seem to add the certain dialog box in the TAB CONTROL that i've created.

Can someone help me?

I've created tab items (TCITEM) and the tab control using CreateWindow.

tab_handle is an HWND global variable.

//create items for tab
    TCITEM tab1Item;
    tab1Item.mask = TCIF_TEXT;
    tab1Item.pszText = "Tab 1";

    TCITEM tab2Item;
    tab2Item.mask = TCIF_TEXT;
    tab2Item.pszText = "Tab 2";
//create tab
    CreateWindow(WC_TABCONTROL, "Test", TCS_FLATBUTTONS | WS_CHILD | WS_VISIBLE, 10, 20, 450, 230, this->m_hWnd, (HMENU) IDD_DLGTAB1, (HINSTANCE)GetWindowLong(this->m_hWnd, GWL_HINSTANCE), NULL);

//getting of tab
    tab_handle = GetDlgItem(this->m_hWnd, IDD_DLGTAB1);

//inserting of tab items in tab
    RECT tab_rectangle;
    GetClientRect(tab_handle, &tab_rectangle);
    int width  = (tab_rectangle.right - tab_rectangle.left);
    int height = (tab_rectangle.bottom - tab_rectangle.top);
//create dialog
    HWND dialog_handle =  CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG2), tab_handle, (DLGPROC) Tab1Dlg::DlgProc, (LPARAM) lParam);

    TabCtrl_InsertItem(tab_handle, 0, &tab1Item);
    TabCtrl_InsertItem(tab_handle, 1, &tab2Item);


    MoveWindow(dialog_handle, tab_rectangle.left+20, tab_rectangle.top+20,(width - 300),(height - 300), TRUE);

    ShowWindow(dialog_handle, SW_SHOW);
1

1 Answers

0
votes

You have to create the dialog first. Then create the tab control as a child control of the dialog.

It's easier to use the dialog editor to drag and drop a tab control in to dialog. Then you can skip CreateWindow(WC_TABCONTROL...) and use GetDlgItem(dialog_handle, IDC_TAB1) to find the tab control.

You also need to create 2 border-less child dialogs in resource editor (not popup dialog). Then use CreateDialog(0, MAKEINTRESOURCE(IDD_PAGE1), dialog_handle, TabChildProc) to put child dialogs inside the tab.

If making a modal dialog, you may want to use DialogBox instead of CreateDialogParam and do the initialization in WM_INITDIALOG

HINSTANCE hinst = GetModuleHandle(NULL);
HWND dialog_handle = CreateDialogParam(hinst,
    MAKEINTRESOURCE(IDD_DIALOG2), 0, (DLGPROC)Tab1Dlg::DlgProc, (LPARAM)0);
ShowWindow(dialog_handle, SW_SHOW);

RECT rc;
GetClientRect(dialog_handle, &rc);
CreateWindow(WC_TABCONTROL, "Test", TCS_FLATBUTTONS | WS_CHILD | WS_VISIBLE, 
    rc.left + 10, rc.top + 10, 
    rc.right - 20, rc.bottom - 20 - 30, 
    dialog_handle, (HMENU)IDC_TAB1, hinst, NULL);

tab_handle = GetDlgItem(dialog_handle, IDC_TAB1);

TCITEM tci = { 0 };
tci.mask = TCIF_TEXT;
char buf[50];
tci.pszText = buf;

strcpy_s(buf, "Page1");
tci.cchTextMax = strlen(buf);
TabCtrl_InsertItem(tab_handle, 0, &tci);

strcpy_s(buf, "Page2");
tci.cchTextMax = strlen(buf);
TabCtrl_InsertItem(tab_handle, 1, &tci);