📄 csdn_文档中心_com样例(二)——样例结构设计.htm
字号:
<SPAN style="COLOR: blue">pointer_default</SPAN>(<SPAN
style="COLOR: blue">unique</SPAN>)<BR>]<BR><FONT color=blue
face=宋体>interface</FONT> IModule: IUnknown<BR>{<BR><FONT color=green
face=宋体>// 初始化模块,nID为模块窗口的子窗口ID</FONT><BR> HRESULT
InitialModule( [<SPAN style="COLOR: blue">in</SPAN>] IModuleSite
*pSite, [<SPAN style="COLOR: blue">in</SPAN>] UINT nID );<BR><FONT
color=green face=宋体>// 返回模块的图标</FONT><BR> HRESULT
GetIcon( [<SPAN style="COLOR: blue">out</SPAN>] HICON *pHicon
);<BR><FONT color=green face=宋体>//
返回模块的名字</FONT><BR> HRESULT GetName( [<SPAN
style="COLOR: blue">out</SPAN>, <SPAN
style="COLOR: blue">string</SPAN>] WCHAR **pName
);<BR>};<BR><BR><FONT color=green face=宋体>//
部门组件不一定实现IModuleCommand,其提供执行模块所特有的命令</FONT><BR>[<BR>
<SPAN style="COLOR: blue">object</SPAN>,<BR> <SPAN
style="COLOR: blue">uuid</SPAN>(1A201ABA-A669-4ac7-9DFE-2DA772E927FC),<BR>
<SPAN style="COLOR: blue">pointer_default</SPAN>(<SPAN
style="COLOR: blue">unique</SPAN>)<BR>]<BR><FONT color=blue
face=宋体>interface</FONT> IModuleCommand:
IUnknown<BR>{<BR> HRESULT DoCommand( [<SPAN
style="COLOR: blue">in</SPAN>] ULONG command, [<SPAN
style="COLOR: blue">in</SPAN>] DWORD param );<BR>};<BR><BR><FONT
color=green face=宋体>//
部门组件不一定实现IModuleNotify,其对模块提供一个通知途径</FONT><BR>[<BR>
<SPAN style="COLOR: blue">object</SPAN>,<BR> <SPAN
style="COLOR: blue">uuid</SPAN>(1A201ABA-A669-4ac7-9DFF-2DA772E927FC),<BR>
<SPAN style="COLOR: blue">pointer_default</SPAN>(<SPAN
style="COLOR: blue">unique</SPAN>)<BR>]<BR><FONT color=blue
face=宋体>interface</FONT> IModuleNotify:
IUnknown<BR>{<BR> HRESULT
OnActivate(); <SPAN style="COLOR: green">//
模块切换时被激活</SPAN><BR> HRESULT OnDeActivate();
<SPAN style="COLOR: green">// 模块切换时取消激活</SPAN><BR>};<BR><BR><FONT
color=green face=宋体>//
部门组件必须实现IModuleUI,其提供模块界面的相关操作</FONT><BR>[<BR>
<SPAN style="COLOR: blue">object</SPAN>,<BR> <SPAN
style="COLOR: blue">uuid</SPAN>(1A201ABA-A669-4ac7-9E00-2DA772E927FC),<BR>
<SPAN style="COLOR: blue">pointer_default</SPAN>(<SPAN
style="COLOR: blue">unique</SPAN>)<BR>]<BR><FONT color=blue
face=宋体>interface</FONT> IModuleUI: IUnknown<BR>{<BR><FONT
color=green face=宋体>// 返回模块的主要窗口</FONT><BR>
HRESULT GetMainWindow( [<SPAN style="COLOR: blue">out</SPAN>] HWND
*pHwnd );<BR><FONT color=green face=宋体>//
翻译快捷键</FONT><BR> HRESULT TranslateAccelerator(
[<SPAN style="COLOR: blue">in</SPAN>] MSG *pMsg
);<BR>};<BR><BR><FONT color=green face=宋体>//
部门组件不一定实现IMenuUdpate,其提供模块界面中菜单的相关操作</FONT><BR>[<BR>
<SPAN style="COLOR: blue">object</SPAN>,<BR> <SPAN
style="COLOR: blue">uuid</SPAN>(1A201ABA-A669-4ac7-9E01-2DA772E927FC),<BR>
<SPAN style="COLOR: blue">pointer_default</SPAN>(<SPAN
style="COLOR: blue">unique</SPAN>)<BR>]<BR><FONT color=blue
face=宋体>interface</FONT> IMenuUpdate:
IUnknown<BR>{<BR> HRESULT GetMenu( [<SPAN
style="COLOR: blue">out</SPAN>] HMENU *pHmenu
);<BR> HRESULT GetMenuItemString( [<SPAN
style="COLOR: blue">in</SPAN>] ULONG
nID,<BR>
[<SPAN style="COLOR: blue">out</SPAN>, <SPAN
style="COLOR: blue">string</SPAN>] WCHAR **pString
);<BR>};<BR><BR><FONT color=green face=宋体>//
当部门组件创建了一个任务时,任务对象必须实现ITask以进行相应的任务管理</FONT><BR>[<BR>
<SPAN style="COLOR: blue">object</SPAN>,<BR> <SPAN
style="COLOR: blue">uuid</SPAN>(1A201ABA-A669-4ac7-9E02-2DA772E927FC),<BR>
<SPAN style="COLOR: blue">pointer_default</SPAN>(<SPAN
style="COLOR: blue">unique</SPAN>)<BR>]<BR><FONT color=blue
face=宋体>interface</FONT> ITask: IUnknown<BR>{<BR><FONT color=green
face=宋体>// 返回任务的进度</FONT><BR> HRESULT
GetProcessRateOfTask( [<SPAN style="COLOR: blue">out</SPAN>] <SPAN
style="COLOR: blue">float</SPAN> *pRate );<BR>
HRESULT TerminateTask(); <SPAN style="COLOR: green">//
终止任务</SPAN><BR><FONT color=green face=宋体>//
将任务和任务管理器绑定起来</FONT><BR> HRESULT SetTaskSite(
[<SPAN style="COLOR: blue">in</SPAN>] ITaskManager *pManager, [<SPAN
style="COLOR: blue">in</SPAN>] DWORD cookie
);<BR>};<BR><BR>[<BR> <SPAN
style="COLOR: blue">uuid</SPAN>(1A201ABA-A669-4ac7-9D00-2DA772E927FC),<BR>
<SPAN style="COLOR: blue">version</SPAN>(1.0),<BR>
<SPAN style="COLOR: blue">helpstring</SPAN>("ExampleBase 1.0
TypeLib")<BR>]<BR><FONT color=blue face=宋体>library</FONT>
ExampleBaseLib<BR>{<BR> <SPAN
style="COLOR: blue">importlib</SPAN>("stdole32.tlb");<BR>
<SPAN
style="COLOR: blue">importlib</SPAN>("stdole2.tlb");<BR> <BR>
<SPAN style="COLOR: blue">interface</SPAN>
IModuleSite;<BR> <SPAN
style="COLOR: blue">interface</SPAN>
IErrorReport;<BR> <SPAN
style="COLOR: blue">interface</SPAN>
ICompanyInfo;<BR> <SPAN
style="COLOR: blue">interface</SPAN>
ITaskManager;<BR> <SPAN
style="COLOR: blue">interface</SPAN> IModule;<BR>
<SPAN style="COLOR: blue">interface</SPAN>
IModuleCommand;<BR> <SPAN
style="COLOR: blue">interface</SPAN>
IModuleNotify;<BR> <SPAN
style="COLOR: blue">interface</SPAN>
IModuleUI;<BR> <SPAN
style="COLOR: blue">interface</SPAN>
IMenuUpdate;<BR> <SPAN
style="COLOR: blue">interface</SPAN> ITask;<BR>
<SPAN style="COLOR: blue">interface</SPAN>
ITaskNotify;<BR>};<BR>
上面的设计有个很明显的问题就是并没有体现组件的特性,只是很简单的部门组件和基本框架的组合,部门组件不能再有什么其他作为,是一种变相的DLL技术。这是样例的目标及特点(各部门完全不一样的信息处理方式)决定的,就是一个插件接口。基本框架相当于一个播放器,而部门组件相当于一种音效处理插件。由于这只是个简单的例子,无法表现出COM组件特性的优点,但就此样例给出线程模型的例子已经是足够了。<BR>
如果每个部门组件都只是信息录入、信息查询和信息管理(忽略其业务流程,如订单需要和出货联系起来),则可以使用另一种功能分割方式,即信息表现的接口、录入信息的接口、查询信息的接口和管理信息的接口(甚至还可以抽象出业务进而形成业务接口),这种方案将体现出组件的概念,但复杂程度亦增加了不少,因为其灵活性大大高于前一种方案。<BR>
由于添加工具条的支持需要更多的代码,并且对本样例没有什么意义,故本样例中没有提供对工具条的支持。<BR>
作为一种习惯,将工程中所有的接口定义在一个.idl文件中,然后再专门定一个项目生成其代理/占位组件,并导出IID等这类全局变量以供以后的使用,并且可以将类型信息一起加入其中,以减少最终完成中的文件数量。对于此,我已经在样例的解决方案中如此做了,源代码请在《COM样例(四)》中下载。</P></FONT><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_文档中心_COM样例(二)——样例结构设计.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_文档中心_COM样例(二)——样例结构设计.files/ico_pencil.gif" width=16>
</SPAN> freeshoot <I>(2004-4-27 17:41:58)</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=27167">登陆</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_文档中心_COM样例(二)——样例结构设计.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 + -