Adding to a tab window

This is a discussion on Adding to a tab window within the Windows Programming forums, part of the Platform Specific Boards category; I'm looking to add a bitmap image to some tabs and I keep coming up empty handed. I know there ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    416

    Adding to a tab window

    I'm looking to add a bitmap image to some tabs and I keep coming up empty handed. I know there are plenty of examples on CodeProjects/CodeGuru, on MSDN, and through Google, but I am not finding anything on how to load a bitmap to a tab. I tried showing and hiding the image with tab selection but when the wanted tab is selected the bitmap covers up the tabs even if its positioned out of the tabs way. They still seem to disappear. I tried loading a bitmap to the handle of the tab window and still nothing works. I have been racking my brain on this for a couple days and cannot get it to work. Is there a way to do this, or is it really in depth, or what?

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Your post makes it sound like you're doing this the wrong way. First, what exactly are you trying to do? Second, what have you done thus far? (Your code?)

    If you're trying to put an image in the _tab_ part of a tab control, then TabCtrl_SetItem might be the function (well, macro) you want. Read the docs, see if that's what you're looking for. (See the relevant member in TCITEM, iImage - you'll also need to load in an image list. Works much the same as ListViews I think, call TabCtrl_SetImageList)

    If you're trying to put an image in the _body_ part of a tab control, show us what you're doing thus far.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    I guess I was pretty vague. I would like to add a picture that is, right now, in bitmap to the body part of a tab. I don't need an image in the tab/title part of the tab window. I have tried a couple approaches so far. One was loading the bitmap with the owner window being the dialog that owns the tab window. That did not work as it covered the tab window entirely and tabs were not viewable. Then I tried loading the bitmap so the tab window was the owner. That did not work as the picture did not show up on any tab, however, the tabs were viewable/selectable. Then I tried having it load the bitmap when a certain tab was selected, and that obviously failed. I did not think the last one would work, but it was worth a shot. I do not know if there is a way to make the bitmap in to a window, or the like, so I can show/hide it. Here is the entire section where my tab/bitmap code is.

    EDIT: I'm actually still confused on how text is added to the tab bodies (using a resource dialog?), but that is not the issue here.

    Code:
    BOOL CALLBACK MathTableProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        HDC hDC, MemDCMathTable, hdc, t_hDC;
        PAINTSTRUCT Ps, ps;
        HBITMAP bmpMathTable;
        TCITEM tcitem;
        NMHDR *pNMHdr;
    
        int tabctrl[10];
    
        switch(Message)
        {
            case WM_NOTIFY:
            {
                pNMHdr = (NMHDR *) lParam;
    
                if (pNMHdr->code == TCN_SELCHANGE)
                {
                    int tabnum = TabCtrl_GetCurSel((HWND)pNMHdr->hwndFrom);
    
                    hDC = GetDC(hwndTab);
    
                    if(tabnum == 0){/* nothing right now */}
    
                    ReleaseDC(hwndTab, hDC);
    
                }
                break;
            }
    
            case WM_INITDIALOG:
            {
                RECT rect;
                mathtablehwnd = hwnd;
    
                GetClientRect(hwnd, &rect);
                InitCommonControls();
    
                //Create tabbed window
                hwndTab = CreateWindow(WC_TABCONTROL,"",WS_CHILD|WS_VISIBLE,
                    0,0,rect.right,rect.bottom,mathtablehwnd,NULL,
                    (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
    
                //Set up tabs
                tcitem.mask = TCIF_TEXT;
                tcitem.iImage = -1;
                //Create tabs
                tcitem.pszText = "Pre-Algebra"; tabctrl[0] = TabCtrl_InsertItem(hwndTab, 0, &tcitem);
                tcitem.pszText = "Algebra"; tabctrl[1] = TabCtrl_InsertItem(hwndTab, 1, &tcitem);
                tcitem.pszText = "Trigonometry"; tabctrl[2]= TabCtrl_InsertItem(hwndTab, 2, &tcitem);
                tcitem.pszText = "Geometry"; tabctrl[3] = TabCtrl_InsertItem(hwndTab, 3, &tcitem);
                tcitem.pszText = "Calculus"; tabctrl[4] = TabCtrl_InsertItem(hwndTab, 4, &tcitem);
    
    
    
                //Change tab font
                SendMessage (hwndTab,WM_SETFONT,(WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
    
                GetClientRect(hwndTab, &rect);
    /*
                prealghwnd = CreateWindow("STATIC","",WS_CHILD|WS_VISIBLE,
                    rect.left+5,rect.top+25,rect.right-7,rect.bottom-27,hwndTab,NULL,
                    (HINSTANCE)GetWindowLong(hwndTab,GWL_HINSTANCE),NULL);
    */
    
                TabCtrl_SetCurSel(hwndTab,0);
                ShowWindow(prealghwnd,SW_SHOW);
    
            }
            break;
    
            case WM_PAINT:
    
                hDC = BeginPaint(hwndTab, &Ps);
                // Load the bitmap from the resource
                if(!(bmpMathTable = LoadBitmap(hInstance, MAKEINTRESOURCE(IDD_MATH))))
                    MessageBox(hwnd,"error","error",MB_OK);
                // Create a memory device compatible with the above DC variable
                MemDCMathTable = CreateCompatibleDC(hDC);
                // Select the new bitmap
                SelectObject(MemDCMathTable, bmpMathTable);
                // Copy the bits from the memory DC into the current dc
                BitBlt(hDC, 15, 45, 250, 150, MemDCMathTable, 0, 0, SRCCOPY);
                // Restore the old bitmap
                DeleteDC(MemDCMathTable);
                DeleteObject(bmpMathTable);
                EndPaint(hwndTab, &Ps);
    
            break;
    Last edited by scwizzo; 07-15-2008 at 08:28 PM.

  4. #4
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Figured it out. For future reference you need to SendMessage() to a static window with the STM_SETIMAGE message. Here is what it looks like.

    Code:
            case WM_INITDIALOG:
            {
                RECT rect;
                tablehwnd = hwnd;
    
                //Get the size of the initial window space to work with
                GetClientRect(hwnd, &rect);
                InitCommonControls();
    
                //Create tabbed window
                hwndTab = CreateWindow(WC_TABCONTROL,"",WS_CHILD|WS_VISIBLE,
                    0,0,rect.right,rect.bottom,tablehwnd,NULL,
                    (HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
    
                //Set up tabs
                tcitem.mask = TCIF_TEXT;
                tcitem.iImage = -1;
    
                //Create tabs
                tcitem.pszText = "Tab 1"; tabctrl[0] = TabCtrl_InsertItem(hwndTab, 0, &tcitem);
                tcitem.pszText = "Tab 2"; tabctrl[1] = TabCtrl_InsertItem(hwndTab, 1, &tcitem);
                tcitem.pszText = "Tab 3"; tabctrl[2]= TabCtrl_InsertItem(hwndTab, 2, &tcitem);
                tcitem.pszText = "Tab 4"; tabctrl[3] = TabCtrl_InsertItem(hwndTab, 3, &tcitem);
                tcitem.pszText = "Tab 5"; tabctrl[4] = TabCtrl_InsertItem(hwndTab, 4, &tcitem);
    
                //Change tab font
                SendMessage (hwndTab,WM_SETFONT,(WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
    
                //Get the size of the tab window
                GetClientRect(hwndTab, &rect);
    
                //create static window for tabbed bitmap
                hwndStatic= CreateWindow(WC_STATIC,"",
                    WS_CHILD|SS_BITMAP|WS_VISIBLE,
                    rect.left+3,rect.top+23,rect.right-7,rect.bottom-27,hwndTab,NULL,
                    (HINSTANCE)GetWindowLong(hwndTab,GWL_HINSTANCE),NULL);
    
                //if static window couldn't be loaded
                if(!hwndStatic)
                    MessageBox(hwndTab,"Tabs loaded with an error!","Error",MB_OK);
    
                //Get the size of the static window
                GetClientRect(hwndStatic, &rect);
                //Place the bitmap inside the static window
                SendMessage(hwndPreAlg,STM_SETIMAGE,IMAGE_BITMAP,(LPARAM)LoadImage(GetModuleHandle(NULL),
                    MAKEINTRESOURCE(IDD_BITMAP),IMAGE_BITMAP,rect.right-rect.left,rect.bottom-rect.top,LR_SHARED));
    
                //Set initial top level tab, and show it's contents
                TabCtrl_SetCurSel(hwndTab,0);
                ShowWindow(hwndStatic,SW_SHOW);
    
            }
            break;
    Last edited by scwizzo; 07-17-2008 at 10:19 AM.

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    New question: why is it that when I created the manifest file none of my bitmaps showed up? If I remove the manifest file the bitmaps come back. Is there a way around this?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 02:22 PM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  3. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  4. internet
    By yeah in forum C Programming
    Replies: 16
    Last Post: 02-12-2005, 09:37 PM
  5. dont want to use all params
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 02-18-2003, 07:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21