• 大小: 36KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-14
  • 语言: 其他
  • 标签: VC  非客户区  

资源简介

VC轻松实现非客户区按钮示例及源码 有时我们需要在非客户区(例如:标题栏)添加按钮,并对按钮作出响应。为此我封装了两个类CNCButton和CNCButtonManager,CNCButton主要用于按钮绘制,CNCButtonManager用于按钮的管理并对非客户区的消息进行处理

资源截图

代码片段和文件信息

// MainFrm.cpp : implementation of the CMainframe class
//

#include “stdafx.h“
#include “titleButtonTest2.h“

#include “MainFrm.h“

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainframe

IMPLEMENT_DYNCREATE(CMainframe CframeWnd)

BEGIN_MESSAGE_MAP(CMainframe CframeWnd)
//{{AFX_MSG_MAP(CMainframe)
ON_BN_CLICKED(ID_BUTTON1 OnNcButton1Clicked)
ON_BN_CLICKED(ID_BUTTON2 OnNcButton2Clicked)
ON_BN_CLICKED(ID_BUTTON3 OnNcButton3Clicked)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
ID_SEPARATOR           // status line indicator
ID_INDICATOR_CAPS
ID_INDICATOR_NUM
ID_INDICATOR_SCRL
};

/////////////////////////////////////////////////////////////////////////////
// CMainframe construction/destruction

CMainframe::CMainframe()
{

}

CMainframe::~CMainframe()
{
}

int CMainframe::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CframeWnd::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);

POINT ptBtn1Offset = {120 10};
POINT ptBtn2Offset = {20 32};
POINT ptBtn3Offset = {190 10};
SIZE sizeBtn1 = {60 14};
SIZE sizeBtn2 = {16 14};
SIZE sizeBtn3 = {16 14};

m_NcButton1.Create(““ this->m_hWnd ptBtn1Offset sizeBtn1 ID_BUTTON1);
m_NcButton2.Create(““ this->m_hWnd ptBtn2Offset sizeBtn2 ID_BUTTON2);
m_NcButton3.Create(““ this->m_hWnd ptBtn3Offset sizeBtn3 ID_BUTTON3);

m_NcButton1.SetText(“VC知识库“ “宋体“ 12);
m_NcButton1.SetTooltip(“VC知识库欢迎您!“);
m_NcButton2.SetButtonBitmap(IDB_PEN1 BTNBMP_NORMAL);
m_NcButton2.SetButtonBitmap(IDB_PEN2 BTNBMP_MOUSEOVER);
m_NcButton2.SetTooltip(“pen“);

m_NcButton3.SetButtonBitmap(IDB_PEN1 BTNBMP_NORMAL);
m_NcButton3.SetButtonBitmap(IDB_PEN2 BTNBMP_MOUSEOVER);
m_NcButton3.SetTooltip(“pen“);

m_NcButtonManager.AddButton(&m_NcButton1);
m_NcButtonManager.AddButton(&m_NcButton2);
m_NcButtonManager.AddButton(&m_NcButton3);

return 0;
}

BOOL CMainframe::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CframeWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
//  the CREATESTRUCT cs

return TRUE

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1848  2004-03-21 20:14  titleButtonTest2\NCButtonManager.h

     文件        693  2004-03-21 19:41  titleButtonTest2\resource.h

     文件        218  2004-03-21 16:17  titleButtonTest2\StdAfx.cpp

     文件       1138  2004-03-21 16:22  titleButtonTest2\StdAfx.h

     文件      30600  2008-05-31 17:15  titleButtonTest2\titleButtonTest2.aps

     文件       2404  2008-05-31 18:32  titleButtonTest2\titleButtonTest2.clw

     文件       4389  2004-03-21 16:17  titleButtonTest2\titleButtonTest2.cpp

     文件        557  2004-03-21 16:17  titleButtonTest2\titleButtonTest2.dsw

     文件       1466  2004-03-21 16:17  titleButtonTest2\titleButtonTest2.h

     文件      11912  2004-03-21 19:41  titleButtonTest2\titleButtonTest2.rc

     文件       1942  2004-03-21 16:17  titleButtonTest2\titleButtonTest2Doc.cpp

     文件       1585  2004-03-21 16:17  titleButtonTest2\titleButtonTest2Doc.h

     文件       2879  2004-03-21 16:17  titleButtonTest2\titleButtonTest2View.cpp

     文件       2051  2004-03-21 16:17  titleButtonTest2\titleButtonTest2View.h

     文件        376  2008-05-31 18:09  titleButtonTest2\res\pen1.bmp

     文件        376  2008-05-31 18:09  titleButtonTest2\res\pen2.bmp

     文件       1078  2004-03-21 16:17  titleButtonTest2\res\titleButtonTest2.ico

     文件        408  2004-03-21 16:17  titleButtonTest2\res\titleButtonTest2.rc2

     文件       1078  2004-03-21 16:17  titleButtonTest2\res\titleButtonTest2Doc.ico

     文件       1078  2004-03-21 16:17  titleButtonTest2\res\Toolbar.bmp

     文件       4452  2008-05-31 17:58  titleButtonTest2\MainFrm.cpp

     文件       2105  2008-05-31 17:58  titleButtonTest2\MainFrm.h

     文件      16327  2008-05-31 18:04  titleButtonTest2\NCButton.cpp

     文件       2735  2004-03-21 20:11  titleButtonTest2\NCButton.h

     文件       9537  2004-03-21 20:12  titleButtonTest2\NCButtonManager.cpp

     文件        173  2012-01-21 19:37  titleButtonTest2\copyright.bat

     文件       2670  2012-02-10 17:38  titleButtonTest2\titleButtonTest2.plg

     文件       5372  2012-02-10 17:38  titleButtonTest2\titleButtonTest2.dsp

     目录          0  2008-05-31 18:09  titleButtonTest2\res

     目录          0  2012-02-10 17:38  titleButtonTest2

............此处省略3个文件信息

评论

共有 条评论