VS2005,用标准Windows类库,怎么操作TabControl啊?
看了很多例子,都是MFC的,有没有不是MFC,不是.NET的例子呢?
在工具栏里面只看到一个TabControl的控件,查了MSDN,发现要添加TabPage,TabPage在.net下面的吧?
如果不用这样的操作的话,怎么实现?

解决方案 »

  1.   

    建立tab控件,然后给每页都嵌入对话框,然后对话框里实现具体内容!MSDN上有API的例子!如下:
    // DoCreateTabControl - creates a tab control, sized to fit the 
    //     specified parent window's client area, and adds some tabs. 
    // Returns the handle to the tab control. 
    // hwndParent - parent window (the application's main window). 
     
    HWND WINAPI DoCreateTabControl(HWND hwndParent) 

        RECT rcClient; 
        HWND hwndTab; 
        TCITEM tie; 
        int i; 
     
        // Get the dimensions of the parent window's client area, and 
        // create a tab control child window of that size. 
        GetClientRect(hwndParent, &rcClient); 
        InitCommonControls(); 
        hwndTab = CreateWindow( 
            WC_TABCONTROL, "", 
            WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, 
            0, 0, rcClient.right, rcClient.bottom, 
            hwndParent, NULL, g_hinst, NULL 
            ); 
        if (hwndTab == NULL) 
            return NULL; 
     
        // Add tabs for each day of the week. 
        tie.mask = TCIF_TEXT | TCIF_IMAGE; 
        tie.iImage = -1; 
        tie.pszText = g_achTemp; 
     
        for (i = 0; i < 7; i++) { 
            LoadString(g_hinst, IDS_FIRSTDAY + i, 
                    g_achTemp, sizeof(g_achTemp)/sizeof(g_achTemp[0])); 
            if (TabCtrl_InsertItem(hwndTab, i, &tie) == -1) { 
                DestroyWindow(hwndTab); 
                return NULL; 
            } 
        } 
        return hwndTab; 
    } VOID WINAPI OnTabbedDialogInit(HWND hwndDlg) 

        DLGHDR *pHdr = (DLGHDR *) LocalAlloc(LPTR, sizeof(DLGHDR)); 
        DWORD dwDlgBase = GetDialogBaseUnits(); 
        int cxMargin = LOWORD(dwDlgBase) / 4; 
        int cyMargin = HIWORD(dwDlgBase) / 8; 
        TCITEM tie; 
        RECT rcTab; 
        HWND hwndButton; 
        RECT rcButton; 
        int i; 
     
        // Save a pointer to the DLGHDR structure. 
        SetWindowLong(hwndDlg, GWL_USERDATA, (LONG) pHdr); 
     
        // Create the tab control. 
        InitCommonControls(); 
        pHdr->hwndTab = CreateWindow( 
            WC_TABCONTROL, "", 
            WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, 
            0, 0, 100, 100, 
            hwndDlg, NULL, g_hinst, NULL 
            ); 
        if (pHdr->hwndTab == NULL) {
            // handle error
        }
     
        // Add a tab for each of the three child dialog boxes. 
        tie.mask = TCIF_TEXT | TCIF_IMAGE; 
        tie.iImage = -1; 
        tie.pszText = "First"; 
        TabCtrl_InsertItem(pHdr->hwndTab, 0, &tie); 
        tie.pszText = "Second"; 
        TabCtrl_InsertItem(pHdr->hwndTab, 1, &tie); 
        tie.pszText = "Third"; 
        TabCtrl_InsertItem(pHdr->hwndTab, 2, &tie); 
     
        // Lock the resources for the three child dialog boxes. 
        pHdr->apRes[0] = DoLockDlgRes(MAKEINTRESOURCE(DLG_FIRST)); 
        pHdr->apRes[1] = DoLockDlgRes(MAKEINTRESOURCE(DLG_SECOND)); 
        pHdr->apRes[2] = DoLockDlgRes(MAKEINTRESOURCE(DLG_THIRD)); 
     
        // Determine the bounding rectangle for all child dialog boxes. 
        SetRectEmpty(&rcTab); 
        for (i = 0; i < C_PAGES; i++) { 
            if (pHdr->apRes[i]->cx > rcTab.right) 
                rcTab.right = pHdr->apRes[i]->cx; 
            if (pHdr->apRes[i]->cy > rcTab.bottom) 
                rcTab.bottom = pHdr->apRes[i]->cy; 
        } 
        rcTab.right = rcTab.right * LOWORD(dwDlgBase) / 4; 
        rcTab.bottom = rcTab.bottom * HIWORD(dwDlgBase) / 8; 
     
        // Calculate how large to make the tab control, so 
        // the display area can accommodate all the child dialog boxes. 
        TabCtrl_AdjustRect(pHdr->hwndTab, TRUE, &rcTab); 
        OffsetRect(&rcTab, cxMargin - rcTab.left, 
                cyMargin - rcTab.top); 
     
        // Calculate the display rectangle. 
        CopyRect(&pHdr->rcDisplay, &rcTab); 
        TabCtrl_AdjustRect(pHdr->hwndTab, FALSE, &pHdr->rcDisplay); 
     
        // Set the size and position of the tab control, buttons, 
        // and dialog box. 
        SetWindowPos(pHdr->hwndTab, NULL, rcTab.left, rcTab.top, 
                rcTab.right - rcTab.left, rcTab.bottom - rcTab.top, 
                SWP_NOZORDER); 
     
        // Move the first button below the tab control. 
        hwndButton = GetDlgItem(hwndDlg, BTN_CLOSE); 
        SetWindowPos(hwndButton, NULL, 
                rcTab.left, rcTab.bottom + cyMargin, 0, 0, 
                SWP_NOSIZE | SWP_NOZORDER); 
     
        // Determine the size of the button. 
        GetWindowRect(hwndButton, &rcButton); 
        rcButton.right -= rcButton.left; 
        rcButton.bottom -= rcButton.top; 
     
        // Move the second button to the right of the first. 
        hwndButton = GetDlgItem(hwndDlg, BTN_TEST); 
        SetWindowPos(hwndButton, NULL, 
            rcTab.left + rcButton.right + cxMargin, 
            rcTab.bottom + cyMargin, 0, 0, 
            SWP_NOSIZE | SWP_NOZORDER); 
     
        // Size the dialog box. 
        SetWindowPos(hwndDlg, NULL, 0, 0, 
            rcTab.right + cyMargin + 
            2 * GetSystemMetrics(SM_CXDLGFRAME), 
            rcTab.bottom + rcButton.bottom + 2 * cyMargin + 
            2 * GetSystemMetrics(SM_CYDLGFRAME) + 
            GetSystemMetrics(SM_CYCAPTION), 
            SWP_NOMOVE | SWP_NOZORDER); 
     
        // Simulate selection of the first item. 
        OnSelChanged(hwndDlg); 

     
    // DoLockDlgRes - loads and locks a dialog box template resource. 
    // Returns the address of the locked resource. 
    // lpszResName - name of the resource 
     
    DLGTEMPLATE * WINAPI DoLockDlgRes(LPCSTR lpszResName) 

        HRSRC hrsrc = FindResource(NULL, lpszResName, RT_DIALOG); 
        HGLOBAL hglb = LoadResource(g_hinst, hrsrc); 
        return (DLGTEMPLATE *) LockResource(hglb); 

     
      

  2.   

    常用这些宏:TabCtrl_InsertItem、TabCtrl_DeleteItem、TabCtrl_GetCurSel、TabCtrl_SetCurSel。
    在MSDN中输入TabCtrl_可以查看其它相关的宏。
      

  3.   

    关键还是消息宏,除了TabCtrl,很多控件都有消息宏, 实际上都离不开SendMessage或PostMessage这两个API函数.
      

  4.   

    http://www.vckbase.com/document/viewdoc/?id=398
      

  5.   

    讨厌楼上的啊,导出贴这个,都说了不要MFC的了
      

  6.   

    呵呵,这边不是有提问的智慧么,能找的都找了一次了。只是没找到不用MFC的。很是郁闷而已。
      

  7.   

    要添加几个页面就创建几个Child style类型的对话框,分别与tab控件关联if (childdlg1.m_hWnd == NULL)
    {
    childdlg1.Create(IDD_CHILD_DLG,&m_tabctrl);
    }
    切换页面就是显示或隐藏子对话框而已
      

  8.   

    参看下面文章:
    http://www.joyvc.cn/GuiAndWindows/GuiAndWindows00004.html
      

  9.   

    嘿嘿,MFC就好办啦。在CodeProject找到一篇C的。先研究一下。
      

  10.   

    贴一个链接,这个例子很好,且,可以直接用了:
    http://www.codeproject.com/KB/winsdk/Win32SDK_C_TabCtrl.aspx