⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 在mfc扩展dll中输出对话框.htm

📁 我在网上收集的一些有关vcDLL编程的文章。
💻 HTM
字号:
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:st1="urn:schemas-microsoft-com:office:smarttags"
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 11">
<meta name=Originator content="Microsoft Word 11">
<link rel=File-List href="在MFC扩展DLL中输出对话框.files/filelist.xml">
<link rel=Edit-Time-Data href="在MFC扩展DLL中输出对话框.files/editdata.mso">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<title>在MFC扩展DLL中输出对话框</title>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
 name="chsdate" downloadurl=""/>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>pop</o:Author>
  <o:LastAuthor>pop</o:LastAuthor>
  <o:Revision>1</o:Revision>
  <o:TotalTime>0</o:TotalTime>
  <o:Created>2006-04-11T12:42:00Z</o:Created>
  <o:LastSaved>2006-04-11T12:42:00Z</o:LastSaved>
  <o:Pages>1</o:Pages>
  <o:Words>355</o:Words>
  <o:Characters>2029</o:Characters>
  <o:Company>baodi</o:Company>
  <o:Lines>16</o:Lines>
  <o:Paragraphs>4</o:Paragraphs>
  <o:CharactersWithSpaces>2380</o:CharactersWithSpaces>
  <o:Version>11.5606</o:Version>
 </o:DocumentProperties>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:WordDocument>
  <w:SpellingState>Clean</w:SpellingState>
  <w:GrammarState>Clean</w:GrammarState>
  <w:PunctuationKerning/>
  <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
  <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
  <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
  <w:ValidateAgainstSchemas/>
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent>
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
  <w:Compatibility>
   <w:SpaceForUL/>
   <w:BalanceSingleByteDoubleByteWidth/>
   <w:DoNotLeaveBackslashAlone/>
   <w:ULTrailSpace/>
   <w:DoNotExpandShiftReturn/>
   <w:AdjustLineHeightInTable/>
   <w:BreakWrappedTables/>
   <w:SnapToGridInCell/>
   <w:WrapTextWithPunct/>
   <w:UseAsianBreakRules/>
   <w:DontGrowAutofit/>
   <w:UseFELayout/>
  </w:Compatibility>
  <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
 </w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
 <w:LatentStyles DefLockedState="false" LatentStyleCount="156">
 </w:LatentStyles>
</xml><![endif]--><!--[if !mso]><object
 classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id=ieooui></object>
