Thread: Custom Tab Control

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    36

    Question Custom Tab Control

    Hi!

    Well I don't seem to get a custom Tab control to work. I read several Tut's and looked at several Code examples, but I don't get it. I'm trying to do these smaller tabs that are aligned under a parent element, not above. (You know, like the worksheet-tabs in MS Excel)

    I'm using the API, not MFC.

    Thanks for any help.


    PrivatePanic
    "I don't know with what weapons World War III will be fought... but World War IV will be fought with sticks and stones." - Albert Einstein

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I get what you mean and all, but we're going to need to see some code just to see where you are going wrong.

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    36
    well, my problem is I completely don't understand these custom tabs and I'd appreciate some push in the right direction to figure it out by myself. That's why I can't give you any code.... I read the tuts and the chapter about custom tab controls in the MSDN but that didn't help me much... so I thought someone here may explain to me roughly the general usage of the custom tab controls.

    If your answer is "RTFM again until you get it" it's okay too, I willl do that then, ....but maybe here is actually someone who can explain this topic to me in a more understandable way
    "I don't know with what weapons World War III will be fought... but World War IV will be fought with sticks and stones." - Albert Einstein

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    It is always difficult to answer a question like this because one simply doesn't know where to begin, i.e. what it is you don't understand!

    A tab control is created with CreateWindow() using the WC_TABCONTROL class. Initially it has no tabs, you insert them, you can either use SendMessage() with the TCM_INSERTITEM message, or use the TabCtrl_InsertItem() macro. Once you've done this, the tab control sends you WM_NOTIFY messages when the user does anything. WM_NOTIFY returns a pointer to a NMHDR structure which contains the action code, (there are more than one), and the tab which sent it.

    Here is a self contained program which creates a very simple tab control sized to fit the screen, with four tabs. All the tabs do is put a message up saying which has been pressed. Have a look at it and see where you go.

    Incidently, the position of the tabs is simply a style issue, if you want to move them around, look at the TCS_x styles.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    36
    Thanks for that example, but you're right, I'm sorry I didn't give more informations what exactly I'm not able to do. I am able to do the Tab Controls, as you described me, that's not the problem. My problem is to create a Custom Tab Control. What I mean is a Tab Control that has not the standard "Tab graphics" but customized ones. I want to have the smaller, white, trapezoid-shaped Tabs like the Tabs u choose the worksheets in MS Excel with.

    I'll attach a small Screenshot to show these Tabs to u.

    I know I can't use the normal TabCtrl for these Tabs, it has to be a customized one; but I have no Idea how to do that.

    Sorry again for the inconvenience and thanks for any helpful hints

    Pry
    "I don't know with what weapons World War III will be fought... but World War IV will be fought with sticks and stones." - Albert Einstein

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    36
    Okay I figured out that I have to use the TCS_OWNERDRAWFIXED style on my TabControl and that I then have to process the WM_DRAWITEM message.

    MSDN says:
    The tab control sends this message whenever a tab needs to be painted. The lParam parameter specifies the address of a DRAWITEMSTRUCT structure, which contains the index of the tab, its bounding rectangle, and the device context (DC) in which to draw.

    But I still don't know how to implement this. *sigh*
    "I don't know with what weapons World War III will be fought... but World War IV will be fought with sticks and stones." - Albert Einstein

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    OK, briefly this is what you have to do. Not compleate as I am pressed for time (Friday afternoon and all that)
    the msg you will have to deal with to repaint the TAB ctrl is

    Code:
    case WM_DRAWITEM:
    pDrawItem = (DRAWITEMSTRUCT *)lParam;
    if(pDrawItem->hwndItem==hWndTAB_Ctrl)
    {
    //process the paint msg
    }
    
    //To paint the tabs white with black border
    HBRUSH   hWhite=NULL,hBlack=NULL;
    
    hWhite=GetStockObject(WHITE_BRUSH);//get a white brush to draw with
    hBlack=GetStockObject(BLACK_BRUSH);
    FillRect(pDrawItem->hDC,&(pDrawItem->rcItem),hWhite);//paint the area white
    FrameRect(pDrawItem->hDC,&(pDrawItem->rcItem), hBlack);//draw a black frame around tab
    //don't have to delete stock objects but it does not harm and GDI resources must be released
    DeleteObject(hWhite);
    DeleteObject(hBlack);
    
    //text
    //get the text on the tab
    //this will be a macro, you can find this and store the string in sBuffer
    
    //then use this to determine its actual length so you can see if it fits, center it ect.
    GetTextExtentPoint32(pDrawItem->hDC, sBuffer, lstrlen(sBuffer), &Size);
    //Size.cx and Size.cy now contain the 'size' of the string
    //find the center start= (total_width-string_width)/2
    xStart=(int)((pDrawItem->rcItem.right-pDrawItem->rcItem.left)-Size.cx)/2;
    
    TextOut(pDrawItem->hDC, xStart,  pDrawItem->rcItem.top, sBuffer, lstrlen(sBuffer));
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #8
    Registered User
    Join Date
    Jul 2002
    Posts
    36

    Thumbs up

    Hey, many thanks!! I'll try that out

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Yeah, Friday and all that... I started fiddling with this as well and had modified the test program to deal with the WM_DRAWITEM message in much the same way, however, the controls don't look quite right so far. Next week maybe...
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  2. Tab order in Tab Control
    By Halloko in forum Windows Programming
    Replies: 2
    Last Post: 05-08-2005, 11:08 PM
  3. tab control
    By tyouk in forum Windows Programming
    Replies: 6
    Last Post: 02-07-2005, 11:47 PM
  4. Building a tab custom control
    By Mithoric in forum Windows Programming
    Replies: 19
    Last Post: 03-06-2004, 09:34 AM
  5. Disable a tab in control tab?
    By Iron Mike in forum Windows Programming
    Replies: 1
    Last Post: 07-23-2003, 10:50 AM