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

📄 cb199912at_f.asp.htm

📁 C++builder学习资料C++builder
💻 HTM
📖 第 1 页 / 共 2 页
字号:
  

<p class=Code><span class=Code>&nbsp;&nbsp;} </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;<b> return</b>  

S_OK; </span></p>  

  

<p class=Code><span class=Code>};</span></p>  

  

<p class=Captions><b>Figure 3:</b> The "get" and "set" method stubs  

of the <i>GridColor</i> property. </p>  

  

<p class=BodyText> &nbsp; </p>  

  

<p class=BodyText> Now open  

the header file for the ActiveForm, add a <b>published</b>  

section, and add a property named <i>GridColor</i>  

of type <i>TColor</i> (see Figure 4). </p>  

  

<p class=BodyText> &nbsp; </p>  

  

<p class=Code><span class=Code><b>class</b>  

TInformant : <b>public</b> TActiveForm</span></p>  

  

<p class=Code><span class=Code>{</span></p>  

  

<p class=Code><span class=Code><b>&nbsp;&nbsp;__published</b>:&nbsp;&nbsp;<i> <span Class=CodeBlue>//  

IDE-managed Components</span></i></span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;TDBNavigator *DBNavigator1; </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;TDBGrid *DBGrid1; </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;TDataSource *DataSource1; </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;TTable *Table1; </span></p>  

  

<p class=Code><span class=Code><b>&nbsp;&nbsp;private</b>:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i> <span Class=CodeBlue>//  

User declarations</span></i></span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;<b> void  

__fastcall</b> SetGridColor(TColor value); </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;TColor <b>__fastcall</b> GetGridColor();</span></p>  

  

<p class=Code><span class=Code><b>&nbsp;&nbsp;public</b>:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i> <span Class=CodeBlue>// User declarations</span></i></span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;__<b> fastcall</b>  

TInformant(HWND ParentWindow); </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;__<b> fastcall</b>  

TInformant(TComponent* AOwner): </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TActiveForm(AOwner) {};</span></p>  

  

<p class=Code><span class=Code><b>&nbsp;&nbsp;__published</b>:</span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;<b> __property</b>  

TColor GridColor =</span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ read = GetGridColor, write =  

SetGridColor };</span></p>  

  

<p class=Code><span class=Code>};</span></p>  

  

<p class=Captions><b>Figure 4: </b>The declaration for the <i  

style='mso-bidi-font-style:normal'>GridColor</i> property. </p>  

  

<p class=BodyText> &nbsp; </p>  

  

<p class=BodyText> Next, implement the <i>GridColor</i>  

property: </p>  

  

<p class=BodyText> &nbsp; </p>  

  

<p class=Code><span class=Code><b>void</b>  

__<b>fastcall</b>  

TInformant::SetGridColor(TColor value) </span></p>  

  

<p class=Code><span class=Code>{</span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;DBGrid1-&gt;Color = value; </span></p>  

  

<p class=Code><span class=Code>}</span></p>  

  

<p class=Code><span class=Code>&nbsp; </span></p>  

  

<p class=Code><span class=Code>TColor __<b  

style='mso-bidi-font-weight:normal'>fastcall</b> TInformant::GetGridColor()</span></p>  

  

<p class=Code><span class=Code>{</span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;<b> return</b>  

DBGrid1-&gt;Color; </span></p>  

  

<p class=Code><span class=Code>}</span></p>  

  

<p class=BodyText> &nbsp; </p>  

  

<p class=BodyText> Now hook  

up the VCL <i>GridColor</i> property<i  

style='mso-bidi-font-style:normal'> </i>to the ActiveX <i>GridColor</i> property, as shown in Figure 6. </p>  

  

<p class=BodyText> &nbsp; </p>  

  

<p class=Code><span class=Code>STDMETHODIMP  

TInformantImpl::get_GridColor(::OLE_COLOR* Value) </span></p>  

  

<p class=Code><span class=Code>{</span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;<b> try</b></span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;{ </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;*Value = m_VclCtl-&gt;GridColor; </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;} </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;<b> catch</b>(Exception  

&amp;e) </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;{ </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;<b> return</b>  

Error(e.Message.c_str(), IID_IInformant); </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;} </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;<b> return</b>  

S_OK; </span></p>  

  

<p class=Code><span class=Code>};</span></p>  

  

<p class=Code><span class=Code>&nbsp; </span></p>  

  

<p class=Code><span class=Code>STDMETHODIMP  

TInformantImpl::set_GridColor(::OLE_COLOR Value) </span></p>  

  

<p class=Code><span class=Code>{</span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;<b> try</b></span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;{ </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;m_VclCtl-&gt;GridColor = Value; </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;} </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;<b> catch</b>(Exception  

&amp;e) </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;{ </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;&nbsp;&nbsp;<b> return</b>  

Error(e.Message.c_str(), IID_IInformant); </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;} </span></p>  

  

<p class=Code><span class=Code>&nbsp;&nbsp;<b> return</b>  

S_OK; </span></p>  

  

<p class=Code><span class=Code>};</span></p>  

  

<p class=Captions><b>Figure 5:</b> Associating the VCL <i  

style='mso-bidi-font-style:normal'>GridColor</i> property to the ActiveX <i  

style='mso-bidi-font-style:normal'>GridColor</i> property. </p>  

  

<p class=BodyText> &nbsp; </p>  

  

<p class=BodyText> As you  

can see, the magic is in <i>m_VclCtl</i>,  

the <i>TWinControlAccess</i> field that maps  

the VCL control properties to the ActiveX control properties. </p>  

  

<p class=BodyText> &nbsp; </p>  

  

<p class=BodyText> This  

ActiveForm can be now dropped on any ActiveX container, and it will display the  

<i>GridColor</i> property that manages the  

color of the grid in its Object Inspector at design time (see Figure 6). </p>  

  

<p class=BodyText> &nbsp; </p>  

  

<p class=Captions><img width=333 height=250  

 src="images/cb199912at_f_image006.jpg" tppabs="http://www.cbuilderzine.com/features/1999/12/cb199912at_f/cb199912at_f_image006.jpg" align=left> <br clear=all>  

<b>Figure 6:</b>  

The example ActiveForm running in Excel 2000 with the new <i>GridColor</i> property set to <i>Yellow</i>.</p>  

  

<p class=BodyText> &nbsp; </p>  

  

  

  

<p class=Subheads>Conclusion</p>  

  

<p class=BodyText> This  

article has demonstrated how to develop ActiveX controls in C++Builder. No  

doubt, C++Builder brings out the strength of ATL with the simplicity of a real  

visual development tool. </p>  

  

<p class=BodyText> &nbsp; </p>  

  

<p class=BodyText> I would  

like to thank the architect of the C++Builder ATL framework, Mr Steve Teixeira,  

for a job well done using his "Connective Tissue" methodology. </p>  

  

<p class=BodyText> &nbsp; </p>  

  

<p class=BodyText> <i>The code accompanying this article  

is available for <a href="download/cb199912at_f.zip" tppabs="http://www.cbuilderzine.com/features/1999/12/cb199912at_f/cb199912at_d.asp">download</a>. </i></p> 

 

<p class=BodyText> &nbsp; </p> 

 

<p class=Biotext> </p> 

 

<p class=BodyText> &nbsp; </p> 

 

 

 

<p class=BodyText> &nbsp; </p> 

 

 

 

<p class=BodyText> &nbsp; </p> 

 

</td> 

</TR> 

</TABLE> 

 

 

</BODY> 

</HTML> 

<!-- <PubToken>cb</PubToken> --> 

⌨️ 快捷键说明

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