?? 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 + -