Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. A tab control with a Close (x) button for each Tab ?

A tab control with a Close (x) button for each Tab ?

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    erajsri
    wrote on last edited by
    #1

    Hi, I want my MFC application to hav a tab control that would sport a close button on each tab just like in the new Firefox 2.0 and IE 7.0. Could you please giv me some starters or any hints on how to achieve this ? thanx a lot ! Eraj

    N N 2 Replies Last reply
    0
    • E erajsri

      Hi, I want my MFC application to hav a tab control that would sport a close button on each tab just like in the new Firefox 2.0 and IE 7.0. Could you please giv me some starters or any hints on how to achieve this ? thanx a lot ! Eraj

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      erajsri wrote:

      a close button on each tab just like in the new Firefox 2.0 and IE 7.0.

      You will have to ownerdraw the tab control and respond to the event that is generated for the close button/icon that you drew on each tab. Tabs in a tab control also support icons so this may help you further. Take a look at this style TCS_OWNERDRAWFIXED. Search CP or Google with the keyword (TCS_OWNERDRAWFIXED) to find out samples.


      Nibu thomas A Developer Programming tips[^]  My site[^]

      1 Reply Last reply
      0
      • E erajsri

        Hi, I want my MFC application to hav a tab control that would sport a close button on each tab just like in the new Firefox 2.0 and IE 7.0. Could you please giv me some starters or any hints on how to achieve this ? thanx a lot ! Eraj

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #3

        First you need to draw the tab by your self( so that you can draw a close button in the tab item ) In the WM_LBUTTONDOWN message of the tab ctrl find the tab item below it using the HitTest() function. Check the clicked point is inside the close button you drawn. If so do the action for close.

        nave

        E 1 Reply Last reply
        0
        • N Naveen

          First you need to draw the tab by your self( so that you can draw a close button in the tab item ) In the WM_LBUTTONDOWN message of the tab ctrl find the tab item below it using the HitTest() function. Check the clicked point is inside the close button you drawn. If so do the action for close.

          nave

          E Offline
          E Offline
          erajsri
          wrote on last edited by
          #4

          thanx for the quick responses, I had a fair hunch that this wud hav to deal with OWNER DRAWING. What Im fearing now is the possibility of having my Tab Control supporting the Windows XP themes. I have seen an article on CP that shows how to draw Windows Theming on OWNER DRAWN controls. Rather than having to learn how to OWNER DRAW windows XP themes, is it possible for me to ask the Tab Control to paint itself using Windows Theming, and then allow me to paint the Close button only ? Or is it that I have to do the full tab painting since I require Windows XP theming on the Tab Control ? thanx :)

          N 1 Reply Last reply
          0
          • E erajsri

            thanx for the quick responses, I had a fair hunch that this wud hav to deal with OWNER DRAWING. What Im fearing now is the possibility of having my Tab Control supporting the Windows XP themes. I have seen an article on CP that shows how to draw Windows Theming on OWNER DRAWN controls. Rather than having to learn how to OWNER DRAW windows XP themes, is it possible for me to ask the Tab Control to paint itself using Windows Theming, and then allow me to paint the Close button only ? Or is it that I have to do the full tab painting since I require Windows XP theming on the Tab Control ? thanx :)

            N Offline
            N Offline
            Naveen
            wrote on last edited by
            #5

            erajsri wrote:

            is it possible for me to ask the Tab Control to paint itself using Windows Theming, and then allow me to paint the Close button only ?

            I think that too is possible. In the onpaint funtion, after the base class have been done the drawing, try drawing the close button. MyTab::OnPaint() { CTabCtrl::OnPaint(); CClientDC (this); // Draw Close button for each item. }

            nave

            E 1 Reply Last reply
            0
            • N Naveen

              erajsri wrote:

              is it possible for me to ask the Tab Control to paint itself using Windows Theming, and then allow me to paint the Close button only ?

              I think that too is possible. In the onpaint funtion, after the base class have been done the drawing, try drawing the close button. MyTab::OnPaint() { CTabCtrl::OnPaint(); CClientDC (this); // Draw Close button for each item. }

              nave

              E Offline
              E Offline
              erajsri
              wrote on last edited by
              #6

              Ive managed to get a close Button inside the tab control. I did this using the UxTheme library and requesting it to paint a close button on the tab. But once I set it to TCS_OWNERDRAWFIXED the problem is that the control is not drawn fully and only the button gets drawn. How can I ask Windows to paint the rest of the control for me. In Custom Draw you are able to request the control to send only "important" messages to u and let windows handle the rest itself. Why isnt this possible in Owner Drawn controls ?

              N 1 Reply Last reply
              0
              • E erajsri

                Ive managed to get a close Button inside the tab control. I did this using the UxTheme library and requesting it to paint a close button on the tab. But once I set it to TCS_OWNERDRAWFIXED the problem is that the control is not drawn fully and only the button gets drawn. How can I ask Windows to paint the rest of the control for me. In Custom Draw you are able to request the control to send only "important" messages to u and let windows handle the rest itself. Why isnt this possible in Owner Drawn controls ?

                N Offline
                N Offline
                Naveen
                wrote on last edited by
                #7

                if you r going to implement the tab control as I said in the previous post, no neeed to set TCS_OWNERDRAWFIXED style. Let the windows draw the tab control, after that paint the button over the tab items. Please check my previous post.

                nave

                E 1 Reply Last reply
                0
                • N Naveen

                  if you r going to implement the tab control as I said in the previous post, no neeed to set TCS_OWNERDRAWFIXED style. Let the windows draw the tab control, after that paint the button over the tab items. Please check my previous post.

                  nave

                  E Offline
                  E Offline
                  erajsri
                  wrote on last edited by
                  #8

                  I cud use the method uve mentioned but the problem is that the OnPaint method does not give any information as to where the painting is goin to occur and wat the control state is like. In contrast the Owner Drawing gives a lot of information. If i used the OnPaint method i would be painting close buttons everywhere on the tab control ( Ive no control over where the painting is gonna happen ).

                  M 1 Reply Last reply
                  0
                  • E erajsri

                    I cud use the method uve mentioned but the problem is that the OnPaint method does not give any information as to where the painting is goin to occur and wat the control state is like. In contrast the Owner Drawing gives a lot of information. If i used the OnPaint method i would be painting close buttons everywhere on the tab control ( Ive no control over where the painting is gonna happen ).

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #9

                    You have complete control over WHERE painting will happen. You may want/need to paint in response to WM_NCPAINT instead of WM_PAINT though. Mark

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups