A tab control with a Close (x) button for each Tab ?
-
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
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[^]
-
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
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
-
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
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 :)
-
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 :)
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
-
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
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 ?
-
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 ?
-
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
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 ).
-
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 ).
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