分享
 
 
 

一个效果很好的outlookbar控件CXTOutBarCtrl

王朝vc·作者佚名  2006-01-17
窄屏简体版  字體: |||超大  

一个效果很好的outlookbar控件CXTOutBarCtrl

作者:许昌元

下载本文示例源代码

该控件来源于Xtreme Toolkit,我对其进行了修改,使其不依赖于类库独立存在,由于我没有运用XT的其他类,可能你会觉得它没有在类库中的华丽,但相对于其小巧的体格而言,已经很难得了。

源文件包括两个头文件,两个执行文件:XTMemDC.h,XTMemDC.cpp,XTOutBarCtrl.h,XTOutBarCtrl.cpp.

其中XTMemDC是一个CDC继承类,用于辅助功能。

该控件的使用方法:

1、用mfc

sdi wizard生成一个子SDI程序。

2、在MainFrm.h头部加入#include

"XTOutBarCtrl.h"

3、在MainFrm.h是加入成员变量

CSplitterWndm_wndSplitter;

CXTOutBarCtrlm_wndOutlookBar;

CImageListm_ImageLarge;

CImageListm_ImageSmall;

boolm_bDestroy;

4、CMainFrame增加消息映射函数

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)

{

// create splitter window

if (!m_wndSplitter.CreateStatic(this, 1, 2))

return FALSE;

// Here we create the outbar control using the splitter as its parent

// and setting its id to the first pane.

if (!m_wndOutlookBar.Create(WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN, CRect(0,0,0,0),

&m_wndSplitter, m_wndSplitter.IdFromRowCol(0, 0), OBS_XT_DEFAULT))

{

TRACE0("Failed to create outlook bar.");

return FALSE;

}

if (!m_wndSplitter.CreateView(0, 1, pContext-m_pNewViewClass,

CSize(100, 100), pContext))

{

m_wndSplitter.DestroyWindow();

return FALSE;

}

// Set the background and text color of the outlook bar.

m_wndOutlookBar.SetBackColor(RGB(0x3a,0x6e,0xa5));

m_wndOutlookBar.SetTextColor(RGB(0xff,0xff,0xff));

// Set the default sizes for the splitter panes.

CRect r;

GetClientRect(&r);

m_wndSplitter.SetColumnInfo( 0, r.Width()/4, 0 );

m_wndSplitter.RecalcLayout();

// Add items to the outlook bar.

InitializeOutlookBar();

return TRUE;

}

5、CMainFrame增加成员函数

void CMainFrame::InitializeOutlookBar()

{

// Create the image lists used by the outlook bar.

m_ImageSmall.Create (16, 16, ILC_COLOR16|ILC_MASK, 2, 1);

m_ImageLarge.Create (32, 32, ILC_COLOR16|ILC_MASK, 2, 1);

// initiailize the image lists.

for (int i = 0; i LoadIcon(nIcons[i]);

ASSERT(hIcon);

m_ImageSmall.Add(hIcon);

m_ImageLarge.Add(hIcon);

}

int iFolder; // index of the added folder

// set the image lists for the outlook bar.

m_wndOutlookBar.SetImageList(&m_ImageLarge, OBS_XT_LARGEICON);

m_wndOutlookBar.SetImageList(&m_ImageSmall, OBS_XT_SMALLICON);

// Add the first folder to the outlook bar.

iFolder = m_wndOutlookBar.AddFolder(_T("Shortcuts 1"), 0);

// Add items to the folder, syntax is folder, index, text, image, and item data.

m_wndOutlookBar.InsertItem(iFolder, 1, _T("Item 1"), 0, NULL);

m_wndOutlookBar.InsertItem(iFolder, 2, _T("Item 2"), 1, NULL);

m_wndOutlookBar.InsertItem(iFolder, 3, _T("Item 3"), 2, NULL);

m_wndOutlookBar.InsertItem(iFolder, 4, _T("Item 4"), 3, NULL);

m_wndOutlookBar.InsertItem(iFolder, 5, _T("Item 5"), 4, NULL);

m_wndOutlookBar.InsertItem(iFolder, 6, _T("Item 6"), 5, NULL);

// Add the second folder to the outlook bar.

iFolder = m_wndOutlookBar.AddFolder(_T("Shortcuts 2"), 1);

// Add items to the folder, syntax is folder, index, text, image, and item data.

m_wndOutlookBar.InsertItem(iFolder, 1, _T("Item 1"), 0, NULL);

m_wndOutlookBar.InsertItem(iFolder, 2, _T("Item 2"), 1, NULL);

// Add the tree control to the outlook bar.

//xuiFolder = m_wndOutlookBar.AddFolderBar(_T("Tree Control"), &m_wndTreeCtrl );

// Set the default font used by the outlook bar.

//xum_wndOutlookBar.SetFontX(&xtAfxData.font);

// We want to receive notification messages.

m_wndOutlookBar.SetOwner(this);

// Select the first folder in the bar.

m_wndOutlookBar.SetSelFolder(iFolder);

// Sizing for splitter

CRect r;

GetClientRect(&r);

m_wndSplitter.SetColumnInfo( 0, r.Width()/7, 0 );

m_wndSplitter.SetColumnInfo( 1, r.Width()/5, 0 );

//m_wndSplitter1.SetSplitterStyle(XT_SPLIT_NOFULLDRAG);

}

