明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 553|回复: 2

ARX 工具条问题

[复制链接]
发表于 2025-5-8 15:13:47 | 显示全部楼层 |阅读模式
前情提要:之前想制作一个工具条,经过数日研究,想使用CAdUiDialogBar 类来制作。
完成后发现菜单栏不能点击,请问这个是什么问题,如何解决?

  1. #include "adui.h"
  2. #include "resource.h"
  3. //-----------------------------------------------------------------------------
  4. class CPolaDialogBar : public CAdUiDialogBar {
  5.   DECLARE_DYNAMIC (CPolaDialogBar)

  6. public:
  7.   CPolaDialogBar (CWnd *pParent =NULL, HINSTANCE hInstance =NULL) ;
  8.   BOOL Create(CFrameWnd* pParentWnd, CString csName);
  9.   enum { IDD = IDD_POLADIALOGBAR} ;

  10. protected:
  11.   virtual void DoDataExchange (CDataExchange *pDX) ;
  12.   afx_msg LRESULT OnAcadKeepFocus (WPARAM, LPARAM) ;
  13.   afx_msg void OnMenuSelect(UINT nID);
  14.   DECLARE_MESSAGE_MAP()
  15. public:
  16.   CMenu m_menu;
  17.   CButton* pButton;
  18.   afx_msg void OnPaint();
  19.   afx_msg void OnSize(UINT nType, int cx, int cy);
  20.   afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  21.   afx_msg void OnButtonClicked();
  22. } ;


  1. #include "StdAfx.h"
  2. #include "resource.h"
  3. #include "PolaDialogBar.h"

  4. //-----------------------------------------------------------------------------
  5. IMPLEMENT_DYNAMIC (CPolaDialogBar, CAdUiDialogBar)

  6. BEGIN_MESSAGE_MAP(CPolaDialogBar, CAdUiDialogBar)
  7.   ON_MESSAGE(WM_ACAD_KEEPFOCUS, OnAcadKeepFocus)
  8.   ON_WM_PAINT()
  9.   ON_WM_SIZE()
  10.   ON_WM_CREATE()
  11.   ON_BN_CLICKED(64000, OnButtonClicked)
  12.   ON_COMMAND_RANGE(ID_MENU_ITEM_1, ID_MENU_ITEM_3, OnMenuSelect)

  13. END_MESSAGE_MAP()

  14. //-----------------------------------------------------------------------------
  15. CPolaDialogBar::CPolaDialogBar (CWnd *pParent /*=NULL*/, HINSTANCE hInstance /*=NULL*/) : CAdUiDialogBar (/*CPolaDialogBar::IDD, pParent, hInstance*/) {
  16. }

  17. BOOL CPolaDialogBar::Create(CFrameWnd* pParentWnd, CString csName)
  18. {
  19.   CAcModuleResourceOverride Vtemp;

  20.   if (!CAdUiDialogBar::Create(pParentWnd, IDD_POLADIALOGBAR, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_BOTTOM, AFX_IDW_CONTROLBAR_LAST))
  21.   {
  22.     return FALSE;
  23.   }
  24.   SetBorders();
  25.   SetWindowText(csName);
  26.   EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
  27.   EnableWindow(true);
  28.   GetDockingFrame()->ShowControlBar(this, TRUE, FALSE);
  29.   GetDockingFrame()->RecalcLayout();
  30.   return TRUE;
  31. }

  32. //-----------------------------------------------------------------------------
  33. void CPolaDialogBar::DoDataExchange (CDataExchange *pDX) {
  34.   CAdUiDialogBar::DoDataExchange (pDX) ;
  35. }

  36. //-----------------------------------------------------------------------------
  37. //----- Needed for modeless dialogs to keep focus.
  38. //----- Return FALSE to not keep the focus, return TRUE to keep the focus
  39. LRESULT CPolaDialogBar::OnAcadKeepFocus (WPARAM, LPARAM) {
  40.   return (TRUE) ;
  41. }

  42. void CPolaDialogBar::OnMenuSelect(UINT nID)
  43. {
  44.   switch (nID)
  45.   {
  46.   case ID_MENU_ITEM_1:
  47.     AfxMessageBox(_T("你选择了菜单项 1"));
  48.     break;
  49.   case ID_MENU_ITEM_2:
  50.     AfxMessageBox(_T("你选择了菜单项 2"));
  51.     break;
  52.   case ID_MENU_ITEM_3:
  53.     AfxMessageBox(_T("你选择了菜单项 3"));
  54.     break;
  55.   }
  56. }

  57. void CPolaDialogBar::OnPaint()
  58. {
  59.   CPaintDC dc(this); // device context for painting

  60.   // TODO: 在此处添加消息处理程序代码
  61.   // 不为绘图消息调用 CAdUiDialogBar::OnPaint()
  62.   
  63. }

  64. void CPolaDialogBar::OnSize(UINT nType, int cx, int cy)
  65. {
  66.   CAdUiDialogBar::OnSize(nType, cx, cy);

  67.   // TODO: 在此处添加消息处理程序代码
  68. }

  69. int CPolaDialogBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
  70. {
  71.   CAcModuleResourceOverride resOverride;
  72.   if (CAdUiDialogBar::OnCreate(lpCreateStruct) == -1)
  73.     return -1;

  74.   // TODO:  在此添加您专用的创建代码
  75.   m_menu.CreatePopupMenu();
  76.   m_menu.AppendMenu(MF_STRING, ID_MENU_ITEM_1, _T("菜单项 1"));
  77.   m_menu.AppendMenu(MF_STRING, ID_MENU_ITEM_2, _T("菜单项 2"));
  78.   m_menu.AppendMenu(MF_STRING, ID_MENU_ITEM_3, _T("菜单项 3"));

  79.   CRect rect(10, 10, 100, 30);
  80.   pButton = new CButton();
  81.   if (!pButton->Create(_T("菜单"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, rect, this, 64000))
  82.   {
  83.     AfxMessageBox(_T("按钮创建失败!"));
  84.     delete pButton;
  85.     pButton = nullptr;
  86.     return -1;
  87.   }

  88.   CFont* pFont = CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT));
  89.   pButton->SetFont(pFont);
  90.   pButton->EnableWindow(TRUE); // 显式启用按钮
  91.   GetDockingFrame()->SetFocus();
  92.   return 0;
  93. }

  94. void CPolaDialogBar::OnButtonClicked()
  95. {
  96.   CPoint point;
  97.   GetCursorPos(&point);
  98.   m_menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
  99. }


  1. #include "stdafx.h"
  2. #include "TestClass.h"
  3. #include "PolaDialogBar.h"

  4. void TestClass::TestClassInit()
  5. {
  6.   acedRegCmds->addCommand(_T("tmpGroupName"), _T("TestBar"), _T("TestBar"), ACRX_CMD_MODAL, Test);
  7. }
  8. void TestClass::TestClassUnload()
  9. {
  10.   acedRegCmds->removeGroup(_T("tmpGroupName"));
  11. }
  12. void TestClass::Test()
  13. {
  14.   CAcModuleResourceOverride res;      // TODO
  15.   CPolaDialogBar* pbar = nullptr;
  16.   if (!pbar)
  17.   {
  18.     AfxSetResourceHandle(_hdllInstance);
  19.     pbar = new CPolaDialogBar;
  20.     if (!pbar->Create(acedGetAcadFrame(), _T("bar")))
  21.     {
  22.       TRACE0("Failed to create DlgBar\n");
  23.       return; // fail to create
  24.     }
  25.     AfxSetResourceHandle(acedGetAcadResourceInstance());
  26.     pbar->EnableDocking(CBRS_ALIGN_ANY);
  27.     acedGetAcadFrame()->DockControlBar(pbar, CBRS_ALIGN_TOP);
  28.     pbar->SetWindowText(_T("pbar"));
  29.   }
  30.   acedGetAcadFrame()->ShowControlBar(pbar, TRUE, FALSE);
  31.   acedGetAcadFrame()->RecalcLayout();
  32.   AcUiMainWindow()->RedrawWindow();
  33.   AdUiShowDockControlBars(true);
  34. }

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
回复

使用道具 举报

 楼主| 发表于 2025-5-9 15:06:25 | 显示全部楼层
此贴终结,在这个论坛上找到了答案。
https://forums.codeguru.com/showthread.php?485273-Why-are-my-dialog-bar-buttons-are-disabled

添加 UpdateCmdUI handlers 可以解决
  1. void CPolaDialogBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHandler)
  2. {
  3.         // TODO: 在此添加专用代码和/或调用基类
  4.         CAdUiDialogBar::OnUpdateCmdUI(pTarget, FALSE);
  5. }
回复 支持 1 反对 0

使用道具 举报

发表于 2025-5-23 09:28:22 | 显示全部楼层


论坛评分貌似有问题,无法使用

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-31 01:14 , Processed in 0.166138 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表