找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 2140|回复: 6

[ARX程序]:求救VC&&ARX高手!!看看我的代码!!

[复制链接]
发表于 2002-5-10 09:17:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

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

×
各位好:
    我在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();
}
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
发表于 2002-5-12 00:53:14 | 显示全部楼层
CManProjectVw1没问题,问题出在CManProjectDlg
估计是你在CManProjectDlg中对m_pTreeCtrl的操作不对, 你把ManProjectDlg.h及CManProjectDlg.cpp完整的贴出来.
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2002-5-12 02:37:00 | 显示全部楼层
下面的附件是一完整的Project
演示了如何手工创建TreeCtrl以及如何通过Dialog向TreeCtrl添加节点
没有用CJ60Lib,也没有用到CTabCtrl.
对Arx应用界面改善感兴趣的朋友或许会从中得到一些技巧,特别是对CAcUiDockControlBar感兴趣的朋友.c:\capture.jpg
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2002-5-12 07:27:37 | 显示全部楼层
是不是DWG文档锁定的问题,你的代码实在太长了,没有看完!对不起!!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2002-5-26 02:12:42 | 显示全部楼层
a possible way to it
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2002-12-17 09:02:32 | 显示全部楼层
文件已坏
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

发表于 2003-10-22 22:44:19 | 显示全部楼层
我也要做类似的东西
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-9-21 05:50 , Processed in 0.260869 second(s), 43 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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