|
主要实现路径是通过创建一个可停靠窗口,并在其中创建toolbutton并给button点击事件添加命令,将子菜单menu显示在button位置,如果需要更加顺滑的交互,需要重写一下menu的样式。
像文中所说,可以通过一个xml文件来控制控件,这样可以省略修改交互的步骤,
我这里只是做出了单纯横向布置的实现和button边框背景取消,还需要增加自适应修改的内容,让侧边顶部都可以实现。
代码逻辑也没有什么可以说的,直接将代码放到下面:
Dialog:- //-----------------------------------------------------------------------------
- class CDockControlBarChildDlg : public CAcUiDialog {
- DECLARE采用DYNAMIC (CDockControlBarChildDlg)
- public:
- CDockControlBarChildDlg (CWnd *pParent =NULL, HINSTANCE hInstance =NULL) ;
- enum { IDD = IDD采用DOCKCONTROLBAR};
- protected:
- virtual void DoDataExchange (CDataExchange *pDX) ;
- virtual BOOL OnCommand (WPARAM wParam, LPARAM lParam) ;
- BOOL OnInitDialog() override;
- protected:
- afx采用msg LRESULT OnAcadKeepFocus (WPARAM wParam, LPARAM lParam) ;
- public:
- afx采用msg void OnSize (UINT nType, int cx, int cy) ;
- protected:
- DECLARE采用MESSAGE采用MAP()
- public:
- CDockMenuPickButton m采用btn采用1;
- CDockMenuPickButton m采用btn采用3;
- CDockMenuPickButton m采用btn采用4;
- CDockMenuPickButton m采用btn采用5;
- CDockMenuPickButton m采用btn采用6;
- CDockMenuPickButton m采用btn采用7;
- afx采用msg void OnBnClickedButton7();
- afx采用msg void OnBnClickedButton6();
- afx采用msg void OnBnClickedButton3();
- afx采用msg void OnBnClickedButton4();
- afx采用msg void OnBnClickedButton5();
- afx采用msg void OnBnClickedButton1();
- private:
- CMenu m采用menu采用1;
- CMenu m采用menu采用3;
- CMenu m采用menu采用4;
- CMenu m采用menu采用5;
- CMenu m采用menu采用6;
- CMenu m采用menu采用7;
- } ;
- IMPLEMENT采用DYNAMIC (CDockControlBarChildDlg, CAcUiDialog)
- BEGIN采用MESSAGE采用MAP(CDockControlBarChildDlg, CAcUiDialog)
- //{{AFX采用MSG采用MAP(CDockControlBarChildDlg)
- ON采用MESSAGE(WM采用ACAD采用KEEPFOCUS, OnAcadKeepFocus) // Needed for modeless dialog.
- //}}AFX采用MSG采用MAP
- ON采用BN采用CLICKED(IDC采用BUTTON7, &CDockControlBarChildDlg::OnBnClickedButton7)
- ON采用BN采用CLICKED(IDC采用BUTTON6, &CDockControlBarChildDlg::OnBnClickedButton6)
- ON采用BN采用CLICKED(IDC采用BUTTON3, &CDockControlBarChildDlg::OnBnClickedButton3)
- ON采用BN采用CLICKED(IDC采用BUTTON4, &CDockControlBarChildDlg::OnBnClickedButton4)
- ON采用BN采用CLICKED(IDC采用BUTTON5, &CDockControlBarChildDlg::OnBnClickedButton5)
- ON采用BN采用CLICKED(IDC采用BUTTON1, &CDockControlBarChildDlg::OnBnClickedButton1)
- END采用MESSAGE采用MAP()
- //-----------------------------------------------------------------------------
- CDockControlBarChildDlg::CDockControlBarChildDlg (CWnd *pParent /*=NULL*/, HINSTANCE hInstance /*=NULL*/) : CAcUiDialog (CDockControlBarChildDlg::IDD, pParent, hInstance) {
- //{{AFX采用DATA采用INIT(CDockControlBarChildDlg)
- //}}AFX采用DATA采用INIT
- }
- //-----------------------------------------------------------------------------
- void CDockControlBarChildDlg::DoDataExchange (CDataExchange *pDX) {
- CAcUiDialog::DoDataExchange(pDX);
- //{{AFX采用DATA采用MAP(CDockControlBarChildDlg)
- //}}AFX采用DATA采用MAP
- DDX采用Control(pDX, IDC采用BUTTON1, m采用btn采用1);//意见反馈
- DDX采用Control(pDX, IDC采用BUTTON6, m采用btn采用6);//样图模板
- DDX采用Control(pDX, IDC采用BUTTON3, m采用btn采用3);//文本模板
- DDX采用Control(pDX, IDC采用BUTTON4, m采用btn采用4);//效率工具
- DDX采用Control(pDX, IDC采用BUTTON5, m采用btn采用5);//绘制指导
- DDX采用Control(pDX, IDC采用BUTTON7, m采用btn采用7);//制图模板
- }
- //-----------------------------------------------------------------------------
- //- Needed for modeless dialogs to keep focus.
- //- Return FALSE to not keep the focus, return TRUE to keep the focus
- LRESULT CDockControlBarChildDlg::OnAcadKeepFocus (WPARAM wParam, LPARAM lParam) {
- return (TRUE) ;
- }
- //-----------------------------------------------------------------------------
- //- As this dialog is a child dialog we need to disable ok and cancel
- BOOL CDockControlBarChildDlg::OnCommand (WPARAM wParam, LPARAM lParam) {
- switch ( wParam ) {
- case IDOK:
- case IDCANCEL:
- return (FALSE) ;
- }
- return (CAcUiDialog::OnCommand (wParam, lParam)) ;
- }
- BOOL CDockControlBarChildDlg::OnInitDialog()
- {
- CAcUiDialog::OnInitDialog();
- //制图标准
- m采用menu采用7.CreatePopupMenu();
- m采用menu采用7.AppendMenu(MF采用STRING, ID采用32768, 采用T("标准图框"));
- m采用menu采用7.AppendMenu(MF采用STRING, ID采用32769, 采用T("图层标准"));
- m采用menu采用7.AppendMenu(MF采用STRING, ID采用32770, 采用T("制图标准"));
- m采用menu采用7.AppendMenu(MF采用STRING, ID采用32771, 采用T("常用图块"));
- //效率工具
- m采用menu采用4.CreatePopupMenu();
- m采用menu采用4.AppendMenu(MF采用STRING, ID采用32778, 采用T("数据速查"));
- m采用menu采用4.AppendMenu(MF采用STRING, ID采用32779, 采用T("计算表格"));
- m采用menu采用4.AppendMenu(MF采用STRING, ID采用327710, 采用T("绘图研发工具"));
- 文本模板
- m采用menu采用3.CreatePopupMenu();
- m采用menu采用3.AppendMenu(MF采用STRING, ID采用32774, 采用T("设计信息征询表"));
- m采用menu采用3.AppendMenu(MF采用STRING, ID采用32775, 采用T("评审文本"));
- m采用menu采用3.AppendMenu(MF采用STRING, ID采用32776, 采用T("汇报文本"));
- m采用menu采用3.AppendMenu(MF采用STRING, ID采用32777, 采用T("施工图设计文件"));
- 样图模板
- m采用menu采用6.CreatePopupMenu();
- m采用menu采用6.AppendMenu(MF采用STRING, ID采用32772, 采用T("样图模板"));
- m采用menu采用6.AppendMenu(MF采用STRING, ID采用327723, 采用T("深度样图"));
- 绘制指导
- m采用menu采用5.CreatePopupMenu();
- m采用menu采用5.AppendMenu(MF采用STRING, ID采用327711, 采用T("制图标准指导书"));
- m采用menu采用5.AppendMenu(MF采用STRING, ID采用327712, 采用T("平面类绘制指导书"));
- m采用menu采用5.AppendMenu(MF采用STRING, ID采用327713, 采用T("立剖面绘制指导书"));
- m采用menu采用5.AppendMenu(MF采用STRING, ID采用327714, 采用T("放大图绘制指导书"));
- m采用menu采用5.AppendMenu(MF采用STRING, ID采用327715, 采用T("专项绘制绘制指导书"));
- 意见反馈
- m采用menu采用1.CreatePopupMenu();
- m采用menu采用1.AppendMenu(MF采用STRING, ID采用327716, 采用T("意见反馈"));
- /*m采用menu采用1 = (CMenu*)GetDlgItem(IDR采用MENU1);
- m采用btn采用1.SetMenu(m采用menu采用1);*/
-
- return TRUE;
- }
- //-----------------------------------------------------------------------------
- void CDockControlBarChildDlg::OnSize (UINT nType, int cx, int cy) {
- CAcUiDialog::OnSize (nType, cx, cy) ;
- //- Now update the dialog
- MoveWindow (0, 0, cx, cy) ;
- }
- void CDockControlBarChildDlg::OnBnClickedButton7()
- {
- CRect rect;
- m采用btn采用7.GetWindowRect(&rect);
- CString str;
- str.Format(采用T("rect width : %d , rect length : %d"), rect.Width(), rect.Height());
- m采用menu采用7.TrackPopupMenu(TPM采用LEFTALIGN | TPM采用TOPALIGN, rect.left, rect.bottom, this);
- //m采用menu.TrackPopupMenu(TPM采用LEFTALIGN | TPM采用TOPALIGN, rect.left, rect.bottom, this);
- }
- void CDockControlBarChildDlg::OnBnClickedButton6()
- {
- // TODO: 在此添加控件通知处理程序代码
- CRect rect;
- m采用btn采用6.GetWindowRect(&rect);
- CString str;
- str.Format(采用T("rect width : %d , rect length : %d"), rect.Width(), rect.Height());
- m采用menu采用6.TrackPopupMenu(TPM采用LEFTALIGN | TPM采用TOPALIGN, rect.left, rect.bottom, this);
- }
- void CDockControlBarChildDlg::OnBnClickedButton3()
- {
- // TODO: 在此添加控件通知处理程序代码
- CRect rect;
- m采用btn采用3.GetWindowRect(&rect);
- CString str;
- str.Format(采用T("rect width : %d , rect length : %d"), rect.Width(), rect.Height());
- m采用menu采用3.TrackPopupMenu(TPM采用LEFTALIGN | TPM采用TOPALIGN, rect.left, rect.bottom, this);
- }
- void CDockControlBarChildDlg::OnBnClickedButton4()
- {
- // TODO: 在此添加控件通知处理程序代码
- CRect rect;
- m采用btn采用4.GetWindowRect(&rect);
- CString str;
- str.Format(采用T("rect width : %d , rect length : %d"), rect.Width(), rect.Height());
- m采用menu采用4.TrackPopupMenu(TPM采用LEFTALIGN | TPM采用TOPALIGN, rect.left, rect.bottom, this);
- }
- void CDockControlBarChildDlg::OnBnClickedButton5()
- {
- // TODO: 在此添加控件通知处理程序代码
- CRect rect;
- m采用btn采用5.GetWindowRect(&rect);
- CString str;
- str.Format(采用T("rect width : %d , rect length : %d"), rect.Width(), rect.Height());
- m采用menu采用5.TrackPopupMenu(TPM采用LEFTALIGN | TPM采用TOPALIGN, rect.left, rect.bottom, this);
- }
- void CDockControlBarChildDlg::OnBnClickedButton1()
- {
- //MessageBox(采用T("Test Menu"));
- // TODO: 在此添加控件通知处理程序代码
- CRect rect;
- m采用btn采用1.GetWindowRect(&rect);
- /*CString str;
- str.Format(采用T("rect width : %d , rect length : %d"), rect.left, rect.bottom);
- MessageBox(str);*/
- BOOL addMenu = m采用menu采用1.TrackPopupMenu(TPM采用LEFTALIGN | TPM采用TOPALIGN, rect.left, rect.bottom, this);
- if(!addMenu)
- {
- MessageBox(采用T("Test Menu Failed"));
- }
- }
复制代码
Button:- //-----------------------------------------------------------------------------
- class CDockMenuPickButton : public CAcUiToolButton {
- DECLARE采用DYNAMIC (CDockMenuPickButton)
- public:
- CDockMenuPickButton () ;
- virtual ~CDockMenuPickButton () ;
- void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) override;
-
- afx采用msg void OnMouseMove(UINT nFlags, CPoint point);
- afx采用msg void OnMouseHover(UINT nFlags, CPoint point);
- afx采用msg void OnMouseLeave();
- protected:
- DECLARE采用MESSAGE采用MAP()
- private:
- BOOL m采用bTrackLeave;
- } ;
- #include "StdAfx.h"
- #include "resource.h"
- #include "DockMenuPickButton.h"
- //-----------------------------------------------------------------------------
- IMPLEMENT采用DYNAMIC (CDockMenuPickButton, CAcUiToolButton)
- BEGIN采用MESSAGE采用MAP(CDockMenuPickButton, CAcUiToolButton)
- END采用MESSAGE采用MAP()
- CDC* hdc;
- CRect hRect;
- //-----------------------------------------------------------------------------
- CDockMenuPickButton::CDockMenuPickButton () {
- }
- //-----------------------------------------------------------------------------
- CDockMenuPickButton::~CDockMenuPickButton () {
- }
- void CDockMenuPickButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
- {
- CDC dc;
- dc.Attach(lpDrawItemStruct->hDC);
- dc.SelectStockObject(NULL采用BRUSH);
- dc.Rectangle(&lpDrawItemStruct->rcItem);
- hdc = &dc;
- COLORREF local采用bk = dc.GetBkColor();
- CString str;
- GetWindowText(str);
- CRect rect = lpDrawItemStruct->rcItem;
- hRect = rect;
- GetClientRect(&rect);
- //设置背景透明色
- dc.SetBkMode(TRANSPARENT);
- dc.SetPolyFillMode(TRANSPARENT);
- ::GetStockObject(NULL采用BRUSH);
-
- //设置画笔为空,无边框
- if(lpDrawItemStruct->itemState & ODS采用SELECTED )
- {
- //设置颜色为背景色,实现边框取消的效果
- //dc.FillSolidRect(&rect,::GetBkColor(dc));
- dc.FillSolidRect(&rect, RGB(190, 200, 255));
- //如果悬停或者选中,需要显示仅显示边框
- dc.Draw3dRect(&rect, GetSysColor(COLOR采用3DDKSHADOW), GetSysColor(COLOR采用3DDKSHADOW));
- //设置文字
- dc.DrawText(str, rect, DT采用SINGLELINE | DT采用CENTER | DT采用VCENTER);
- dc.SetTextColor(RGB(255, 0, 0));
- }
- else if(lpDrawItemStruct->itemData & ODS采用HOTLIGHT)
- {
- //设置颜色为背景色,实现边框取消的效果
- dc.FillSolidRect(&rect, RGB(170,180,255));
- //设置文字
- dc.DrawText(str, rect, DT采用SINGLELINE | DT采用CENTER | DT采用VCENTER);
- dc.SetTextColor(RGB(255, 0, 0));
- }
- else
- {
- //设置颜色为背景色,实现边框取消的效果
- dc.FillSolidRect(&rect, ::GetBkColor(dc));
- //设置文字
- dc.DrawText(str, rect, DT采用SINGLELINE | DT采用CENTER | DT采用VCENTER);
- dc.SetTextColor(RGB(255, 0, 0));
- }
-
- //CBrush* pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL采用BRUSH));
- //CBrush* pOldBrush = dc.SelectObject(pBrush);
- //dc.SelectObject(pBrush);
-
- //dc.SelectObject(pOldBrush);
- }
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|