xiaotina 发表于 2004-8-3 10:56:00

#include "stdafx.h"<BR>#include "BarTest.h"


#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-&gt;EnableDocking(CBRS_ALIGN_ANY);<BR>        // need this step to force some MFC initialization<BR>        pAcadFrame-&gt;RecalcLayout();


        BOOL s1 = pToolbar-&gt;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-&gt;SetBorders(5,2,5,2);<BR>        BOOL s2 = pToolbar-&gt;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-&gt;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-&gt;SetWindowText(s);<BR>        pToolbar-&gt;EnableDocking(CBRS_ALIGN_ANY);<BR>        CToolBarCtrl *pTbc=&amp;pToolbar-&gt;GetToolBarCtrl();<BR>        pTbc-&gt;SetOwner(pToolbarHandler);<BR>//        pTbc-&gt;RestoreState(m_regkey, "辅助制图", "ToolBar");<BR>//        pTbc-&gt;EnableButton(ID_PGDM);<BR>        pAcadFrame-&gt;DockControlBar(pToolbar, AFX_IDW_DOCKBAR_TOP, CRect(500,300,600,400));<BR>        pAcadFrame-&gt;ShowControlBar(pToolbar, TRUE, TRUE);<BR>        pAcadFrame-&gt;FloatControlBar(pToolbar,CPoint(600,80));


        return TRUE;<BR>}


void DeleteBar()<BR>{<BR>        if ( pToolbar )<BR>                delete pToolbar;<BR>        if ( pToolbarHandler )<BR>                delete pToolbarHandler;<BR>}

xiaotina 发表于 2004-8-3 12:49:00

再试一次
页: 1 [2]
查看完整版本: 急,求救:AutoCad框架上停靠工具条遇到问题