6、CMainFrame增加消息映射

LRESULT CMainFrame::OnOutbarNotify(WPARAM wParam, LPARAM lParam)

{

int nBarAction = (int)wParam;

// Cast the lParam to a XT_OUTBAR_INFO* struct pointer.

XT_OUTBAR_INFO* pOBInfo = (XT_OUTBAR_INFO*)lParam;

ASSERT(pOBInfo);

switch (nBarAction)

{

case OBN_XT_ITEMCLICK:

TRACE2( "Item selected: %d, Name: %s.\n", pOBInfo-nIndex, pOBInfo-lpszText);

break;

case OBN_XT_FOLDERCHANGE:

TRACE2( "Folder selected: %d, Name: %s.\n", pOBInfo-nIndex, pOBInfo-lpszText);

break;

case OBN_XT_ONLABELENDEDIT:

TRACE2( "Item edited: %d, New name: %s.\n", pOBInfo-nIndex, pOBInfo-lpszText);

break;

case OBN_XT_ONGROUPENDEDIT:

TRACE2( "Folder edited: %d, New name: %s.\n", pOBInfo-nIndex, pOBInfo-lpszText);

break;

case OBN_XT_DRAGITEM:

TRACE3( "Dragging From: %d, To: %d, Name: %s.\n", pOBInfo-nDragFrom,

pOBInfo-nDragTo, pOBInfo-lpszText);

break;

case OBN_XT_ITEMHOVER:

TRACE2( "Hovering Item: %d, Name: %s.\n", pOBInfo-nIndex, pOBInfo-lpszText);

break;

case OBN_XT_DELETEITEM:

if (!m_bDestroy && AfxMessageBox(_T("Are you sure you want to remove this folder shortcut?"),

MB_ICONWARNING|MB_YESNO) == IDNO)

{

// The user selected No, return FALSE to abort the action.

return FALSE;

}

TRACE2( "Item deleted: %d, Name: %s.\n", pOBInfo-nIndex, pOBInfo-lpszText);

break;

case OBN_XT_DELETEFOLDER:

if (!m_bDestroy && AfxMessageBox(_T("Are you sure you want to remove the specified folder?"),

MB_ICONWARNING|MB_YESNO) == IDNO)

{

// The user selected No, return FALSE to abort the action.

return FALSE;

}

TRACE2( "Folder deleted: %d, Name: %s.\n", pOBInfo-nIndex, pOBInfo-lpszText);

break;

}

return TRUE;

}

还有其他一些内容请参见源程序,愿这个控件能对您的编程有所帮助,谢谢。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有