效果如下
添加 outputbar.h
outputbar.cpp
outputbar.h改为
//******************************************************************************* // COPYRIGHT NOTES // --------------- // This is a sample for BCGControlBar Library Professional Edition // Copyright (C) 1998-2014 BCGSoft Ltd. // All rights reserved. // // This source code can be used, distributed or modified // only under terms and conditions // of the accompanying license agreement. //******************************************************************************* // #if !defined(AFX_OUTPUTBAR_H__708257AC_7B83_11D3_A74B_0090274409AC__INCLUDED_) #define AFX_OUTPUTBAR_H__708257AC_7B83_11D3_A74B_0090274409AC__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 // OutputBar.h : header file // ///////////////////////////////////////////////////////////////////////////// class COutputBar : public CBCGPDockingControlBar { // Construction public: COutputBar(); // Attributes protected: CString m_strText; int m_nScrollOffset; int m_nTotalTextHeight; protected: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(COutputBar) //}}AFX_VIRTUAL virtual BOOL ScrollVertAvailable(BOOL bTop); virtual void OnScrollClient(UINT uiScrollCode); // Implementation public: virtual ~COutputBar(); void UpdateInfo (int nType); void UpdateTextHeight(); // Generated message map functions protected: //{{AFX_MSG(COutputBar) afx_msg void OnPaint(); afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg BOOL OnEraseBkgnd(CDC* pDC); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_OUTPUTBAR_H__708257AC_7B83_11D3_A74B_0090274409AC__INCLUDED_)
outputbar.cpp改为
//******************************************************************************* // COPYRIGHT NOTES // --------------- // This is a sample for BCGControlBar Library Professional Edition // Copyright (C) 1998-2014 BCGSoft Ltd. // All rights reserved. // // This source code can be used, distributed or modified // only under terms and conditions // of the accompanying license agreement. //******************************************************************************* // // OutputBar.cpp : implementation file // #include "stdafx.h" #include "BCGControl3.0.h" #include "MainFrm.h" #include "OutputBar.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define HORZ_MARGIN 10 ///////////////////////////////////////////////////////////////////////////// // COutputBar COutputBar::COutputBar() { m_nScrollOffset = 0; m_nTotalTextHeight = 0; } COutputBar::~COutputBar() { } BEGIN_MESSAGE_MAP(COutputBar, CBCGPDockingControlBar) //{{AFX_MSG_MAP(COutputBar) ON_WM_PAINT() ON_WM_SIZE() ON_WM_ERASEBKGND() //}}AFX_MSG_MAP END_MESSAGE_MAP() void COutputBar::OnPaint() { CPaintDC dc(this); // device context for painting CBCGPMemDC memDC (dc, this); CDC* pDC = &memDC.GetDC (); CRect rect; GetClientRect (rect); pDC->FillRect(rect, &globalData.brBarFace); CFont* pOldFont = pDC->SelectObject (&globalData.fontRegular); pDC->SetTextColor (globalData.clrBarText); pDC->SetBkMode (TRANSPARENT); rect.DeflateRect (HORZ_MARGIN, 0); rect.top -= m_nScrollOffset; pDC->DrawText (m_strText, rect, DT_WORDBREAK); //pDC->DrawText (_T("1"), rect, DT_WORDBREAK); pDC->SelectObject (pOldFont); } void COutputBar::UpdateInfo (int nType) { if (GetSafeHwnd () == NULL) { return; } m_strText.Empty (); switch (nType) { case 1: m_strText = _T("\n这里将显示全部信息回显"); break; } UpdateTextHeight(); m_nScrollOffset = 0; SetWindowPos (NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_FRAMECHANGED); RedrawWindow (NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_UPDATENOW); } void COutputBar::OnSize(UINT nType, int cx, int cy) { UpdateTextHeight(); if (m_nTotalTextHeight < cy) { m_nScrollOffset = 0; } CBCGPDockingControlBar::OnSize(nType, cx, cy); RedrawWindow (); } void COutputBar::UpdateTextHeight() { CClientDC dc(this); CRect rect; GetClientRect (rect); CFont* pOldFont = dc.SelectObject (&globalData.fontRegular); rect.DeflateRect (HORZ_MARGIN, 0); dc.DrawText (m_strText, rect, DT_WORDBREAK | DT_CALCRECT); dc.SelectObject (pOldFont); m_nTotalTextHeight = rect.Height(); } BOOL COutputBar::OnEraseBkgnd(CDC* /*pDC*/) { return TRUE; } BOOL COutputBar::ScrollVertAvailable(BOOL bTop) { if (bTop) { return m_nScrollOffset > 0; } CRect rect; GetClientRect (rect); return m_nTotalTextHeight - m_nScrollOffset > rect.bottom; } void COutputBar::OnScrollClient(UINT uiScrollCode) { switch (HIBYTE(uiScrollCode)) { case SB_LINEUP: m_nScrollOffset -= globalData.GetTextHeight(); break; case SB_LINEDOWN: m_nScrollOffset += globalData.GetTextHeight(); break; } RedrawWindow(); }
Mainfrm.h中加入 #include "OutputBar.h"
并添加对象COutputBar m_wndInformationBar;
Mainfrm.cpp中 的Oncreate中加入
if (!m_wndInformationBar.Create (_T("信息反馈"), this, CRect (0, 0, 100, 100), TRUE, 10086, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_BOTTOM | CBRS_FLOAT_MULTI, #ifdef _BCGSUITE_INC_ AFX_CBRS_REGULAR_TABS, AFX_CBRS_RESIZE | AFX_CBRS_AUTOHIDE) #else CBRS_BCGP_REGULAR_TABS, CBRS_BCGP_RESIZE | CBRS_BCGP_AUTOHIDE) #endif ) { TRACE0("Failed to create information bar\n"); return FALSE; // fail to create } m_wndInformationBar.UpdateInfo (1); //SetupThemeCombo(1); m_wndInformationBar.EnableDocking(CBRS_ALIGN_ANY);
时间: 2024-10-16 07:23:05