• 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的资源。

  • 相关阅读:
    Spring 学习——Spring IOC概念
    Oracle使用——Oracle表空间处理
    Spring 学习——Spring框架结构、概念
    Java错误——The hierarchy of the type is inconsistent错误
    Git教程
    git 常用操作
    "use strict"; 的正确使用
    react学习笔记(二)React表单详解
    chrome 添加有用扩展程序
    react学习笔记(一)
  • 原文地址:https://www.cnblogs.com/meetcomet/p/1588412.html
Copyright © 2020-2023  润新知