XP style Explorer Bar

Introduction

This article presents a full implementation of the Windows XP Explorer Bar as a set of Win32 controls and a MFC wrapper. The Explorer Bar works on Windows 98/Me/2k/XP and is fully shellstyle.dll aware, i.e. can be used with any XP visual theme (standard, 3rd party non-standard, and the classic Windows scheme).

The new custom controls include extended button controls, extended static controls, tasklink controls, and collapsible header controls.

Background

The Windows Explorer that comes with Windows XP introduces a fancy new control bar called "Explorer Bar". The bar handles one or more collapsible panes containing tasklinks or informative text and having a collapsible header control.

The Explorer Bar is neither exported by any API nor uses it the standard XP theme renderer. All bitmaps and metrics reside in specialized DLLs named "shellstyle.dll".

The implementation presented here has a full parser for this non-standard information and a highly sophisticated rendering engine allowing fade and roll effects to be applied to expanding/collapsing panes.

Using the code

The zip archive contains a Platform SDK like HTMLHelp file (explorerbar.chm) with the full documentation (Win32/MFC). You must build all configurations of explorerbar.dsw before using the library. If you are interested in the sample application, then build ExpBarSample.dsw as well.

After building all configurations of explorerbar.dsw you find the library in "explorerbar/lib" and the MFC wrapper in "explorerbar/lib/MFC".

General comments, points of interest

Approx. 18.000 lines of code needed to be written in order to support all functionalities of the Windows XP Explorer Bar, i.e. expect bug-fixes!

Even if the Explorer Bar will be exported in the future by an API, it will not work under Windows 98/Me/2k because it will probably use a new XP theme renderer tightly linked to Windows XP.

One big TODO item is a pure MFC version of the Explorer Bar. This would simplify the message handling stated in the Explorer Bar SDK (HTMLHelp). The current implementation (explorerbar.dll) has been written for Win32 applications for maximum platform support.

History

Version 1.0 is the first published version of the Explorer Bar. It is embedded in the great sizeable control bar by Cristi Posea.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

ExplorerBar 是一个 Windows API 控件,它可以在 Windows 窗口中创建一个具有树形结构的导航栏,类似于 Windows 资源管理器中的导航栏。要使用 ExplorerBar 控件,您需要完成以下步骤: 1. 在您的 Windows 应用程序中包含 commctrl.h 头文件。 2. 调用 InitCommonControls() 函数以初始化公共控件。 3. 创建一个父窗口,并在其中创建一个子窗口,该子窗口将承载 ExplorerBar 控件。 4. 调用 CreateWindowEx() 函数来创建 ExplorerBar 控件。 5. 使用 ExplorerBar_AddItem() 函数添加项目到控件中。 6. 为每个项目设置属性,例如图标、文本和状态。 7. 使用 ExplorerBar_Expand() 函数展开或折叠项目。 8. 处理 WM_NOTIFY 消息以响应用户与控件的交互。 下面是一个简单的示例代码,演示如何使用 ExplorerBar 控件: ```c++ #include <windows.h> #include <commctrl.h> #pragma comment(lib, "comctl32.lib") LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: { // 初始化公共控件 InitCommonControls(); // 创建 ExplorerBar 控件 HWND hExplorerBar = CreateWindowEx(0, WC_EXPLORER, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 200, 300, hWnd, NULL, GetModuleHandle(NULL), NULL); // 添加项目 EXPLORERITEM ei = { 0 }; ei.mask = EIM_TEXT | EIM_CHILDREN; ei.pszText = TEXT("Item 1"); ei.cChildren = 2; SendMessage(hExplorerBar, EM_INSERTITEM, 0, (LPARAM)&ei); ei.pszText = TEXT("Item 2"); ei.cChildren = 0; SendMessage(hExplorerBar, EM_INSERTITEM, 0, (LPARAM)&ei); ei.pszText = TEXT("Item 3"); ei.cChildren = 0; SendMessage(hExplorerBar, EM_INSERTITEM, 0, (LPARAM)&ei); // 展开第一个项目 ExplorerBar_Expand(hExplorerBar, 0, TRUE); } return 0; case WM_NOTIFY: { LPNMHDR lpnm = (LPNMHDR)lParam; switch (lpnm->code) { case NM_CLICK: { LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lParam; if (lpnmlv->hdr.hwndFrom == GetDlgItem(hWnd, IDC_EXPLORERBAR)) { // 处理 ExplorerBar 点击事件 } } break; } } return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, message, wParam, lParam); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // 注册窗口类 WNDCLASSEX wcex = { 0 }; wcex.cbSize = sizeof(WNDCLASSEX); wcex.lpfnWndProc = WndProc; wcex.hInstance = hInstance; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.lpszClassName = TEXT("ExplorerBarDemo"); RegisterClassEx(&wcex); // 创建窗口 HWND hWnd = CreateWindow(TEXT("ExplorerBarDemo"), TEXT("ExplorerBar Demo"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 400, NULL, NULL, hInstance, NULL); // 显示窗口 ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); // 消息循环 MSG msg = { 0 }; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } ``` 请注意,上述示例代码仅是一个演示,并不包含所有可能用到的功能。如果您需要更详细的信息,请查看 Microsoft MSDN 文档。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值