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