ARX 工具条问题
前情提要:之前想制作一个工具条,经过数日研究,想使用CAdUiDialogBar 类来制作。完成后发现菜单栏不能点击,请问这个是什么问题,如何解决?
#include "adui.h"
#include "resource.h"
//-----------------------------------------------------------------------------
class CPolaDialogBar : public CAdUiDialogBar {
DECLARE_DYNAMIC (CPolaDialogBar)
public:
CPolaDialogBar (CWnd *pParent =NULL, HINSTANCE hInstance =NULL) ;
BOOL Create(CFrameWnd* pParentWnd, CString csName);
enum { IDD = IDD_POLADIALOGBAR} ;
protected:
virtual void DoDataExchange (CDataExchange *pDX) ;
afx_msg LRESULT OnAcadKeepFocus (WPARAM, LPARAM) ;
afx_msg void OnMenuSelect(UINT nID);
DECLARE_MESSAGE_MAP()
public:
CMenu m_menu;
CButton* pButton;
afx_msg void OnPaint();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnButtonClicked();
} ;
#include "StdAfx.h"
#include "resource.h"
#include "PolaDialogBar.h"
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC (CPolaDialogBar, CAdUiDialogBar)
BEGIN_MESSAGE_MAP(CPolaDialogBar, CAdUiDialogBar)
ON_MESSAGE(WM_ACAD_KEEPFOCUS, OnAcadKeepFocus)
ON_WM_PAINT()
ON_WM_SIZE()
ON_WM_CREATE()
ON_BN_CLICKED(64000, OnButtonClicked)
ON_COMMAND_RANGE(ID_MENU_ITEM_1, ID_MENU_ITEM_3, OnMenuSelect)
END_MESSAGE_MAP()
//-----------------------------------------------------------------------------
CPolaDialogBar::CPolaDialogBar (CWnd *pParent /*=NULL*/, HINSTANCE hInstance /*=NULL*/) : CAdUiDialogBar (/*CPolaDialogBar::IDD, pParent, hInstance*/) {
}
BOOL CPolaDialogBar::Create(CFrameWnd* pParentWnd, CString csName)
{
CAcModuleResourceOverride Vtemp;
if (!CAdUiDialogBar::Create(pParentWnd, IDD_POLADIALOGBAR, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_BOTTOM, AFX_IDW_CONTROLBAR_LAST))
{
return FALSE;
}
SetBorders();
SetWindowText(csName);
EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM);
EnableWindow(true);
GetDockingFrame()->ShowControlBar(this, TRUE, FALSE);
GetDockingFrame()->RecalcLayout();
return TRUE;
}
//-----------------------------------------------------------------------------
void CPolaDialogBar::DoDataExchange (CDataExchange *pDX) {
CAdUiDialogBar::DoDataExchange (pDX) ;
}
//-----------------------------------------------------------------------------
//----- Needed for modeless dialogs to keep focus.
//----- Return FALSE to not keep the focus, return TRUE to keep the focus
LRESULT CPolaDialogBar::OnAcadKeepFocus (WPARAM, LPARAM) {
return (TRUE) ;
}
void CPolaDialogBar::OnMenuSelect(UINT nID)
{
switch (nID)
{
case ID_MENU_ITEM_1:
AfxMessageBox(_T("你选择了菜单项 1"));
break;
case ID_MENU_ITEM_2:
AfxMessageBox(_T("你选择了菜单项 2"));
break;
case ID_MENU_ITEM_3:
AfxMessageBox(_T("你选择了菜单项 3"));
break;
}
}
void CPolaDialogBar::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CAdUiDialogBar::OnPaint()
}
void CPolaDialogBar::OnSize(UINT nType, int cx, int cy)
{
CAdUiDialogBar::OnSize(nType, cx, cy);
// TODO: 在此处添加消息处理程序代码
}
int CPolaDialogBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
CAcModuleResourceOverride resOverride;
if (CAdUiDialogBar::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO:在此添加您专用的创建代码
m_menu.CreatePopupMenu();
m_menu.AppendMenu(MF_STRING, ID_MENU_ITEM_1, _T("菜单项 1"));
m_menu.AppendMenu(MF_STRING, ID_MENU_ITEM_2, _T("菜单项 2"));
m_menu.AppendMenu(MF_STRING, ID_MENU_ITEM_3, _T("菜单项 3"));
CRect rect(10, 10, 100, 30);
pButton = new CButton();
if (!pButton->Create(_T("菜单"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, rect, this, 64000))
{
AfxMessageBox(_T("按钮创建失败!"));
delete pButton;
pButton = nullptr;
return -1;
}
CFont* pFont = CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT));
pButton->SetFont(pFont);
pButton->EnableWindow(TRUE); // 显式启用按钮
GetDockingFrame()->SetFocus();
return 0;
}
void CPolaDialogBar::OnButtonClicked()
{
CPoint point;
GetCursorPos(&point);
m_menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
}
#include "stdafx.h"
#include "TestClass.h"
#include "PolaDialogBar.h"
void TestClass::TestClassInit()
{
acedRegCmds->addCommand(_T("tmpGroupName"), _T("TestBar"), _T("TestBar"), ACRX_CMD_MODAL, Test);
}
void TestClass::TestClassUnload()
{
acedRegCmds->removeGroup(_T("tmpGroupName"));
}
void TestClass::Test()
{
CAcModuleResourceOverride res; // TODO
CPolaDialogBar* pbar = nullptr;
if (!pbar)
{
AfxSetResourceHandle(_hdllInstance);
pbar = new CPolaDialogBar;
if (!pbar->Create(acedGetAcadFrame(), _T("bar")))
{
TRACE0("Failed to create DlgBar\n");
return; // fail to create
}
AfxSetResourceHandle(acedGetAcadResourceInstance());
pbar->EnableDocking(CBRS_ALIGN_ANY);
acedGetAcadFrame()->DockControlBar(pbar, CBRS_ALIGN_TOP);
pbar->SetWindowText(_T("pbar"));
}
acedGetAcadFrame()->ShowControlBar(pbar, TRUE, FALSE);
acedGetAcadFrame()->RecalcLayout();
AcUiMainWindow()->RedrawWindow();
AdUiShowDockControlBars(true);
}
此贴终结,在这个论坛上找到了答案。
https://forums.codeguru.com/showthread.php?485273-Why-are-my-dialog-bar-buttons-are-disabled
添加 UpdateCmdUI handlers 可以解决
void CPolaDialogBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHandler)
{
// TODO: 在此添加专用代码和/或调用基类
CAdUiDialogBar::OnUpdateCmdUI(pTarget, FALSE);
}
页:
[1]