在资源编译器里画一对话框条IDD_DIALOGBAR1,然后用CLASSWIDZAD加类,基类用的是CWnd,后手动改为CDialogBar,class CMyDialogBar:public CdialogBarMainFrm.h下定义
CMyDialogBar m_DialogBar;MainFrm.cpp下if (!m_DialogBar.Create(this,IDD_DIALOGBAR1,CBRS_LEFT|CBRS_TOOLTIPS|CBRS_FLYBY|WS_VISIBLE|WS_CHILD,IDD_DIALOGBAR1))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
问题:
1、运行后不显示对话框条;
2、不能写停泊EnableDocking,写了就有断言错误;
3、想在对话框条上画图,
CMyDialogBar m_DialogBar;MainFrm.cpp下if (!m_DialogBar.Create(this,IDD_DIALOGBAR1,CBRS_LEFT|CBRS_TOOLTIPS|CBRS_FLYBY|WS_VISIBLE|WS_CHILD,IDD_DIALOGBAR1))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
问题:
1、运行后不显示对话框条;
2、不能写停泊EnableDocking,写了就有断言错误;
3、想在对话框条上画图,
不行的话,我给你个小例子
你要想docking,用CReBar好了
{
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
} //Create the user command bar in the CMainFrame's bottom!
if (!m_wndDlgBar.Create(this, IDD_COMMAND_BAR,
CBRS_BOTTOM|CBRS_TOOLTIPS|CBRS_FLYBY, IDD_COMMAND_BAR))
{
TRACE0("Failed to create DlgBar\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); CStatic *pStatic=(CStatic*)this->m_wndDlgBar.GetDlgItem(IDC_STATIC_MOVE);
if(pStatic!=NULL)
{
pStatic->SetTimer(1,100L,NULL);
this->m_StaticMove.SubclassDlgItem(IDC_STATIC_MOVE,&this->m_wndDlgBar);
}
return 0;
}
例如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
} //Create the user command bar in the CMainFrame's bottom!
if (!m_wndDlgBar.Create(this, IDD_COMMAND_BAR,
CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY |
CBRS_SIZE_DYNAMIC|CBRS_BOTTOM, IDD_COMMAND_BAR))
{
TRACE0("Failed to create DlgBar\n");
return -1; // Fail to create.
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
CStatic *pStatic=(CStatic*)this->m_wndDlgBar.GetDlgItem(IDC_STATIC_MOVE);
if(pStatic!=NULL)
{
pStatic->SetTimer(1,100L,NULL);
this->m_StaticMove.SubclassDlgItem(IDC_STATIC_MOVE,&this->m_wndDlgBar);
} this->m_wndDlgBar.EnableDocking(CBRS_ALIGN_ANY);
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
DockControlBar(&this->m_wndDlgBar);
return 0;
}
我上面的代码就是在CDialogBar上了画了一个动态的园,很easy的!
CStatic *pStatic=(CStatic*)this->m_wndDlgBar.GetDlgItem(IDC_STATIC_MOVE);
if(pStatic!=NULL)
{
pStatic->SetTimer(1,100L,NULL);
this->m_StaticMove.SubclassDlgItem(IDC_STATIC_MOVE,&this->m_wndDlgBar);
}给你个demo工程吧!
你可以到我得ftp下载去:ftp://csdn:[email protected]:10766
里面有个文件UseEditLogin.rar今天心情很不错!帮人帮到底了
#define AFX_STATIC_MOVE_H__23870C90_CA4C_4E8E_85CC_9AD1C608E843__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Static_Move.h : header file
///////////////////////////////////////////////////////////////////////////////
// CStatic_Move windowclass CStatic_Move : public CStatic
{
// Construction
public:
CStatic_Move();
private:
CPen m_pen;
CBrush m_brush[3];
int m_index;
// Attributes
public:// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CStatic_Move)
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CStatic_Move(); // Generated message map functions
protected:
//{{AFX_MSG(CStatic_Move)
afx_msg void OnPaint();
afx_msg void OnTimer(UINT nIDEvent);
//}}AFX_MSG DECLARE_MESSAGE_MAP()
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_STATIC_MOVE_H__23870C90_CA4C_4E8E_85CC_9AD1C608E843__INCLUDED_)
//------------------------------------------------------
// Static_Move.cpp : implementation file
//#include "stdafx.h"
#include "UseEditLogin.h"
#include "Static_Move.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CStatic_MoveCStatic_Move::CStatic_Move()
{
m_pen.CreateStockObject(NULL_PEN);
m_brush[0].CreateSolidBrush(RGB(255,0,0));//red
m_brush[1].CreateSolidBrush(RGB(0,255,0));//green
m_brush[2].CreateSolidBrush(RGB(0,0,255));//blue
m_index=0;
}CStatic_Move::~CStatic_Move()
{
}
BEGIN_MESSAGE_MAP(CStatic_Move, CStatic)
//{{AFX_MSG_MAP(CStatic_Move)
ON_WM_PAINT()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CStatic_Move message handlersvoid CStatic_Move::OnPaint()
{
CPaintDC dc(this); // device context for painting
// Get the client area.
CRect rectClient;
GetClientRect(rectClient);
CPoint ptCentral=rectClient.CenterPoint();
int dim=rectClient.Width()<rectClient.Height()?rectClient.Width():rectClient.Height(); //make sure the rectClient to be a circle!
if(dim<rectClient.Width())
rectClient.InflateRect(-CSize((rectClient.Width()-dim)/2,0));
else
rectClient.InflateRect(CSize(0,-(rectClient.Height()-dim)/2)); CPoint pt[3];
pt[0]=CPoint(0,ptCentral.y);
pt[1]= CPoint(int(dim*3/4),int(ptCentral.y-1.732*dim/4));
pt[2]=CPoint(int(dim*3/4),int(ptCentral.y+1.732*dim/4)); CBrush* pOldBrush;
CPen* pOldPen;
pOldPen = dc.SelectObject(&m_pen);
pOldBrush = dc.SelectObject(&m_brush[m_index]); dc.Pie(rectClient,pt[1],pt[0]);
dc.SelectObject(&m_brush[(m_index+1)%3]);
dc.Pie(rectClient,pt[0],pt[2]);
dc.SelectObject(&m_brush[(m_index+2)%3]);
dc.Pie(rectClient,pt[2],pt[1]);
// Restore the previous pen and brush.
dc.SelectObject(pOldPen);
dc.SelectObject(pOldBrush);
// Do not call CStatic::OnPaint() for painting messages
}void CStatic_Move::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
// TODO: Add your message handler code here and/or call default
m_index++;
if(m_index>2)
m_index=0;
this->Invalidate();
CStatic::OnTimer(nIDEvent);
CStatic::OnTimer(nIDEvent);
}
//新工作搞定了,心情愉快中。