Introduction
Recently in one of my programs, I would have needed to use a CBCGPOutlookBar control (in Mode2003) from the BCGControlBar library. It is created as a ControlBar object and it is possible to bind it at the left or right side of a frame. I was not able to put it to the -- necessary for me -- float state. Also, it is not possible to create it as a child for any window, e.g. to put it on the dialog. The control that I created is derived from CWnd and is a common control based on MFC. It does not have restrictions and it is possible to put it on any window (main frame, dialog, float bar (ControlBar), etc).
Using the Code
The control includes three hierarchical classes:
|
Class
|
File
|
Description
|
|
OutlookTabCtrlBase
|
OutlookTabCtrl.h
|
Base class. Includes all the base functionality, but it does not draw or display the menu and setting dialog.
|
|
OutlookTabCtrl
|
OutlookTabCtrl.h
|
Derived from OutlookTabCtrlBase. Overrides and implements the virtual methods that are necessary to draw the control and save its state to the registry.
|
|
OutlookTabCtrlEx
|
OutlookTabCtrlEx.h
|
Derived from OutlookTabCtrl. Overrides and implements a single virtual method, ShowMenu. It shows the menu and, if it is possible, shows the dialog based on the OutlookTabCtrlCmdDialog class.
|
To create the control and add elements to it, you can do the next steps:
OutlookTabCtrlEx m_OutlookTabCtrlEx;
CListCtrl m_List1, m_List2;
...
...
if(m_OutlookTabCtrlEx.Create(this,
WS_CHILD | WS_VISIBLE | WS_BORDER,CRect(3,3,200,350),
ID_OutlookTabCtrl)==false)
return -1;
CImageList imagelistBig, imagelistSmall;
CBitmap bmpBig, bmpSmall;
imagelistBig.Create(24,24,ILC_COLOR24 | ILC_MASK,2,0);
bmpBig.LoadBitmap(IDB_BITMAP1);
imagelistBig.Add(&bmpBig,RGB(255,0,255));
imagelistSmall.Create(16,16,ILC_COLOR24 | ILC_MASK,2,0);
bmpSmall.LoadBitmap(IDB_BITMAP2);
imagelistSmall.Add(&bmpSmall,RGB(255,0,255));
m_OutlookTabCtrlEx.SetImageLists(&imagelistBig,&imagelistSmall,NULL,NULL);
if(m_List1.Create(WS_CHILD | WS_CLIPCHILDREN | LVS_REPORT,CRect(0,0,0,0),
&m_OutlookTabCtrlEx,ID_List1)==0 ||
m_List2.Create(WS_CHILD | WS_CLIPCHILDREN | LVS_REPORT,CRect(0,0,0,0),
&m_OutlookTabCtrlEx,ID_List2)==0)
return -1; m_List1.InsertColumn(0,"Mail",LVCFMT_LEFT,100);
m_List2.InsertColumn(0,"Calendar",LVCFMT_LEFT,100);
if(m_OutlookTabCtrlEx.AddTab(&m_List1,"Mail",0,0)==NULL ||
m_OutlookTabCtrlEx.AddTab(&m_List2,"Calendar",1,1)==NULL)
return -1;
if(m_OutlookTabCtrlEx.LoadState(AfxGetApp(),
"OutlookTabCtrl","TabsState")==false)
m_OutlookTabCtrlEx.PushTab();
m_OutlookTabCtrlEx.Update();
Windows for all new added elements should have the unique identifiers. Elements can be in the state of a tab or button. By default, an element is added as a tab. Using the Insert function, it is possible to add the element to the random position. Remove changes the position. The control is expected to call the Update function to show the results that are set by functions Delete, SetItemWnd, ShowItem, etc. The control can hide the element (ShowItem) or block it (Disable) and get an index between visible elements (GetVisibleIdxByHandle) or all elements in the control (GetIdxByHandle).
Also, it is possible to check the existence of the element (IsExist) or position it below the mouse cursor (HitTest). The control is able to save and load its state from the registry or other source (LoadState/SaveState). This is just a part of the possibilities. To get the full power, look at the opened and closed interfaces of the OutlookTabCtrlBase and OutlookTabCtrl classes, as well as the OutlookTabCtrlExCustom class for creating the user interface of the control.
Good luck.
History
- 4 October, 2007 -- Original version posted
- 11 October, 2007 -- Fixed problem with addition Dialog as child control; added functions
SetLayout and SetButtonsAlign for determination places of the control's areas
- 17 December, 2008 -- Just corrected some small errors