MPCStatusBar - 增强型 CStatusBar






4.44/5 (3投票s)
2000年2月17日

168488

4193
一个增强的 CStatusBar,可以轻松且动态地在状态栏上添加/删除控件
概述
MPCStatusBar
类允许您轻松地添加/删除标准指示器,和/或在状态栏上添加/删除控件。 MPCStatusBarPane
和 MPCStatusBarPaneControlInfo
类与 MPCStatusBar
一起提供。
此外,还有一个“即用型”类 MPCLogoPane
类,您可以使用它在状态栏的左侧添加您的公司或软件的徽标。 当然,源代码附带一个简单的 MDI 应用程序,您可以在其中看到 MPCStatusBar
类与 MPCLogoPane
和状态栏上的标准 CEdit
结合使用。
示例
动态添加/删除控件的示例源代码
在您的 *mainframe.h*(或子框架)中声明一个 MPCStatusBar
来替换 CStatusBar
MPCStatusBar m_wndStatusBar;
添加/删除控件的示例函数
void Function_addcontrol( BOOL bAddalogo )
{
// Get the mainframe
CMainFrame * pMainframe = (CMainFrame *) AfxGetApp()->m_pMainWnd;
if ( bAddalogo )
{
// Add an indicator, with width, ..
pMainframe->m_wndStatusBar.AddIndicator(0,INDICATOR_LOGO);
// set the width and style
int idx = pMainframe->m_wndStatusBar.CommandToIndex(INDICATOR_LOGO);
pMainframe->m_wndStatusBar.SetPaneWidth(idx,120);
pMainframe->m_wndStatusBar.SetPaneStyle(idx,
pMainframe->m_wndStatusBar.GetPaneStyle(idx)
| SBPS_NOBORDERS );
// Create a log pane window, and append it to status bar
MPCLogoPane * pLogo = new MPCLogoPane;
pLogo->Create("Your App Name ",WS_CHILD|WS_VISIBLE,
&pMainframe->m_wndStatusBar,120);
pLogo->SetLogoFont("Arial", 18);
pMainframe->m_wndStatusBar.AddControl(pLogo,INDICATOR_LOGO);
}
else
{
pMainframe->m_wndStatusBar.RemovePane(INDICATOR_LOGO);
}
}
类
MPCStatusBar
MPCStatusBarPane
MPCStatusBarPaneControlInfo
此外,您可以使用“即用型”MPCLogoPane
类将徽标添加到您的应用程序的状态栏中。
MPCStatusBar
这是您用来替换 CStatusBar
的类。
void PositionControls()
用于将状态栏中的控件移动到正确的位置(==指示器的
RECT
)。 内部使用。MPCStatusBarPaneControlInfo * GetPanControl(int nPaneID)
返回有关指示器上的控件的一些信息,如果不存在则返回
NULL
。BOOL AddControl(CWnd * pWnd, int nPaneID, BOOL bAutodeleteControl = TRUE )
在窗格 (
nPaneID
) 上插入一个控件 (pWnd
)。 如果bAutodelete
为TRUE
,则在删除窗格 (nPaneID
) 或调用MPCStatusBar
析构函数时,将关闭控件的窗口并删除该控件。 如果控件已附加,则返回TRUE
。 在将控件附加到窗格上之前,您需要创建一个窗格(请参阅AddIndicator
),或者使用尚未用于控件的现有窗格。void SetPaneWidth(int index, int cxWidth)
更改窗格的宽度(无论有没有控件)
BOOL AddIndicator( int position, UINT paneID)
向状态栏添加一个指示器。
BOOL GetStatusPane(int nIndex, MPCStatusBarPane & xfxpane)
xfxpane
填充了有关nIndex
处的窗格的一些信息。void RemovePane(int nPaneID)
删除一个窗格。 如果窗格有一个控件,并且该控件是使用
autodelete=true
添加的(请参阅AddControl
),则会将其删除。
MPCStatusBarPane
此类允许您获取有关 MPCStatusBar
中窗格的信息。 请参阅 MPCStatusBar
。
UINT nID;
窗格的 ID
int cxText;
文本大小
UINT nStyle;
指示器的样式
UINT nFlags;
MFC 使用的内部标志
CString strText;
窗格的文本
MPCStatusBarPane::MPCStatusBarPane(MPCStatusBarPane & xfxpane )
复制构造函数
MPCStatusBarPane& MPCStatusBarPane::operator=(MPCStatusBarPane & xfxpane )
赋值运算符
MPCStatusBarPaneControlInfo
此类允许您获取有关 MPCStatusBar
中窗格的附加信息,该窗格具有一个控件。
CWnd * m_hWnd;
控件
int m_nPaneID;
此控件所在的窗格
BOOL m_bAutodelete;
指示在删除窗格时,或在调用
MPCStatusBar
的析构函数时是否自动删除。
MPCLogoPane
BOOL MPCLogoPane::Create(CString sText, DWORD dwStyle, CWnd * pParent, UINT nID)
sText
-- 您要在窗口中显示的文本dwStyle
-- 窗口的样式 (WS_CHILD | WS_VISIBLE
在状态栏中使用)nID
-- 窗口的 ID
void MPCLogoPane::SetLogoFont(CString Name, int nHeight/* = 24*/, int nWeight/* = FW_BOLD*/, BYTE bItalic/* = true*/, BYTE bUnderline/* = false*/)
设置用于显示文本的字体。
void MPCLogoPane::SetLogoText(CString sTxt)
设置要显示的文本
许可证
本文未附加明确的许可证,但可能在文章文本或下载文件本身中包含使用条款。如有疑问,请通过下面的讨论区联系作者。
作者可能使用的许可证列表可以在此处找到。