我想在状态栏上预览画笔和画刷的状态,可以在状态栏上画图吗?

解决方案 »

  1.   

    //MyStatusBar.h
    // MyStatusBar.h: interface for the CMyStatusBar class.
    //
    //////////////////////////////////////////////////////////////////////#if !defined(AFX_MYSTATUSBAR_H__E77E4765_F456_4A0F_A6AB_82B3652561B5__INCLUDED_)
    #define AFX_MYSTATUSBAR_H__E77E4765_F456_4A0F_A6AB_82B3652561B5__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000class CMyStatusBar : public CStatusBar  
    {
    public: CMyStatusBar();
    virtual ~CMyStatusBar();protected:
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnPaint();
    DECLARE_MESSAGE_MAP()
    };#endif // !defined(AFX_MYSTATUSBAR_H__E77E4765_F456_4A0F_A6AB_82B3652561B5__INCLUDED_)
    //MyStatusBar.cpp
    // MyStatusBar.cpp: implementation of the CMyStatusBar class.
    //
    //////////////////////////////////////////////////////////////////////#include "stdafx.h"
    #include "Statusbar.h"
    #include "MyStatusBar.h"#ifdef _DEBUG
    #undef THIS_FILE
    static char THIS_FILE[]=__FILE__;
    #define new DEBUG_NEW
    #endifstatic UINT id[] = 
    {
    ID_SEPARATOR,
    ID_SEPARATOR
    };//////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////BEGIN_MESSAGE_MAP(CMyStatusBar, CStatusBar)
    ON_WM_CREATE()
    ON_WM_PAINT()
    END_MESSAGE_MAP()CMyStatusBar::CMyStatusBar()
    {}CMyStatusBar::~CMyStatusBar()
    {}int CMyStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (CStatusBar::OnCreate(lpCreateStruct) == -1)
    return -1;
        
        SetIndicators(id, 2);    return 0;
    }void CMyStatusBar::OnPaint()
    {
    CStatusBar::OnPaint(); CBrush brush(RGB(0, 123, 220));
    CDC *pDC = GetDC();
    RECT rc;
    GetItemRect(1, &rc);
    pDC->FillRect(&rc, &brush);
    ReleaseDC(pDC);
    }我派生了个CStatusBar类CMyStatusBar然后在它的OnPaint()中的第二个面板中画出一个与其相同的矩形,楼主如果想画什么的话在onpaint()中加代码就可以了,这是我能想到的方法,大家还有什么好方法交流一下。
    qq:13589137 验证:CSDN     (注意不是该字串一律不加)