zoukankan      html  css  js  c++  java
  • Dll 学习3 将MDI子窗口封装在DLL中

    结果没有任何高深的技巧,难怪搜遍GOOGLE没有任何有用信息。哎…

    要注意的事项:1.资源的ID尽量不要和主文件重名 2.如果用正规的DLL,注意AFX_MANAGE_STATE(AfxGetStaticModuleState());(见DLL学习1)

    我用的是MFC扩展DLL。

    主程序中菜单相关项:

    void CMainFrame::OnTestDll()
    {
        // TODO: Add your command handler code here
            MessageBox("OK");
        typedef CMDIChildWnd * (*pFunc)(int, bool, CString,CString, CString);//type define a pointer of the function which has a int
                                    //return value and void parameter list.
        hModule=LoadLibrary("FormDll1.dll");//load the dymanic linked libraray
        pFunc pDisplay =(pFunc) GetProcAddress(hModule,"Display");//get the pointer to the function
        (pDisplay)(1, !(77), "1234","D:\\素材","D:\\Save");//invoke the function

    }

    DLL:

    #include "stdafx.h"
    #include <afxdllx.h>
    #include "global.h"
    #include "Resource.h"
    #include "MyDocument.h"
    #include "DeskChildFrame.h"
    #include "MyFormView.h"

    ……

    extern "C" __declspec(dllexport) CMDIChildWnd *  Display(int, bool, CString, CString, CString);
    CMDIChildWnd * Display(int nCode, bool First, CString Confirm, CString ReadPath, CString SavePath)
    {
        g_nCode = nCode;
        g_Confirm = Confirm;
        g_bFirst = First;
        g_ReadPath = ReadPath;
        g_SavePath = SavePath;

        CMultiDocTemplate * pDocTemplate;
        pDocTemplate = new CMultiDocTemplate(
            IDR_WordDll_ICON,
            RUNTIME_CLASS(CMyDocument),
            RUNTIME_CLASS(CDeskChildFrame), // custom MDI child frame
            RUNTIME_CLASS(CMyFormView));
        CString str = "dll测试";
        CDocument* pDoc = pDocTemplate->CreateNewDocument();
        CDeskChildFrame * pFrame = (CDeskChildFrame *)pDocTemplate->CreateNewFrame(pDoc, NULL);
        pDoc->SetTitle(str);
           pDocTemplate->InitialUpdateFrame(pFrame, pDoc);
        return pFrame;
    }

    其中CMyFormView中有一个Formview的资源。

  • 相关阅读:
    列举些个建模软件及其crack方法
    解除Server2008远程桌面管理重重关卡
    VMware运行报错
    当下流行的分布式文件系统大阅兵
    Tomcat的目录结构详解
    从Windows Server文件服务到分布式文件服务
    cloudfoundry
    动态磁盘&动态卷
    管理日志(1):为什么要开会
    C# 面试题目 destructor可以是虚方法吗?
  • 原文地址:https://www.cnblogs.com/meetcomet/p/1588412.html
Copyright © 2011-2022 走看看