📄 csdn_文档中心_银弹制造:开发最灵活的软件(一).htm
字号:
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">UserControl*<SPAN
style="mso-tab-count: 1"> </SPAN>pUserControl = <SPAN
style="COLOR: blue">__try_cast</SPAN>< UserControl* >(
control );<o:p></o:p></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">m_Control.pUnkControl
= <SPAN
style="COLOR: blue">reinterpret_cast</SPAN><IUnknown*><BR>(System::Runtime::InteropServices::Marshal::GetIUnknownForObject(control).ToPointer());<o:p></o:p></SPAN></P>
<P class=2 style="MARGIN: auto 0cm"><SPAN lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 宋体">OnInitialUserControl();<BR>CRectclientRect;<BR>GetClientRect(
&clientRect );</SPAN></P></TD></TR></TBODY></TABLE>
<P class=2 style="MARGIN: auto 0cm auto 18pt"><FONT face=宋体
size=3>使用过<SPAN lang=EN-US>MFC Application Project with .NET Support
1.0</SPAN>的程序员都会发现在<SPAN lang=EN-US>UserControlView</SPAN>中可以使用<SPAN
lang=EN-US>OnInitialUserControl</SPAN>来初始化非托管资源,以下代码取自官方网站提供的例子<SPAN
lang=EN-US>example003.zip</SPAN>里的<SPAN
lang=EN-US>TestAppView.cpp</SPAN>(不要被这个类名所迷惑,他其实就是<SPAN
lang=EN-US>UserControlView,</SPAN>这个例子的作者并没有用向导生成<SPAN
lang=EN-US>UserContrlView,</SPAN>而是自己增加了一个):</FONT></P>
<TABLE border=1 cellPadding=0 cellSpacing=0 class=MsoNormalTable
style="BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; BORDER-LEFT: medium none; BORDER-RIGHT: medium none; BORDER-TOP: medium none; MARGIN: auto auto auto 23.4pt; WIDTH: 405pt; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext"
width=540>
<TBODY>
<TR
style="HEIGHT: 31.5pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
<TD
style="BACKGROUND-COLOR: transparent; BORDER-BOTTOM: windowtext 1pt solid; BORDER-LEFT: windowtext 1pt solid; BORDER-RIGHT: windowtext 1pt solid; BORDER-TOP: windowtext 1pt solid; HEIGHT: 31.5pt; PADDING-BOTTOM: 0cm; PADDING-LEFT: 5.4pt; PADDING-RIGHT: 5.4pt; PADDING-TOP: 0cm; WIDTH: 405pt; mso-border-alt: solid windowtext .5pt"
vAlign=top width=540>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">m_pCtrl->Button2->set_Text(S"VB.NET
usercontrol-button changed by c++
code.");<o:p></o:p></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">m_pCtrl->Button2->add_Click(<SPAN
style="COLOR: blue">new</SPAN>
system::EventHandler((CTest*)m_pTestObj,CTest::ClickButton2));<o:p></o:p></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">m_pCtrl->TabPage1->set_Text(S"VB.NET
usercontrol-TabPage title changed by c++
code.");<o:p></o:p></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">m_pCtrl->Button1->add_Click(<SPAN
style="COLOR: blue">new</SPAN>
System::EventHandler((CTest*)m_pTestObj,CTest::Click));<o:p></o:p></SPAN></P>
<P align=left class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; TEXT-ALIGN: left; mso-layout-grid-align: none"><SPAN
lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 0pt">m_pCtrl->add_Click(<SPAN
style="COLOR: blue">new</SPAN>
System::EventHandler((CTest*)m_pTestObj,CTest::Click));<o:p></o:p></SPAN></P>
<P class=2 style="MARGIN: auto 0cm"><SPAN lang=EN-US
style="COLOR: green; FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 宋体">//Handle
events of .NET usercontrol<BR></SPAN><SPAN lang=EN-US
style="FONT-FAMILY: 新宋体; FONT-SIZE: 9pt; mso-hansi-font-family: 宋体">m_pCtrl->add_xxx(<SPAN
style="COLOR: blue">new</SPAN>
testcls::UserControl1::xxxEventHandler((CTest*)m_pTestObj,
CTest::Fire));</SPAN></P></TD></TR></TBODY></TABLE>
<P class=2 style="MARGIN: auto 0cm auto 18pt"><FONT face=宋体
size=3>可以看到不管是托管的控件的属性,还是方法甚至是事件,都可以使用非托管代码控制、作出响应。如何保证这一点,本文作者由于对<SPAN
lang=EN-US>MFC</SPAN>及<SPAN
lang=EN-US>.NET</SPAN>对象模型掌握程度有限,无法给出更详细的描述,请大家见谅。</FONT></P>
<P class=2 style="MARGIN: auto 0cm auto 18pt"><FONT size=3><FONT
face=宋体><SPAN lang=EN-US>MFC Application Project with .NET Support
1.0</SPAN>官方网站:</FONT></FONT></P>
<P class=2 style="MARGIN: auto 0cm auto 18pt"><SPAN lang=EN-US><A
href="http://www.apptemplate.com/"><FONT face=宋体
size=3>http://www.apptemplate.com/</FONT></A></SPAN></P>
<P class=2 style="MARGIN: auto 0cm auto 18pt"><FONT face=宋体
size=3>下载地址:</FONT></P>
<P class=2 style="MARGIN: auto 0cm auto 18pt"><SPAN lang=EN-US><A
href="http://www.apptemplate.com/GB/downloads/"><FONT face=宋体
size=3>http://www.apptemplate.com/GB/downloads/</FONT></A></SPAN></P>
<P align=right class=2
style="MARGIN: auto 0cm auto 18pt; TEXT-ALIGN: right; WORD-BREAK: break-all"><SPAN
lang=EN-US><FONT face=宋体 size=3>Brian Liang
2004-04</FONT></SPAN></P><BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE align=center bgColor=#006699 border=0 cellPadding=0 cellSpacing=0
width=770>
<TBODY>
<TR bgColor=#006699>
<TD align=middle bgColor=#006699 id=white><FONT
color=#ffffff>对该文的评论</FONT></TD>
<TD align=middle>
<SCRIPT src="CSDN_文档中心_银弹制造:开发最灵活的软件(一).files/readnum.htm"></SCRIPT>
</TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1 src="CSDN_文档中心_银弹制造:开发最灵活的软件(一).files/ico_pencil.gif" width=16>
</SPAN> Firec <I>(2004-5-8 10:10:31)</I> </TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3 width=532><BR>你已经死了!
<BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1 src="CSDN_文档中心_银弹制造:开发最灵活的软件(一).files/ico_pencil.gif" width=16>
</SPAN> blue_morning <I>(2004-5-4 13:52:15)</I>
</TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3 width=532><BR>没错!用.NET; 一个字:吐 对于这种文章只有吐。
<BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1 src="CSDN_文档中心_银弹制造:开发最灵活的软件(一).files/ico_pencil.gif" width=16>
</SPAN> coastline_4000 <I>(2004-5-1 11:36:11)</I>
</TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3 width=532><BR>够恶心文章 <BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1 src="CSDN_文档中心_银弹制造:开发最灵活的软件(一).files/ico_pencil.gif" width=16>
</SPAN> ccqhydzcc <I>(2004-5-1 2:21:16)</I> </TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3 width=532><BR>又是一个收钱的广告,的确需要银弹才能买
<BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1 src="CSDN_文档中心_银弹制造:开发最灵活的软件(一).files/ico_pencil.gif" width=16>
</SPAN> fans1 <I>(2004-4-29 7:53:44)</I> </TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3 width=532><BR>银弹制造?这标题真够吓人的
<BR></TD></TR></TBODY></TABLE><BR>
<DIV align=center>
<TABLE align=center bgColor=#cccccc border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TH bgColor=#006699 id=white><FONT
color=#ffffff>我要评论</FONT></TH></TR></TBODY></TABLE></DIV>
<DIV align=center>
<TABLE border=0 width=770>
<TBODY>
<TR>
<TD>你没有登陆,无法发表评论。 请先<A
href="http://www.csdn.net/member/login.asp?from=/Develop/read_article.asp?id=27291">登陆</A>
<A
href="http://www.csdn.net/expert/zc.asp">我要注册</A><BR></TD></TR></TBODY></TABLE></DIV><BR>
<HR noShade SIZE=1 width=770>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=500>
<TBODY>
<TR align=middle>
<TD height=10 vAlign=bottom><A
href="http://www.csdn.net/intro/intro.asp?id=2">网站简介</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=5">广告服务</A> - <A
href="http://www.csdn.net/map/map.shtm">网站地图</A> - <A
href="http://www.csdn.net/help/help.asp">帮助信息</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=2">联系方式</A> - <A
href="http://www.csdn.net/english">English</A> </TD>
<TD align=middle rowSpan=3><A
href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><IMG
border=0 height=48 src="CSDN_文档中心_银弹制造:开发最灵活的软件(一).files/biaoshi.gif"
width=40></A></TD></TR>
<TR align=middle>
<TD vAlign=top>百联美达美公司 版权所有 京ICP证020026号</TD></TR>
<TR align=middle>
<TD vAlign=top><FONT face=Verdana>Copyright © CSDN.net, Inc. All rights
reserved</FONT></TD></TR>
<TR>
<TD height=15></TD>
<TD></TD></TR></TBODY></TABLE></DIV>
<DIV></DIV><!--内容结束//--><!--结束//--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -