NX二次开发源码分享:NX10可以直接对资源条进行二次开发
NX二次开发源码分享:NX10可以直接对资源条进行二次开发
这是官方的一个例子,新建了一个资源条,使用MFC的Tree创建了树列表,并加载了所有组件的属性到节点上。
// Mandatory UF Includes
#include <uf.h>
// NXOpen Includes
#include <NXOpen/Assemblies_Component.hxx>
#include <NXOpen/Assemblies_ComponentAssembly.hxx>
#include <NXOpen/ListingWindow.hxx>
#include <NXOpen/LogFile.hxx>
#include <NXOpen/NXMessageBox.hxx>
#include <NXOpen/NXException.hxx>
#include <NXOpen/NXObject.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/ResourceBarManager.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/UI.hxx>
using namespace NXOpen;
using namespace NXOpen::Assemblies;
// Std C++ Includes
#include <iostream>
#include <sstream>
#include <map>
using std::exception;
using std::endl;
using std::cout;
using std::cerr;
// MFC Includes
#define _WIN32_WINNT 0x06010000
#include <afxwin.h>
#include <afxcmn.h>
#define IDC_TREE1 1002
//------------------------------------------------------------------------------
// NXOpen C++ class
//------------------------------------------------------------------------------
class MyClass
{
// class members
public:
static Session *theSession;
static UI *theUI;
static int m_tab;
static int m_cbID;
MyClass();
~MyClass();
void print(const NXString &);
void log(const NXString &);
void getAttributes(Component *, HTREEITEM);
void getComponents(Component *, HTREEITEM);
int ActivationHandler1(int tab_id);
void Clear();
void Populate(BasePart*);
void cbPartOpened(BasePart*);
void cbPartClosed(BasePart*);
private:
Part *workPart, *displayPart;
NXMessageBox *mb;
ListingWindow *listW;
LogFile *logF;
CTreeCtrl *m_tree;
CImageList m_Images;
};
//------------------------------------------------------------------------------
// Initialize static variables
//------------------------------------------------------------------------------
Session *(MyClass::theSession) = nullptr;
UI *(MyClass::theUI) = nullptr;
int MyClass::m_tab = 0;
int MyClass::m_cbID = {0,0};
MyClass *theApp = nullptr;
//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
MyClass::MyClass()
{
logF->WriteLine("GTAC: MyClass Constructor");
theSession = NXOpen::Session::GetSession();
theUI = UI::GetUI();
mb = theUI->NXMessageBox();
listW = theSession->ListingWindow();
logF = theSession->LogFile();
workPart = theSession->;Parts()->Work();
displayPart = theSession->;Parts()->Display();
m_tree = new CTreeCtrl();
BOOL bSuccess = m_Images.Create(16, 16, ILC_COLOR32, 0, 2);
int index = m_Images.Add( AfxGetApp()->LoadStandardIcon(IDI_WINLOGO) );
index = m_Images.Add( AfxGetApp()->LoadStandardIcon(IDI_INFORMATION) );
m_tab = theUI->ResourceBarManager()->ResourceBarManager::Create("Assembly Attributes", "ant_component_mode");
theUI->ResourceBarManager()->ResourceBarManager::RegisterActivationCallback(m_tab,
make_callback(this, &MyClass::ActivationHandler1));
theUI->ResourceBarManager()->ResourceBarManager::ActivateTab(m_tab);
m_cbID = theSession->;Parts()->AddPartOpenedHandler(make_callback(this, &MyClass::cbPartOpened));
m_cbID = theSession->;Parts()->AddPartClosedHandler(make_callback(this, &MyClass::cbPartClosed));
}
//------------------------------------------------------------------------------
// Destructor
//------------------------------------------------------------------------------
MyClass::~MyClass()
{
logF->WriteLine("GTAC: MyClass Destructor");
if( m_tree->GetSafeHwnd() )
{
BOOL bSuccess = m_tree->DestroyWindow();
}
theUI->ResourceBarManager()->Destroy(theApp->m_tab);
theSession->;Parts()->RemovePartOpenedHandler(m_cbID);
theSession->;Parts()->RemovePartClosedHandler(m_cbID);
}
//------------------------------------------------------------------------------
// Print string to listing window and/or syslog
//------------------------------------------------------------------------------
void MyClass::print(const NXString &msg)
{
if(! listW->IsOpen() ) listW->Open();
listW->WriteLine(msg);
}
void MyClass::log(const NXString &msg)
{
logF->WriteLine(msg);
}
// Callback triggered when opening resource bar tab
int MyClass::ActivationHandler1(int tab_id)
{
// Get the WindowHandle object
WindowHandle *window_handle = MyClass::theUI->ResourceBarManager()->GetWindowHandle(tab_id);
// Get the real handle
HWND parent_handle = (HWND)window_handle->GetHandle();
// Get the CWnd object from HWND, FromHandlePermanent will return 0!
CWnd *wParent1 = CWnd::FromHandle(parent_handle);
ASSERT(wParent1);
// Switch module state to avoid Assertion from afxCurrentInstanceHandle
AFX_MANAGE_STATE(AfxGetStaticModuleState());
BOOL bSuccess = m_tree->Create(WS_CHILD|WS_VISIBLE|WS_BORDER|TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT|TVS_TRACKSELECT,
CRect(10,50,510,1810), wParent1, IDC_TREE1);
m_tree->SetImageList(&m_Images, TVSIL_NORMAL);
Populate(displayPart);
return 0;
}
//------------------------------------------------------------------------------
// getAttributes
//------------------------------------------------------------------------------
**** Hidden Message *****
二次开发完全不会啊 我想看看,进来 好难学啊:'( 看看,这个好像很牛的样子! 谢谢高手的分享哈 学习学习学习 ddddddddddddddddddd 学习学习:) 卡看看 阿发撒旦法撒旦法