- UID
- 3272
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-3-23
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
各位好:
我在CAD中做了一个类VC的窗口,想动态的增加树控件的项目,很久没搞定,
左边是三个树视图,加在Tab中,用对话框更新树视,但没效果。
此类是一个视类。
// ManProjectVw1.cpp : implementation file
//
#include "StdAfx.h"
#include "resource.h"
#include "ManProjectVw1.h"
#include "ManProjectDlg.h"
#include "TreeDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CManProjectVw1
IMPLEMENT_DYNCREATE(CManProjectVw1, CTreeView)
CManProjectVw1::CManProjectVw1()
{
}
CManProjectVw1::~CManProjectVw1()
{
}
BEGIN_MESSAGE_MAP(CManProjectVw1, CTreeView)
//{{AFX_MSG_MAP(CManProjectVw1)
ON_NOTIFY_REFLECT(TVN_SELCHANGING, OnSelchanging)
ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnItemexpanding)
ON_WM_CREATE()
ON_BN_DOUBLECLICKED(IDOK, OnDoubleclickedOk)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CManProjectVw1 drawing
void CManProjectVw1::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
ASSERT_VALID(pDoc);
}
/////////////////////////////////////////////////////////////////////////////
// CManProjectVw1 diagnostics
#ifdef _DEBUG
void CManProjectVw1::AssertValid() const
{
CTreeView::AssertValid();
}
void CManProjectVw1::Dump(CDumpContext& dc) const
{
CTreeView::Dump(dc);
}
CTreeDoc* CManProjectVw1::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTreeDoc)));
return (CTreeDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CManProjectVw1 message handlers
void CManProjectVw1::OnSelchanging(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CManProjectVw1::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CManProjectVw1::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
int CManProjectVw1::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CTreeView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_TreeCtrl = &GetTreeCtrl();
// Create the image list for the tree control
m_ImageList.Create (IDB_BITMAP5, 16, 1, RGB(0,255,0));
m_TreeCtrl->SetImageList (&m_ImageList, TVSIL_NORMAL);
// Add the parent item
// HTREEITEM htItem = m_TreeCtrl->InsertItem(csTree[0]);
// m_TreeCtrl->SetItemState( htItem, TVIS_BOLD, TVIS_BOLD );
// Add children
for( int i = 1; i < 8; i++ ) {
// m_TreeCtrl->InsertItem (csTree[1], 1, 1, htItem, TVI_LAST);
}
// Add children
// m_TreeCtrl->InsertItem (csTree[2], 2, 3, htItem, TVI_LAST);
// m_TreeCtrl->Expand(htItem, TVE_EXPAND);
return 0;
}
BOOL CManProjectVw1::PreCreateWindow(CREATESTRUCT& cs)
{
cs.style |= TVS_HASBUTTONS | TVS_HASLINES |
TVS_LINESATROOT;
return CTreeView::PreCreateWindow(cs);
}
void CManProjectVw1::OnDoubleclickedOk()
{
CManProjectDlg dlg;
CTreeCtrl& theCtrl = GetTreeCtrl();
dlg.m_pTreeCtrl = &theCtrl;
if (dlg.DoModal() == IDOK)
{
//SAMPLE: the dialog has modified our content directly,
// but it's up to us to set the dirty flag
GetDocument()->SetModifiedFlag();
}
}
void CManProjectVw1::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
}
下面是一个对话框类:我用对话框类更新树项目
//-----------------------------------------------------------------------------
//----- ManProjectDlg.cpp : implementation file
#include "StdAfx.h"
#include "resource.h"
#include "ManProjectDlg.h"
#include "DockBar.h"
#include "ManProjectVw1.h"
#include "TreeDoc.h"
//-----------------------------------------------------------------------------
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
class CTreeDoc;
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC (CManProjectDlg, CAcUiDialog)
BEGIN_MESSAGE_MAP(CManProjectDlg, CAcUiDialog)
//{{AFX_MSG_MAP(CManProjectDlg)
ON_MESSAGE(WM_ACAD_KEEPFOCUS, OnAcadKeepFocus) // Needed for modeless dialog.
ON_BN_CLICKED(IDC_SAVE, OnSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//-----------------------------------------------------------------------------
CManProjectDlg::CManProjectDlg (CWnd* pParent /*=NULL*/, HINSTANCE hInstance /*=NULL*/) : CAcUiDialog (CManProjectDlg::IDD, pParent, hInstance) {
//{{AFX_DATA_INIT(CManProjectDlg)
m_ProjectName = _T("");
m_MaoKouStyle = _T("");
//}}AFX_DATA_INIT
}
void CManProjectDlg::DoDataExchange (CDataExchange *pDX) {
CAcUiDialog::DoDataExchange (pDX) ;
//{{AFX_DATA_MAP(CManProjectDlg)
DDX_Text(pDX, IDC_MAOKOUGESHUEDIT2, m_ProjectName);
DDX_Text(pDX, IDC_MAOKOUSTYLEEDIT3, m_MaoKouStyle);
//}}AFX_DATA_MAP
}
// Needed for modeless dialogs to keep focus.
// Return FALSE to not keep the focus, return TRUE to keep the focus
LONG CManProjectDlg::OnAcadKeepFocus(UINT, UINT)
{
return TRUE;
}
//-----------------------------------------------------------------------------
void CManProjectDlg::OnOK()
{
CAcModuleResourceOverride resOverride;
UpdateData(TRUE);
ASSERT(m_cTree!=NULL);
HTREEITEM hSelected=m_pTreeCtrl->GetSelectedItem();
CString str;
GetDlgItemText(IDC_PROJECTEDIT1, str);
HTREEITEM hParent =m_pTreeCtrl->GetParentItem(hSelected);
if (hParent == NULL)
hParent = TVI_ROOT;
//SAMPLE: insert at root
m_pTreeCtrl->InsertItem(str,TVI_ROOT,m_nInsertMethod);
CAcUiDialog::OnOK();
}
void CManProjectDlg::OnSave()
{
}
BOOL CManProjectDlg::OnInitDialog()
{
CAcUiDialog::OnInitDialog();
//SAMPLE: we'd better have an associated tree control!
ASSERT(m_cTree != NULL);
//SAMPLE: what's selected in our control?
HTREEITEM hSelected = m_pTreeCtrl->GetSelectedItem();
//SAMPLE: if nothing, must insert at root
// otherwise, it's the user's choice.
if (hSelected == NULL)
{
m_nInsertMethod = TVI_ROOT;
}
CAcUiDialog::OnInitDialog();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
下面是程序入口:
// 材料成型CAD项目管理.cpp : Initialization functions
#include "StdAfx.h"
#include "StdArx.h"
#include "resource.h"
#include <afxdllx.h>
#include "DockBar.h"
#include <migrtion.h>
#include <dbapserv.h>
#include <Afxext.h>
#include "ManProjectVw1.h"
#include "ManProjectVw2.h"
#include "ManProjectVw3.h"
#include "CJTabCtrlBar.h"
#include "MyTree.h"
void DeleteSampToolBar();
void CreateLeftView();
CCJTabCtrlBar* m_wndWorkspace;
CImageList m_ImageList;
CImageList m_TabImages;
HINSTANCE _hdllInstance =NULL ;
// This command registers an ARX command.
void AddCommand(const char* cmdGroup, const char* cmdInt, const char* cmdLoc,
const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal = -1);
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_MSG
void InitApplication();
void UnloadApplication();
//}}AFX_ARX_MSG
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_ADDIN_FUNCS
//}}AFX_ARX_ADDIN_FUNCS
////////////////////////////////////////////////////////////////////////////
//
// Define the sole extension module object.
AC_IMPLEMENT_EXTENSION_MODULE(CADDLL);
// Now you can use the CAcModuleRecourceOverride class in
// your application to switch to the correct resource instance.
// Please see the ObjectARX Documentation for more details
/////////////////////////////////////////////////////////////////////////////
// DLL Entry Point
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
_hdllInstance = hInstance;
// Extension DLL one time initialization
CADDLL.AttachInstance(hInstance);
InitAcUiDLL();
CreateLeftView();
} else if (dwReason == DLL_PROCESS_DETACH) {
// Terminate the library before destructors are called
CADDLL.DetachInstance();
DeleteSampToolBar();
}
return TRUE; // ok
}
/////////////////////////////////////////////////////////////////////////////
// ObjectARX EntryPoint
extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
{
switch (msg) {
case AcRx::kInitAppMsg:
// Comment out the following line if your
// application should be locked into memory
acrxDynamicLinker->unlockApplication(pkt);
acrxDynamicLinker->registerAppMDIAware(pkt);
InitApplication();
break;
case AcRx::kUnloadAppMsg:
UnloadApplication();
break;
}
return AcRx::kRetOK;
}
// Init this application. Register your
// commands, reactors...
void InitApplication()
{
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_INIT
AddCommand("CADMFCTEST", "MANPROJECT", "MANPROJECT", ACRX_CMD_TRANSPARENT | ACRX_CMD_USEPICKSET, cadMfcTestManProject);
//}}AFX_ARX_INIT
// TODO: add your initialization functions
}
// Unload this application. Unregister all objects
// registered in InitApplication.
void UnloadApplication()
{
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_EXIT
acedRegCmds->removeGroup("CADMFCTEST");
//}}AFX_ARX_EXIT
// TODO: clean up your application
}
// This functions registers an ARX command.
// It can be used to read the localized command name
// from a string table stored in the resources.
void AddCommand(const char* cmdGroup, const char* cmdInt, const char* cmdLoc,
const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal)
{
char cmdLocRes[65];
// If idLocal is not -1, it's treated as an ID for
// a string stored in the resources.
if (idLocal != -1) {
// Load strings from the string table and register the command.
::LoadString(_hdllInstance, idLocal, cmdLocRes, 64);
acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLocRes, cmdFlags, cmdProc);
} else
// idLocal is -1, so the 'hard coded'
// localized function name is used.
acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLoc, cmdFlags, cmdProc);
}
void CreateLeftView()
{
InitCommonControls();
CMDIFrameWnd* pFrame=acedGetAcadFrame();
AfxSetResourceHandle(_hdllInstance);
// Create the image list to be used with the control bars.
m_ImageList.Create(IDB_BITMAP2, 13, 1, RGB(0,255,0));
// CG: The following block was inserted by the 'Dialog Bar' component
m_wndWorkspace=new CCJTabCtrlBar();
m_wndWorkspace->SetBtnImageList (&m_ImageList);
m_wndWorkspace->SetMenuID(IDR_POPUP);
// Initialize dialog bar m_wndWorkspace
if (!m_wndWorkspace->Create(pFrame, ID_LEFTVIEW,
_T("Workspace"), CSize(220,200)))
{
TRACE0("Failed to create dialog bar m_wndWorkspace\n");
}
m_wndWorkspace->AddView(_T("图纸管理"), RUNTIME_CLASS(CManProjectVw1));
m_wndWorkspace->AddView(_T("数据库管理"), RUNTIME_CLASS(CManProjectVw2));
m_wndWorkspace->AddView(_T("计算管理"), RUNTIME_CLASS(CManProjectVw3));
// Define the image list to use with the tab control
m_TabImages.Create (IDB_BITMAP4, 16, 1, RGB(0,255,0));
m_wndWorkspace->SetTabImageList(&m_TabImages);
// allow bar to be resized when floating
m_wndWorkspace->SetBarStyle(m_wndWorkspace->GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
m_wndWorkspace->EnableDocking(CBRS_ALIGN_ANY);
pFrame->EnableDocking(CBRS_ALIGN_ANY);
pFrame->DockControlBar(m_wndWorkspace, AFX_IDW_DOCKBAR_LEFT);
pFrame->ShowControlBar(m_wndWorkspace, TRUE, TRUE);
pFrame->RecalcLayout();
}
// clean up
void DeleteSampToolBar()
{
if(m_wndWorkspace)
{
delete m_wndWorkspace;
m_wndWorkspace= NULL;
}
if(acedGetAcadFrame()->m_hWnd && acdbCurDwg())
acedGetAcadFrame()->RecalcLayout();
} |
|