码迷,mamicode.com
首页 > 其他好文 > 详细

Bcgcontrolbar 输出栏(Outputbar)文本显示

时间:2015-03-15 16:37:06      阅读:437      评论:0      收藏:0      [点我收藏+]

标签:

效果如下 

技术分享

添加 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);

 

Bcgcontrolbar 输出栏(Outputbar)文本显示

标签:

原文地址:http://www.cnblogs.com/xd-jinjian/p/4339893.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!