// 地籍宗地图参数设置
class CDJZDTSetupChildPage : public CXTPPropertyPage;
// 绘制地物参数设置
class CRuoHaiDrawDwSetupChildPage : public CXTPPropertyPage
//////////////////////////////////////////////////////////////////////////
struct DiaLogSetUpTreeNode
{
CString caption;
std::vector<CString> children;
};
class CCategoriesTreeNavigator : public CXTPPropertyPageTreeNavigator
{
public:
// 构造函数,支持传入树视图样式
CCategoriesTreeNavigator(DWORD dwStyle = TVS_SHOWSELALWAYS | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT)
: CXTPPropertyPageTreeNavigator(dwStyle)
{
}
CCategoriesTreeNavigator(const CString& NodeName, DWORD dwStyle = TVS_SHOWSELALWAYS | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT)
: CXTPPropertyPageTreeNavigator(dwStyle)
{
}
CCategoriesTreeNavigator(std::vector<CString> TreeNodes, DWORD dwStyle = TVS_SHOWSELALWAYS | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT)
: CXTPPropertyPageTreeNavigator(dwStyle)
{
}
CCategoriesTreeNavigator(std::vector<DiaLogSetUpTreeNode> TreeNode, DWORD dwStyle = TVS_SHOWSELALWAYS | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT)
: CXTPPropertyPageTreeNavigator(dwStyle)
{
}
/// <summary>
/// 添加单个节点
/// </summary>
/// <param name="NodeName"></param>
/// <returns></returns>
BOOL CreateTree(const CString& NodeName)
{
if (NodeName == _T(""))
{
return FALSE;
}
HTREEITEM hItemOptions = InsertItem(NodeName);
for (int i = 0; i < m_pSheet->GetPageCount(); i++)
{
CXTPPropertyPage* pPage = m_pSheet->GetPage(i);
CString strCaption = pPage->GetCaption();
HTREEITEM hItem = InsertItem(strCaption, -1, -1, hItemOptions);
SetItemData(hItem, (DWORD_PTR)pPage);
pPage->m_dwData = (DWORD_PTR)hItem;
}
return TRUE;
}
BOOL CreateTree(const std::vector<CString>& TreeNodes)
{
if (TreeNodes.size() < 0)
{
return FALSE;
}
ASSERT(m_pSheet->GetPageCount() == TreeNode.size());
for (size_t i = 0; i < TreeNodes.size(); ++i)
{
CString rootName = TreeNodes[i]; // 根节点标题
CreateTree(rootName);
}
return TRUE;
}
/// <summary>
/// 添加多个节点
/// </summary>
/// <param name="TreeNode"></param>
/// <returns></returns>
BOOL CreateTree(const std::vector<DiaLogSetUpTreeNode>& TreeNode)
{
if (TreeNode.size() < 0)
{
return FALSE;
}
ASSERT(m_pSheet->GetPageCount() == TreeNode.size());
for (size_t i = 0; i < TreeNode.size(); ++i)
{
DiaLogSetUpTreeNode element = TreeNode[i]; // 显式声明类型为 std::pair
CString rootName = element.caption; // 根节点标题
std::vector<CString> subNodes = element.children; // 子节点标题
// 插入根节点
HTREEITEM hRoot = InsertItem(rootName);
// 遍历子节点
for (size_t j = 0; j < subNodes.size(); ++j)
{
const CString& subNodeName = subNodes[j]; //
// 插入子节点
HTREEITEM hSubNode = InsertItem(subNodeName, -1, -1, hRoot);
CXTPPropertyPage* pPage = m_pSheet->GetPage(i);
SetItemData(hSubNode, (DWORD_PTR)pPage); // 设置子节点数据
pPage->m_dwData = (DWORD_PTR)hSubNode;
}
}
return TRUE;
}
BOOL CreateTree()
{
CreateTree(TreeNode_);
return TRUE;
}
public:
std::vector<DiaLogSetUpTreeNode> TreeNode_;
};
//////////////////////////////////////////////////////////////////////////
class CDeepMapSetUpPropSheetPaletteWnd : public CXTPCommandBarsSiteBase<CWnd>
{
public:
CDeepMapSetUpPropSheetPaletteWnd();
void SetBshow(bool bshow); //修改成员b_show
bool GetBshow(); //获取成员b_show
static void LoadSetUpPale();
static void UnLoadSetUpPale();
static void RegistrationHotkeysAltAnd6();//注册热键 Alt+6
static void UnRegistrationHotkeysAltAnd6();//卸载arx程序前卸载钩子函数
protected:
DECLARE_DYNCREATE(CDeepMapSetUpPropSheetPaletteWnd)
public:
CCategoriesTreeNavigator* pTreeNavigator_; // 导航器指针
CXTPPropertySheet* pCustomPropSheet_; // 自定义属性表指针
CDJZDTSetupChildPage* mDjzdtChildPage_;
CRuoHaiDrawDwSetupChildPage* mDrawDwChildPage_;
UINT m_nRibbonStyle;
bool isShow_;//是否显示了
// 客户区矩形
CRect rect_;
public:
virtual void OnInitialUpdate();
protected:
virtual ~CDeepMapSetUpPropSheetPaletteWnd();
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual void OnDraw(CDC* pDC);
virtual void PostNcDestroy();
protected:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
// 用于客户区绘制
afx_msg void OnPaint();
// 用于非客户区绘制
afx_msg void OnNcPaint();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnDestroy();
afx_msg void OnSetFocus(CWnd* pOldWnd);
afx_msg void OnClose();
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
// CDeepMapSetUpPropSheetPaletteWnd
IMPLEMENT_DYNCREATE(CDeepMapSetUpPropSheetPaletteWnd, CWnd)
BEGIN_MESSAGE_MAP(CDeepMapSetUpPropSheetPaletteWnd, CWnd)
ON_WM_PAINT()
ON_WM_NCPAINT()
ON_WM_SIZE()
ON_WM_ERASEBKGND()
ON_WM_SETFOCUS()
ON_WM_DESTROY()
ON_WM_CLOSE()
ON_WM_CREATE()
END_MESSAGE_MAP()
CDeepMapSetUpPropSheetPaletteWnd::CDeepMapSetUpPropSheetPaletteWnd()
{
isShow_ = false;
mDrawDwChildPage_ = new CRuoHaiDrawDwSetupChildPage();
mDjzdtChildPage_ = new CDJZDTSetupChildPage();
}
CDeepMapSetUpPropSheetPaletteWnd::~CDeepMapSetUpPropSheetPaletteWnd()
{
}
void CDeepMapSetUpPropSheetPaletteWnd::SetBshow(bool bshow)
{
isShow_ = bshow;
}
bool CDeepMapSetUpPropSheetPaletteWnd::GetBshow()
{
return isShow_;
}
void CDeepMapSetUpPropSheetPaletteWnd::LoadSetUpPale()
{
CRuoHaiFreeReleaseFile* reFile = new CRuoHaiFreeReleaseFile();
reFile->MakeFileOutfromResource();
reFile->MakeGdalFileOutfromResource();
CString strVS2015DLL;
strVS2015DLL = reFile->ThirdPartyPath_;
strVS2015DLL += _T("\\VisualStudio2015.dll");
if (!CHyFile::IsFileExist(strVS2015DLL))
{
//VS2015dllproject->MakeVisualStudioDllFromRes();
AfxMessageBox(strVS2015DLL + _T("文件不存在!"));
}
g_hModuleVisualStudio2015.LoadLibrary(strVS2015DLL);
// TODO: Add your initialization code here
if (g_pSetUpPaneManager == NULL)
{
CRect rect = CRect(0, 0, 420, 300);
CMDIFrameWnd* pAcadFrame = acedGetAcadFrame();
g_pSetUpPaneManager = new CXTPDockingPaneManager;
g_pSetUpPaneManager->InstallDockingPanes(pAcadFrame);
XTPResourceImages()->SetHandle(g_hModuleVisualStudio2015, xtpIniVisualStudio2015Dark);
g_pSetUpPaneManager->SetTheme(xtpPaneThemeVisualStudio2015);
g_pSetUpWndPane = g_pSetUpPaneManager->CreatePane(IDR_PANE, XTP_DPI(rect), xtpPaneDockLeft);
g_pSetUpPaletteWnd = new CDeepMapSetUpPropSheetPaletteWnd;
g_pSetUpPaletteWnd->Create(_T("STATIC"), NULL, WS_CHILD, rect, pAcadFrame, 0);
((CDeepMapSetUpPropSheetPaletteWnd*)g_pSetUpPaletteWnd)->OnInitialUpdate();
g_pSetUpWndPane->Attach(g_pSetUpPaletteWnd);
g_pSetUpWndPane->SetTitle(_T("SETUP"));
// 窗格的布局
CXTPDockingPaneLayout layoutNormal(g_pSetUpPaneManager);
if (layoutNormal.Load(_T("NormalLayout")))
{
g_pSetUpPaneManager->SetLayout(&layoutNormal);
g_pSetUpPaneManager->RecalcFramesLayout();
}
// 拖动窗格时可以停靠的位置
g_pSetUpPaneManager->SetAlphaDockingContext(TRUE);
// 在拖动对接窗格时使用Visual Studio 2005样式对接上下文贴纸
g_pSetUpPaneManager->SetShowDockingContextStickers(TRUE);
g_pSetUpPaneManager->SetShowContentsWhileDragging(TRUE);
// 调用此成员在拖动时设置“显示窗口内容”选项
//pPaneManager->SetDefaultPaneOptions(xtpPaneHasMenuButton);
g_pSetUpPaneManager->SetThemedFloatingFrames(FALSE);
delete reFile;
reFile = NULL;
}
delete reFile;
reFile = NULL;
}
void CDeepMapSetUpPropSheetPaletteWnd::UnLoadSetUpPale()
{
if (g_pSetUpPaletteWnd)
{
delete g_pSetUpPaletteWnd;
g_pSetUpPaletteWnd = NULL;
}
if (g_pSetUpPaneManager)
{
delete g_pSetUpPaneManager;
g_pSetUpPaneManager = NULL;
acedGetAcadFrame()->RecalcLayout();
}
////将焦点放在当前视图
//acedGetAcadDwgView()->SetFocus();
//acDocManager->lockDocument(curDoc());
//acDocManager->sendStringToExecute(curDoc(), _T("UNote "), false, true, false);
//acDocManager->unlockDocument(curDoc());
}
void CDeepMapSetUpPropSheetPaletteWnd::RegistrationHotkeysAltAnd6()
{
if (BRegiHotCtrl6Ok)
{
if (acDocManager->curDocument() != NULL)
{
acutPrintf(_T("\n%s 热键已经注册了。\n"), Str_HOTKEY_ALT_6); //如果钩子已经注册,则返回
}
return;
}
if (acedRegisterWatchWinMsg(WatchAltAnd6) == FALSE)
{
if (acDocManager->curDocument() != NULL)
{
acutPrintf(_T("\n%s 热键注册失败。\n"), Str_HOTKEY_ALT_6); //无法注册钩子
}
}
else
{
if (acDocManager->curDocument() != NULL)
{
acutPrintf(_T("\n%s 热键注册成功,此热键是打开关闭DeepMap停靠面板。\n"), Str_HOTKEY_ALT_6); //快捷命令已经定义
}
BRegiHotCtrl6Ok = true;
}
return;
}
//卸载arx程序前卸载钩子函数
void CDeepMapSetUpPropSheetPaletteWnd::UnRegistrationHotkeysAltAnd6()
{
if (BRegiHotCtrl6Ok == true)
{
acedRemoveWatchWinMsg(WatchAltAnd6);
acutPrintf(_T("\n%s 热键卸载成功。\n"), Str_HOTKEY_ALT_6);
}
}
BOOL CDeepMapSetUpPropSheetPaletteWnd::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
return CWnd::PreCreateWindow(cs);
}
void CDeepMapSetUpPropSheetPaletteWnd::OnDraw(CDC* pDC)
{
}
void CDeepMapSetUpPropSheetPaletteWnd::OnPaint()
{
CPaintDC dc(this);
}
void CDeepMapSetUpPropSheetPaletteWnd::OnNcPaint()
{
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CXTPCommandBarsSiteBase::OnNcPaint()
}
int CDeepMapSetUpPropSheetPaletteWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CAcModuleResourceOverride resourceOverride;
/*if (!mChildDlg.Create(IDD_DrawDwSETUP_DIALOG, this))
{
acedAlert(_T("创建对话框失败!\n"));
return -1;
}
mChildDlg.ShowWindow(SW_SHOW);
mChildDlg.MoveWindow(0, 0, 50, 100, TRUE);*/
if (!mDjzdtChildPage_->CXTPPropertyPage::Create(IDD_DJZDT_SETUP_DIALOG, this))
{
acedAlert(_T("创建对话框失败!\n"));
return -1;
}
mDjzdtChildPage_->ShowWindow(SW_SHOW);
mDjzdtChildPage_->MoveWindow(0, 0, 50, 100, TRUE);
if (!mDrawDwChildPage_->CXTPPropertyPage::Create(IDD_DrawDwSETUP_DIALOG, this))
{
acedAlert(_T("创建对话框失败!\n"));
return -1;
}
mDrawDwChildPage_->ShowWindow(SW_SHOW);
mDrawDwChildPage_->MoveWindow(0, 0, 50, 100, TRUE);
return 0;
}
void CDeepMapSetUpPropSheetPaletteWnd::OnInitialUpdate()
{
// 初始化命令栏
if (!InitCommandBars())
{
TRACE0("初始化命令栏失败!\n");
return;
}
CXTPCommandBars* pCommandBars = GetCommandBars();
if (pCommandBars == NULL)
{
TRACE0("创建命令栏对象失败!\n");
return;
}
CXTPPaintManager::SetTheme(xtpThemeVisualStudio2015);
XTPResourceImages()->SetHandle(g_hModuleVisualStudio2015, xtpIniVisualStudio2015Dark);
pCommandBars->GetCommandBarsOptions()->ShowKeyboardCues(xtpKeyboardCuesShowWindowsDefault);
pCommandBars->GetCommandBarsOptions()->bShowExpandButtonAlways = FALSE;
pCommandBars->GetPaintManager()->m_bAutoResizeIcons = TRUE;
pCommandBars->GetCommandBarsOptions()->SetDPIScallingOptions(TRUE);
LoadCommandBars(_T("CommandBars"));
RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposDefault);
std::vector<CString> TreeNodes;
TreeNodes.push_back(_T("地物绘制设置"));
TreeNodes.push_back(_T("地籍宗地图设置"));
pCustomPropSheet_ = new CXTPPropertySheet(_T("CXTPPropertyPageTreeNavigator Sample"));
pTreeNavigator_ = new CCategoriesTreeNavigator(TreeNodes);
pCustomPropSheet_->SetNavigator(pTreeNavigator_);
pCustomPropSheet_->m_psh.dwFlags |= PSH_NOAPPLYNOW;
pCustomPropSheet_->AddPage(mDjzdtChildPage_);
pCustomPropSheet_->AddPage(mDrawDwChildPage_);
pCustomPropSheet_->SetResizable();
pTreeNavigator_->CreateTree(TreeNodes);
}
void CDeepMapSetUpPropSheetPaletteWnd::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
CRect rcClient(0, 0, cx, cy);
RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, 0, 0, &rcClient);
RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &rcClient, &rcClient);
if (mDrawDwChildPage_->GetSafeHwnd())
{
mDrawDwChildPage_->MoveWindow(rcClient);
}
if (mDjzdtChildPage_->GetSafeHwnd())
{
mDjzdtChildPage_->MoveWindow(rcClient);
}
}
BOOL CDeepMapSetUpPropSheetPaletteWnd::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}
void CDeepMapSetUpPropSheetPaletteWnd::OnSetFocus(CWnd* /*pOldWnd*/)
{
}
void CDeepMapSetUpPropSheetPaletteWnd::OnDestroy()
{
CWnd::OnDestroy();
// TODO: 在此处添加消息处理程序代码
}
void CDeepMapSetUpPropSheetPaletteWnd::OnClose()
{
// Save the current state for command bars.
SaveCommandBars(_T("CommandBars"));
CWnd::OnClose();
}
void CDeepMapSetUpPropSheetPaletteWnd::PostNcDestroy()
{
// TODO: 在此添加专用代码和/或调用基类
CWnd::PostNcDestroy();
}
我想实现树形控件的效果,但是这个代码把两个对话框都Create出来重叠在一起了没有到达树形控件点击切换对话框的效果