想知道一下.CTabCtrl怎么样自绘每个项的标签.希望能做个像AntiVir或者卡巴斯基 的那种效果,希望高手能指点一下.不想用别人写的类,谢谢.希望能给个详细点的思路或者代码.THX A LOT!

解决方案 »

  1.   

    http://www.microsoft.com/msj/0599/c/c0599.aspx
      

  2.   

    May 1999--------------------------------------------------------------------------------
    Code for this article: May99CQA.exe (58KB)
    Paul DiLascia is the author of Windows ++: Writing Reusable Code in C++ (Addison-Wesley, 1992) and a freelance consultant and writer-at-large. He can be reached at [email protected] or http://pobox.com/~askpd.
     
    If you remember, last month (April 1999) I showed you how to write a class called CFolderTabCtrl that implements a simple folder-style tab control like the ones found in Microsoft® Excel and Visual Studio®. To demonstrate CFolderTabCtrl, I wrote a little test program FLDRTAB. It's a dialog-based app with a CFolderTabCtrl; when you click one of the tabs, FLDRTAB displays a message indicating which tab you clicked (see Figure 1). 
      
    Figure 1 FLDRTAB  
    FLDRTAB is fine for a test program, but if you want to mimic the look of Microsoft Excel or Visual Studio, there's a bit more work to do. In these applications, the folder tab control shares space with the horizontal scroll bar (see Figure 2). Well gosh, how do they do that? In this column—Folder Tabs, Part Two—I'll show you how to use two new classes, CFolderFrame and CFolderView. 
      
    Figure 2 Folder Tabs and Scroll Bars  
     
    Figure 3 Original DibView  
    Way back in the March 1997 issue, in one of my "MFC Goodies" articles, I wrote a bitmap viewer called DibView. DibView displays both the image and, below it, the information in the BITMAPINFOHEADER struct (see Figure 3). For this month's column, I modified DibView to use the new folder tab classes. The new, improved DibView displays the image and BITMAPINFOHEADER information in separate "pages" selected using the folder tab control. Figure 4 shows DibView with the Image page selected. Figure 5 shows it with the Bitmap Info page selected. There's also a Hex page (raw hex data), which is not shown. Personally, I rather doubt the new DibView represents a UI improvement since it would be better to show all the information at one time, but I'm not out to win any UI design awards in this month's column. I only want to show you how to implement the folder tab/scroll bar combo. 
      
    Figure 4 Modified DibView Image Page  
      

  3.   


    Whenever you want to modify or enhance the MFC application framework in some way, you should aim to touch the framework in as few places as possible. Brain surgery, not demolition, is the model. Keeping that in mind, the basic strategy I adopted was to insert a new window, CFolderFrame, between the frame and the view. Figure 6 illustrates the basic architecture. The main frame (or MDI child frame) contains CFolderFrame as a child window; CFolderFrame in turn contains the view, scroll bars, and folder tab control, and manages the interaction between them. 
      
    Figure 5 DibView Bitmap Info Page  
    From the perspective of a programmer using CFolderFrame, there're only a few things you have to do. First—and this is where you get to apply the brain surgery scalpel—you have to override your frame's OnCreateClient function to create the folder frame window.  
       BOOL CMainFrame::OnCreateClient(..., 
         CCreateContext* pcc)
       {
         return m_wndFolderFrame.Create(this,
           RUNTIME_CLASS(CDIBView), pcc,
           IDR_FOLDERTABS);
       } DibView supports both SDI and MDI versions. In the case of an MDI app, you want to override OnCreateClient in the MDI child frame. OnCreateClient is the function where MFC normally creates the view. Instead, you should create a CFolderFrame. Don't call the base class OnCreateClient! The folder frame will in turn create a view using the runtime class and the create context that you passed. IDR_FOLDERTABS is the ID of the string resource that holds the names of the tabs. If you want to specify tab names dynamically, you can omit this argument and call CFolderFrame::GetFolderTabCtrl to get the folder tab control, then CFolderTabCtrl::AddItem to add items (see last month's column for more details). 
      
    Figure 6 CFolderFrame Architecture  
    Next, you have to add some code to your view. The most important thing is to derive your view from CFolderView instead of CScrollView. You are using a scroll view, aren't you? The whole problem I'm discussing here is how to make the folder tab share space with the scroll bar. If you're not using a scroll view, there's no problem—you can create the folder tab control as a child of your view. 
    Once you've derived your view from CFolderView, you're ready to handle notifications from the tab control. All you have to do is override a new virtual function CFolderView::OnChangedFolder. CFolderView calls it when the user clicks on a new folder tab. For DibView, the implementation is simple: just store the new page number and repaint.  
     void CDIBView::OnChangedFolder(int iPage)
     {
       m_iPage = iPage;
       UpdateScrollSizes();
       Invalidate();
     } 
      

  4.   

    OnPaint中 
    int nTab = GetItemCount();
    int nSel = GetCurSel(); if (!nTab) // no pages added
    return;
    while (nTab--)
    {
    GetItemRect(nTab, &rcItem);
    //根据nTab获得图标 文本信息 重绘rcItem区域
    }