Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - CXTPTabClientWnd tab change icon
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTPTabClientWnd tab change icon

 Post Reply Post Reply
Author
Message
ruanjiandev View Drop Down
Newbie
Newbie


Joined: 16 June 2005
Status: Offline
Points: 6
Post Options Post Options   Thanks (0) Thanks(0)   Quote ruanjiandev Quote  Post ReplyReply Direct Link To This Post Topic: CXTPTabClientWnd tab change icon
    Posted: 16 June 2005 at 8:18pm

CXTPTabClientWnd tab dose not change the icon automatically when I change the icon of the MDIFrame by call SetIcon(...)

Any one know the workaround? thanks

Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 22 June 2005 at 3:50am

TabClient send WM_XTP_GETTABICON first to get current icon:

BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
 //{{AFX_MSG_MAP(CChildFrame)
 ON_COMMAND(ID_BACK, OnBack)
 ON_MESSAGE(WM_XTP_GETTABICON, OnGetTabIcon)
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CChildFrame::OnBack()
{
 HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
 SetIcon(hIcon, FALSE);
 GetParentFrame()->RecalcLayout();
}

LRESULT CChildFrame::OnGetTabIcon(WPARAM, LPARAM)
{
 return ::SendMessage(m_hWnd, WM_GETICON, ICON_SMALL, 0);
}

Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
danpetitt View Drop Down
Senior Member
Senior Member


Joined: 17 July 2005
Location: United Kingdom
Status: Offline
Points: 109
Post Options Post Options   Thanks (0) Thanks(0)   Quote danpetitt Quote  Post ReplyReply Direct Link To This Post Posted: 30 July 2006 at 6:26pm
I am using this method and an overridden CXTTabClientWnd::GetTabIcon to draw an 'occasional' icon on my client tabs.
 
However the tabs that dont get an icon still has the caption text moved to the right the width of an icon even when there isnt one.
 
Is there any chance that the space is only allocated if the GetTabIcon returns TRUE?
 
Or perhaps there is a nice way of doing this?
 
It would also be nice to specify the size of the icon used (i dont want 16x16) and also the location "Left/Right".
Back to Top
danpetitt View Drop Down
Senior Member
Senior Member


Joined: 17 July 2005
Location: United Kingdom
Status: Offline
Points: 109
Post Options Post Options   Thanks (0) Thanks(0)   Quote danpetitt Quote  Post ReplyReply Direct Link To This Post Posted: 31 July 2006 at 4:00am
I got this working in the end. I had to derive a class from CSingleWorkspace and override the DrawIcon function so I could pass back/modify the icon size where and if appropriate.
 
For those that would like this, here is the code:
class CMyTabClientWnd : public CXTPTabClientWnd
{
public:
 class CMyWorkspace : public CXTPTabClientWnd::CSingleWorkspace
 {
  virtual BOOL DrawIcon(CDC* pDC, CPoint pt, CXTPTabManagerItem* pItem, BOOL bDraw, CSize& szIcon) const
  {
   if (GetPaintManager()->m_bShowIcons == FALSE)
    return FALSE;
   HICON hIcon = GetItemIcon( pItem );
   if( hIcon )
   {
    // We have an icon so lets set the size ... the cx/cy could be obtained from the icon but in this case I am only using one 8x8 icon so hardcoding is okay
    szIcon.cx = 8;
    szIcon.cy = 8;
    if( bDraw )
    {
     // Only draw it if we were asked to
     DrawIconEx( pDC->GetSafeHdc(), pt.x, pt.y, hIcon, szIcon.cx, szIcon.cy, 0, NULL, DI_NORMAL );
    }
    return TRUE;
   }
   // There is no icon so modify icon size to "0" so tab width and caption position are layed out properly
   szIcon.cx = 0;
   return FALSE;
  };
 };

 virtual CWorkspace* CreateWorkspace()
 {
  return new CMyWorkspace();
 }
 virtual HICON GetItemIcon(const CXTPTabManagerItem* pItem) const
 {
  HICON hIcon = NULL;
  if( pItem )
  {
   // Obtain icon to use from frame window or return NULL if none
   HWND hWnd = pItem->GetHandle();
   hIcon = (HICON)::SendMessage(hWnd, WM_XTP_GETTABICON, 0, 0);
  }
  return hIcon ? hIcon : NULL;
 };
};
Back to Top
mailhaim View Drop Down
Newbie
Newbie


Joined: 28 September 2005
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote mailhaim Quote  Post ReplyReply Direct Link To This Post Posted: 28 November 2006 at 4:15am
Hi Oleg,
I'm not fully understand what is the purpose of:
ON_COMMAND(ID_BACK, OnBack)
in order to fetch the tab icon and where ID_BACK defined?!

I took the OnBack and put it in OnGetTabIcon, as follows:
LRESULT CChildFrame::OnGetTabIcon(WPARAM, LPARAM)
{
    HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    if( hIcon != NULL )
    {
        SetIcon(hIcon, FALSE);
        GetParentFrame()->RecalcLayout();
        return 0;
    }
    return ::SendMessage(m_hWnd, WM_GETICON, ICON_SMALL, 0);
}

The problem is this code is constantly get called.
What is the problem?
Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 28 November 2006 at 7:55am

If you don;'t need dynamically change it you can create icon in constructor:

CChildFrame::CChildFrame()
{
m_hIconTab = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}
 
and retrieve it:
 
LRESULT CChildFrame::OnGetTabIcon(WPARAM, LPARAM)
{
    return (LRESULT)m_hIconTab;
}
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
mailhaim View Drop Down
Newbie
Newbie


Joined: 28 September 2005
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote mailhaim Quote  Post ReplyReply Direct Link To This Post Posted: 29 November 2006 at 3:01am
Hi oleg,
The icon I would like to use depnds on information that persist in the document.
What is the first place that the frame and document are attached?
I tried in OnCreateClient() but GetActiveDocument() returns NULL.

Regards, Haim
Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 29 November 2006 at 6:08am
Hi,
 
think best place is OnInitialUpdate.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.063 seconds.