📄 tabbedviews.cpp
字号:
// TabbedViews.cpp : Initialization functions
#include "StdAfx.h"
#include "StdArx.h"
#include "resource.h"
#include <afxdllx.h>
#include "WindowManager.h"
//-----------------------------------------------------------------------------
#define szRDS _RXST("")
//-----------------------------------------------------------------------------
class AcApDataManager;
//-----------------------------------------------------------------------------
CViewManager* g_pViewManager = NULL;
AcApDataManager* g_pDocReactor = NULL;
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);
static void AddAllOpenedDocViews();
static void AddOrRemoveTabViewsBar(void);
// 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(TabbedViewsDLL);
// Now you can use the CAcModuleResourceOverride 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
TabbedViewsDLL.AttachInstance(hInstance);
InitAcUiDLL();
} else if (dwReason == DLL_PROCESS_DETACH) {
// Terminate the library before destructors are called
TabbedViewsDLL.DetachInstance();
}
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;
}
//----- AsdkDataManager
class AcApDataManager : public AcApDocManagerReactor
{
public:
AcApDataManager()
{
m_pView = NULL;
acDocManager -> addReactor(this);
}
~AcApDataManager()
{
acDocManager -> removeReactor(this);
}
virtual void documentCreated(AcApDocument *pDoc)
{
CDocument *pDocument = pDoc -> cDoc();
if( pDocument == NULL ) return;
// struct resbuf buf;
// buf.restype = RTSTR;
// acedGetVar("DWGNAME", &buf);
// pDocument -> SetTitle(buf.resval.rstring);
POSITION pos = pDocument -> GetFirstViewPosition();
while (pos != NULL)
{
CView* pView = pDocument -> GetNextView( pos );
pView -> UpdateWindow( );
g_pViewManager -> AddView(_T(" "), static_cast<CView*>(pView));
}
}
virtual void documentActivated(AcApDocument *pDoc)
{
CDocument *pDocument = pDoc -> cDoc();
if( pDocument == NULL ) return;
POSITION pos = pDocument -> GetFirstViewPosition( );
if (pos != NULL)
m_pView = pDocument -> GetNextView( pos );
}
virtual void documentToBeDestroyed(AcApDocument *pDoc)
{
if( m_pView != NULL )
g_pViewManager -> RemoveView( m_pView );
m_pView = NULL;
}
private:
CView* m_pView;
};
// Init this application. Register your
// commands, reactors...
void InitApplication()
{
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_INIT
//}}AFX_ARX_INIT
// TODO: add your initialization functions
CMDIFrameWnd* pAcadFrame = acedGetAcadFrame();
AddOrRemoveTabViewsBar();
if( g_pDocReactor == NULL )
g_pDocReactor = new AcApDataManager();
}
// Unload this application. Unregister all objects
// registered in InitApplication.
void UnloadApplication()
{
// NOTE: DO NOT edit the following lines.
//{{AFX_ARX_EXIT
//}}AFX_ARX_EXIT
// TODO: clean up your application
if( g_pDocReactor != NULL )
delete g_pDocReactor;
AddOrRemoveTabViewsBar();
}
// 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);
}
static void AddAllOpenedDocViews()
{
AcApDocument* pDoc;
CDocument *pDocument;
AcApDocumentIterator* pDocIter;
pDocIter = acDocManager -> newAcApDocumentIterator();
for ( ; !pDocIter -> done(); pDocIter -> step()){
pDoc = pDocIter -> document();
pDocument = pDoc -> cDoc();
POSITION pos = pDocument -> GetFirstViewPosition();
while (pos != NULL)
{
CView* pView = pDocument -> GetNextView(pos);
pView -> UpdateWindow();
g_pViewManager -> AddView(_T(" "), static_cast<CView*>(pView));
}
}
}
// ----- Asdk_TabbedViews.TabBar command (do not rename)
static void AddOrRemoveTabViewsBar(void)
{
// Add your code for command Asdk_TabbedViews.TabBar here
CMDIFrameWnd *pAcadFrame = acedGetAcadFrame();
if ( g_pViewManager == NULL ){
g_pViewManager = new CViewManager;
// g_pViewManager -> CreateViewManager(pAcadFrame, ID_VIEW_VIEWTAB);
CMDIClient pMDIClient;
pMDIClient.SubclassMDIClient(pAcadFrame, g_pViewManager);
AddAllOpenedDocViews();
}
else{
g_pViewManager -> DestroyWindow();
delete g_pViewManager;
g_pViewManager = NULL;
//在这里应该让主pAcadFrame 刷新的,找不到有效函数
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -