[Help]如何才能实现一个如Windows附件中的"画图"程序的工具箱?

whitep 2004-08-26 12:11:48
"画图"的工具箱是两个按钮一行向左停靠于FrameWnd内的,应当怎样做,才可以实现这一效果呢?另外,这个工具箱下面还有一个跟正常的按钮大小不一样的控件,这又是如何实现的呢?
谢谢!
...全文
128 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
scmsir 2004-08-26
  • 打赏
  • 举报
回复
呵呵,有现成的了。
scmsir 2004-08-26
  • 打赏
  • 举报
回复
#if !defined(__SCBARG_H__)
#define __SCBARG_H__

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

/////////////////////////////////////////////////////////////////////////
// CSCBButton (button info) helper class

class CSCBButton
{
public:
CSCBButton();

void Move(CPoint ptTo) {ptOrg = ptTo; };
CRect GetRect() { return CRect(ptOrg, CSize(13, 13)); };
void Paint(CDC* pDC);

BOOL bPushed;
BOOL bRaised;

protected:
CPoint ptOrg;
};

/////////////////////////////////////////////////////////////////////////
// CSizingControlBar control bar

#ifndef baseCCoolBar
#define baseCCoolBar CSizingControlBar
#endif

class CCoolBar : public baseCCoolBar
{
DECLARE_DYNAMIC(CCoolBar);

// Construction
public:
CCoolBar();

// Attributes
public:
virtual BOOL HasGripper() const;

// Operations
public:

// Overridables
virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
virtual BOOL Create(LPCTSTR lpszWindowName, CWnd* pParentWnd,
CSize sizeDefault, BOOL bHasGripper,
UINT nID, DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_TOP);
virtual BOOL Create(LPCTSTR lpszWindowName, CWnd* pParentWnd,
UINT nID, DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_TOP);

// Overrides
public:
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCoolBar)
//}}AFX_VIRTUAL

// Implementation
public:
void SetNotifyWindow(HWND hNotifyWnd);
HWND GetNotifyWindow() { return m_hNotifyWnd; };
virtual ~CCoolBar();

protected:
// implementation helpers
virtual void NcPaintGripper(CDC* pDC, CRect rcClient);
virtual void NcCalcClient(LPRECT pRc, UINT nDockBarID);

protected:
int m_cyGripper;
CSCBButton m_biHide;
BOOL m_bActive; // a child has focus
CString m_sFontFace;
HWND m_hNotifyWnd; // 消息通知窗口,默认为父窗口

// Generated message map functions
protected:
//{{AFX_MSG(CCoolBar)
afx_msg UINT OnNcHitTest(CPoint point);
afx_msg void OnNcLButtonUp(UINT nHitTest, CPoint point);
afx_msg LRESULT OnSetText(WPARAM wParam, LPARAM lParam);
afx_msg BOOL OnNotify( WPARAM wParam, LPARAM lParam, LRESULT* pResult );
//}}AFX_MSG

DECLARE_MESSAGE_MAP()
};

#endif // !defined(__SCBARG_H__)

zhaogaojian 2004-08-26
  • 打赏
  • 举报
回复
哈哈,这个给你一个类效果很好// palettebar.h : interface of the CPaletteBar class
//
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.

class CPaletteBar : public CToolBar
{
// Constructor
public:
CPaletteBar();
void SetColumns(UINT nColumns);
UINT GetColumns() { return m_nColumns; };

// Attributes
public:

// Operations
public:

// Implementation
public:
virtual ~CPaletteBar();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:
UINT m_nColumns;

// Generated message map functions
protected:
//{{AFX_MSG(CPaletteBar)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

// palettebar.cpp : implementation of the Floating tool palettebar class
//
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.

#include "stdafx.h"
#include "palettebar.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPaletteBar

BEGIN_MESSAGE_MAP(CPaletteBar, CToolBar)
//{{AFX_MSG_MAP(CPaletteBar)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPaletteBar construction/destruction

CPaletteBar::CPaletteBar()
{
m_nColumns = 2;
m_cxLeftBorder = 5;
m_cyTopBorder = 5;
m_cxRightBorder = 5;
m_cyBottomBorder = 5;
}

CPaletteBar::~CPaletteBar()
{
}

/////////////////////////////////////////////////////////////////////////////
// CPaletteBar diagnostics

#ifdef _DEBUG
void CPaletteBar::AssertValid() const
{
CToolBar::AssertValid();
}

void CPaletteBar::Dump(CDumpContext& dc) const
{
CToolBar::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CPaletteBar message handlers

void CPaletteBar::SetColumns(UINT nColumns)
{
m_nColumns = nColumns;
int nCount = GetToolBarCtrl().GetButtonCount();

for (int i = 0; i < nCount; i++)
{
UINT nStyle = GetButtonStyle(i);
BOOL bWrap = (((i + 1) % nColumns) == 0);
if (bWrap)
nStyle |= TBBS_WRAPPED;
else
nStyle &= ~TBBS_WRAPPED;
SetButtonStyle(i, nStyle);
}

Invalidate();
//this->SetHeight(200);

GetParentFrame()->RecalcLayout();
}

以下是实现部分
////////////////////////////////////////////////////////////////
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;

if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}

if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}

// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
if (!CreatePaletteBar())
return -1;
return 0;
}
BOOL CMainFrame::CreatePaletteBar()
{if (!m_wndPaletteBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_SIZE_FIXED |
CBRS_TOP | CBRS_TOOLTIPS, ID_PALETTEBAR) ||
!m_wndPaletteBar.LoadBitmap(IDB_PALETTE) ||
!m_wndPaletteBar.SetButtons(palette,
sizeof(palette)/sizeof(UINT)))
{
TRACE0("Failed to create toolbar\n");
return FALSE; // fail to create
}

m_wndPaletteBar.SetWindowText(_T("Palette"));
m_wndPaletteBar.EnableDocking(0);

// Create the Palette. We are using hardcoded numbers for ease here
// normally the location would be read in from an ini file.
CPoint pt(GetSystemMetrics(SM_CXSCREEN) - 100,
GetSystemMetrics(SM_CYSCREEN) / 3);
m_wndPaletteBar.SetColumns(2);
FloatControlBar(&m_wndPaletteBar, pt);
return TRUE;

}
///////////////////////////////////////////////////////////////
wgc 2004-08-26
  • 打赏
  • 举报
回复
你用CDialogBar ,然后在CMainFrame的oncreate象工具条那样浮动着就可以了
pomelowu 2004-08-26
  • 打赏
  • 举报
回复
用CToolBar都可以实现的

15,976

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