- 积分
- 255
- 明经币
- 个
- 注册时间
- 2004-7-27
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2004-8-3 10:56:00
|
显示全部楼层
#include "stdafx.h" #include "BarTest.h"
#include "ToolbarCal.h" #include "ToolbarHandler.h"
#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif
static AFX_EXTENSION_MODULE BarTestDLL = { NULL, NULL };
CToolbarCal *pToolbar; CToolbarHandler *pToolbarHandler;
extern "C" int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { // Remove this if you use lpReserved UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH) { TRACE0("BARTEST.DLL 初始化...\n"); // Extension DLL one-time initialization if (!AfxInitExtensionModule(BarTestDLL, hInstance)) return 0;
// Insert this DLL into the resource chain // NOTE: If this Extension DLL is being implicitly linked to by // an MFC Regular DLL (such as an ActiveX Control) // instead of an MFC application, then you will want to // remove this line from DllMain and put it in a separate // function exported from this Extension DLL. The Regular DLL // that uses this Extension DLL should then explicitly call that // function to initialize this Extension DLL. Otherwise, // the CDynLinkLibrary object will not be attached to the // Regular DLL's resource chain, and serious problems will // result. CTemporaryResourceOverride::SetDefaultResource(hInstance); } else if (dwReason == DLL_PROCESS_DETACH) { TRACE0("BARTEST.DLL 退出...\n"); DeleteBar();
// Terminate the library before destructors are called AfxTermExtensionModule(BarTestDLL); } return 1; // ok }
BOOL InitBarTest() { new CDynLinkLibrary(BarTestDLL); return CreateBar(); }
BOOL CreateBar() { CMDIFrameWnd *pAcadFrame = acedGetAcadFrame();
CTemporaryResourceOverride mrs;
pToolbar = new CToolbarCal; if(!pToolbar){ AfxMessageBox(IDS_ERR_CREATETOOLBAR); return FALSE; }
// Enable AutoCAD's mainframe for docking pAcadFrame->EnableDocking(CBRS_ALIGN_ANY); // need this step to force some MFC initialization pAcadFrame->RecalcLayout();
BOOL s1 = pToolbar->CreateEx(pAcadFrame,TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_SIZE_DYNAMIC | CBRS_FLYBY | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS);
if(!s1){ AfxMessageBox(IDS_ERR_CREATETOOLBAR); delete pToolbar; pToolbar = NULL; return FALSE; }
pToolbar->SetBorders(5,2,5,2); BOOL s2 = pToolbar->LoadToolBar(IDR_TOOLBAR_DEBUG);
if(!s2){ AfxMessageBox(IDS_ERR_CREATETOOLBAR); delete pToolbar; pToolbar = NULL; return FALSE; }
// create toolbar handler pToolbarHandler = new CToolbarHandler;
if(!pToolbarHandler){ AfxMessageBox(IDS_ERR_CREATETOOLBAR); delete pToolbar; pToolbar = NULL; return FALSE; }
BOOL s3 = pToolbarHandler->Create(NULL, NULL, WS_CHILD, //| WS_MINIMIZE, CRect(0,0,1,1), pAcadFrame, IDW_TOOLBARHANDLER); if(!s3){ AfxMessageBox(IDS_ERR_CREATETOOLBAR); delete pToolbarHandler; pToolbarHandler = NULL; delete pToolbar; pToolbar = NULL; return FALSE; }
CString s; s.LoadString(IDS_STR_TOOLBARTITLE); pToolbar->SetWindowText(s); pToolbar->EnableDocking(CBRS_ALIGN_ANY); CToolBarCtrl *pTbc=&pToolbar->GetToolBarCtrl(); pTbc->SetOwner(pToolbarHandler); // pTbc->RestoreState(m_regkey, "辅助制图", "ToolBar"); // pTbc->EnableButton(ID_PGDM); pAcadFrame->DockControlBar(pToolbar, AFX_IDW_DOCKBAR_TOP, CRect(500,300,600,400)); pAcadFrame->ShowControlBar(pToolbar, TRUE, TRUE); pAcadFrame->FloatControlBar(pToolbar,CPoint(600,80));
return TRUE; }
void DeleteBar() { if ( pToolbar ) delete pToolbar; if ( pToolbarHandler ) delete pToolbarHandler; } |
|