<style>
st1\:*{behavior:url(#ieooui) }
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:宋体;
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-alt:SimSun;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
	{font-family:"\@宋体";
	panose-1:2 1 6 0 3 1 1 1 1 1;
	mso-font-charset:134;
	mso-generic-font-family:auto;
	mso-font-pitch:variable;
	mso-font-signature:3 135135232 16 0 262145 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{mso-style-parent:"";
	margin:0cm;
	margin-bottom:.0001pt;
	text-align:justify;
	text-justify:inter-ideograph;
	mso-pagination:none;
	font-size:10.5pt;
	mso-bidi-font-size:12.0pt;
	font-family:"Times New Roman";
	mso-fareast-font-family:宋体;
	mso-font-kerning:1.0pt;}
span.SpellE
	{mso-style-name:"";
	mso-spl-e:yes;}
span.GramE
	{mso-style-name:"";
	mso-gram-e:yes;}
 /* Page Definitions */
 @page
	{mso-page-border-surround-header:no;
	mso-page-border-surround-footer:no;}
@page Section1
	{size:595.3pt 841.9pt;
	margin:72.0pt 90.0pt 72.0pt 90.0pt;
	mso-header-margin:42.55pt;
	mso-footer-margin:49.6pt;
	mso-paper-source:0;
	layout-grid:15.6pt;}
div.Section1
	{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
 /* Style Definitions */
 table.MsoNormalTable
	{mso-style-name:普通表格;
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-parent:"";
	mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
	mso-para-margin:0cm;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman";
	mso-ansi-language:#0400;
	mso-fareast-language:#0400;
	mso-bidi-language:#0400;}
</style>
<![endif]-->
</head>

<body lang=ZH-CN style='tab-interval:21.0pt;text-justify-trim:punctuation'>

<div class=Section1 style='layout-grid:15.6pt'>

<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width="100%"
 style='width:100.0%;mso-cellspacing:0cm;mso-padding-alt:0cm 0cm 0cm 0cm'>
 <tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes;height:30.0pt'>
  <td style='padding:0cm 0cm 0cm 0cm;height:30.0pt'>
  <p class=MsoNormal align=center style='text-align:center;mso-pagination:widow-orphan'><b><span
  style='font-size:12.0pt;font-family:宋体;mso-bidi-font-family:宋体;mso-font-kerning:
  0pt'>在<span lang=EN-US>MFC</span>扩展<span lang=EN-US>DLL</span>中输出对话框</span></b><span
  lang=EN-US style='font-size:9.0pt;font-family:宋体;mso-bidi-font-family:宋体;
  mso-font-kerning:0pt'><o:p></o:p></span></p>
  </td>
 </tr>
 <tr style='mso-yfti-irow:1;mso-yfti-lastrow:yes;height:18.75pt'>
  <td style='border:none;border-bottom:solid windowtext 1.5pt;padding:0cm 0cm 0cm 0cm;
  height:18.75pt'>
  <p class=MsoNormal align=center style='text-align:center;mso-pagination:widow-orphan'><span
  style='font-size:9.0pt;font-family:宋体;mso-bidi-font-family:宋体;mso-font-kerning:
  0pt'>【文章出处:转载】<span lang=EN-US>&nbsp;</span>【作者:未知】<span lang=EN-US>&nbsp;</span>【发布时间:<st1:chsdate
  Year="2005" Month="1" Day="25" IsLunarDate="False" IsROCDate="False" w:st="on"><span
   lang=EN-US>2005-01-25</span></st1:chsdate>】<span lang=EN-US>&nbsp;</span>【查看:
  <span lang=EN-US><script language="JavaScript"  src="/php/count.php?artID=10760&view=yes">
  </script>17</span>次】 <span lang=EN-US><o:p></o:p></span></span></p>
  </td>
 </tr>
</table>

<p class=MsoNormal align=left style='text-align:left;mso-pagination:widow-orphan'><span
lang=EN-US style='font-size:9.0pt;font-family:宋体;mso-bidi-font-family:宋体;
display:none;mso-hide:all;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>

<div align=center>

<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width="96%"
 style='width:96.0%;mso-cellspacing:0cm;mso-padding-alt:0cm 0cm 0cm 0cm'>
 <tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes;height:3.0pt'>
  <td colspan=3 style='padding:0cm 0cm 0cm 0cm;height:3.0pt'>
  <p class=MsoNormal align=left style='text-align:left;mso-pagination:widow-orphan'><span
  lang=EN-US style='font-size:3.0pt;mso-bidi-font-size:9.0pt;font-family:宋体;
  mso-bidi-font-family:宋体;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>
  </td>
 </tr>
 <tr style='mso-yfti-irow:1;mso-yfti-lastrow:yes'>
  <td valign=top style='padding:0cm 0cm 0cm 0cm' id=fontzoom>
  <p class=MsoNormal align=left style='text-align:left;line-height:15.0pt;
  mso-pagination:widow-orphan'><span lang=EN-US style='font-size:10.0pt;
  font-family:宋体;mso-bidi-font-family:宋体;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>
  <p class=MsoNormal align=left style='text-align:left;line-height:15.0pt;
  mso-pagination:widow-orphan'><span style='font-size:10.0pt;font-family:宋体;
  mso-bidi-font-family:宋体;mso-font-kerning:0pt'>从<span lang=EN-US>MFC</span>扩展动态链接库中输出对话框似乎是很容易的<span
  lang=EN-US>.</span>你仅需要将相应类用<span lang=EN-US>AFX_EXT_CLASS</span>输出即可。如果你用一个应用程序和一个动态链接库建立或许会成功。但是如果你在应用程序和<span
  lang=EN-US>DLL</span>中都插入更多的资源,你将会得到严重错误。<span lang=EN-US> <br>
  </span>原因如下:<span lang=EN-US> <br>
  <br>
  </span>表示一个指定资源的正常途径是用它的<span lang=EN-US>ID</span>。<span lang=EN-US>ID</span>是一个用资源编辑器定义的整型常量。现在,假定你已有一个资源(是字符串)命名为<span
  lang=EN-US>ID_MY_TEXT. <br>
  <br>
  <span class=SpellE>CString</span> <span class=SpellE>strText</span>; <br>
  <span class=SpellE>strText.LoadString</span>( ID_MY_TEXT ); <br>
  <span class=SpellE>afxDump</span> &lt;&lt; <span class=SpellE>strText</span>;
  <br>
  <br>
  </span>上述代码将字符串输出到调试窗口。有时你可能得到一个错误,而且它只发生在如果文本在一个<span lang=EN-US>MFC</span>的扩展动态链接库里。错误的原因在于应用程序获取一个资源的途径。因为应用程序和动态链接库都有一个资源文件。不同的资源<span
  lang=EN-US>ID</span>有可能一样(以为<span lang=EN-US>VC</span>资源编辑器为每个模块确定<span
  lang=EN-US>ID</span>的起始编号方式)。<span lang=EN-US> <br>
  <br>
  </span>你可能认为在你的应用程序里搜索一个资源的顺序是首先为应用程序,而后为你的<span lang=EN-US>DLL</span>。我们需要改变搜索资源的顺序。<span
  lang=EN-US> <br>
  <br>
  </span>在本站有其他文章详细讲述了从<span lang=EN-US>DLL</span>中输出对话框。但是它只能工作在正规的<span
  lang=EN-US>MFC</span>动态链接库中。<span lang=EN-US> <br>
  <br>
  </span>我写了一个类(在<span lang=EN-US>DLL</span>的<span lang=EN-US>MAIN</span>和对话框中有一些改变),允许你在任何你喜欢的地方调用你的对话框,就<span
  class=GramE>象</span>:<span lang=EN-US> <br>
  <br>
  <span class=SpellE>CMyApp::OnDLLDialog</span>() <br>
  { <br>
  <span class=SpellE>CDLLDialog</span> <span class=SpellE>dlg</span>; <br>
  <span class=SpellE>dlg.DoModal</span>(); <br>
  } <br>
  </span>我写了一个简单的类,在类的构造函数中设置动态链接库的资源句柄,<span class=GramE>在析构函数</span>中设置先前的句柄。<span
  lang=EN-US> <br>
  <br>
  /////////////////////////////////////////////////////////////////////////////////////////////
  <br>
  // File <span class=SpellE>ExtDllState.h</span> <br>
  ////////////////////////////////////////////////////////////////////////////////////////////
  <br>
  #<span class=SpellE>ifndef</span> __EXTDLLSTATE_H__ <br>
  #define __EXTDLLSTATE_H__ <br>
  <br>
  class <span class=SpellE>CEXTDLLState</span> <br>
  { <br>
  public: <br>
  <span class=SpellE>CEXTDLLState</span>(); <br>
  ~<span class=SpellE>CEXTDLLState</span>(); <br>
  protected: <br>
  HINSTANCE <span class=SpellE>m_hInstOld</span>; <br>
  }; <br>
  <br>
  #<span class=SpellE>endif</span> <br>
  ////////////////////////////////////////////////////////////////////////////////////////////
  <br>
  File <span class=SpellE>ExtDllState.cpp</span> <br>
  ////////////////////////////////////////////////////////////////////////////////////////////
  <br>
  <span class=SpellE>CEXTDLLState::CEXTDLLState</span>() <br>
  { <br>
  <span class=SpellE>m_hInstOld</span> = <span class=SpellE>AfxGetResourceHandle</span>();
  <br>
  <span class=SpellE>AfxSetResourceHandle</span>(<span class=SpellE>extensionDLL.hModule</span>);
  <br>
  } <br>
  <br>
  <span class=SpellE>CEXTDLLState::~CEXTDLLState</span>() <br>
  { <br>
  <span class=SpellE>AfxSetResourceHandle</span>(<span class=SpellE>m_hInstOld</span>);
  <br>
  } <br>
  //////////////////////////////////////////////////////////////////////////////////////
  <br>
  <br>
  </span>你可能看它<span class=GramE>很</span>短小,但是却能做很多工作:复制上面的类代码到<span
  class=SpellE><span lang=EN-US>ExDllState.h</span></span>和<span class=SpellE><span
  lang=EN-US>ExtDllState.cpp</span></span>中,将两个文件放入公有的<span lang=EN-US>Include</span>目录下,使得每个项目找到它。在你的<span
  lang=EN-US>DLL</span>中,找到<span lang=EN-US>main</span>源文件,你会看到类似下面的一些代码:<span
  lang=EN-US> <br>
  <br>
  static AFX_EXTENSION_MODULE MY_DLL_NAMEDLL = { NULL, NULL }; <br>
  </span>用<span lang=EN-US> &quot;<span class=SpellE>extensionDLL</span>&quot;</span>替换该变量。放入下面的代码:<span
  lang=EN-US> <br>
  <br>
  #include &quot;<span class=SpellE>EXTDLLState.h</span>&quot; <br>
  #include &quot;<span class=SpellE>ExtDllState.cpp</span>&quot; <br>
  <br>
  </span>在文件的其他地方寻找<span lang=EN-US>MY_DLL_NAMEDLL</span>的事件,用<span
  class=SpellE><span lang=EN-US>extensionDLL</span></span>替换它。事件只能在这个文件里发生,以为该变量是静态的。<span
  lang=EN-US> <br>
  <br>
  </span>现在,如果你想输出一个对话框,请进入<span class=SpellE><span lang=EN-US>COrresponding</span></span>类的源文件里并包含<span
  class=SpellE><span lang=EN-US>EXTDLLState.h</span></span>,重载函数<span
  class=SpellE><span lang=EN-US>DoModal</span></span><span lang=EN-US>()(</span>最好使用<span
  class=SpellE><span lang=EN-US>ClassWizard</span></span><span lang=EN-US>)</span>,你将看到类似下面的代码:<span
  lang=EN-US> <br>
  <br>
  <span class=SpellE>int</span> <span class=SpellE>CMyDLLDlg::DoModal</span>() <br>
  { <br>
  // TODO: Add your specialized code here and/or call the base class <br>
  return <span class=SpellE>CDialog::DoModal</span>(); <br>
  } <br>
  <br>
  </span>用<span lang=EN-US>&quot;<span class=SpellE>CEXTDLLState</span>
  State;&quot;</span>替换<span lang=EN-US>TODO</span>行,就<span class=GramE>象</span>下面:<span
  lang=EN-US> <br>
  <br>
  <span class=SpellE>int</span> <span class=SpellE>CDLLDlgDlg::DoModal</span>()
  <br>
  { <br>
  <span class=SpellE>CEXTDLLState</span> State; <br>
  return <span class=SpellE>CDialog::DoModal</span>(); <br>
  } <br>
  <br>
  </span>你能在<span lang=EN-US>MFC</span>扩展<span lang=EN-US>DLL</span>中想存取资源的任何地方使用<span
  class=SpellE><span lang=EN-US>CEXTDLLState</span></span>,而且总能得到正确的结果,我希望它能对你有所帮助。<span
  lang=EN-US><o:p></o:p></span></span></p>
  </td>
  <td style='padding:0cm 0cm 0cm 0cm'>
  <p class=MsoNormal align=left style='text-align:left;mso-pagination:widow-orphan'><span
  lang=EN-US style='font-size:10.0pt;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>
  </td>
  <td style='padding:0cm 0cm 0cm 0cm'>
  <p class=MsoNormal align=left style='text-align:left;mso-pagination:widow-orphan'><span
  lang=EN-US style='font-size:10.0pt;mso-font-kerning:0pt'><o:p>&nbsp;</o:p></span></p>
  </td>
 </tr>
</table>

</div>

<p class=MsoNormal><span lang=EN-US><o:p>&nbsp;</o:p></span></p>

</div>

</body>

</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -