📄 csdn_文档中心_com样例(四)——客户端代码.htm
字号:
<TABLE border=0 width=770>
<TBODY>
<TR>
<TD align=middle bgColor=#fafafa class=td1 vAlign=top width=150><BR>
<SCRIPT src="CSDN_文档中心_COM样例(四)——客户端代码.files/microsoft.js"></SCRIPT>
</TD>
<TD align=middle width=620>
<TABLE bgColor=#eeeeee border=0 cellPadding=0 cellSpacing=0 width=600>
<TBODY>
<TR bgColor=#ffffff>
<TD align=middle height=10 width=50></TD>
<TD align=right><A href="http://www.csdn.net/">CSDN</A> - <A
href="http://www.csdn.net/develop/">文档中心</A> - <FONT
color=#003399>Visual C++</FONT> </TD></TR>
<TR>
<TD align=middle height=5></TD>
<TD align=middle width=500></TD></TR>
<TR>
<TD align=middle bgColor=#003399 height=10><FONT
color=#ffffff>标题</FONT></TD>
<TD><B> COM样例(四)——客户端代码</B> lop5712(原作)
</TD></TR>
<TR>
<TD align=middle height=5></TD>
<TD align=middle width=500></TD></TR>
<TR>
<TD align=middle bgColor=#003399><FONT color=#ffffff>关键字</FONT></TD>
<TD width=500> COM 样例</TD></TR>
<TR>
<TD align=middle height=5></TD>
<TD align=middle width=500></TD></TR></TBODY></TABLE><!--文章说明信息结束//-->
<TABLE border=0 width=600>
<TBODY>
<TR>
<TD align=left><BR><FONT
style="FONT-FAMILY: '宋体'; FONT-SIZE: 10pt; LINE-HEIGHT: 150%">
<P align=center><FONT face=楷体_GB2312
size=5><STRONG>COM样例(四)</STRONG></FONT> </P>
<P align=right><FONT face=楷体_GB2312
size=4><STRONG>——客户端代码</STRONG></FONT> </P>
<P>
本文为此系列文章的最后一篇,罗列客户端的源代码。客户端使用MFC实现,其中的框架类CMainFrame实现了IModuleSite、IErrorReport和ICompanyInfo,而另一个窗口包装类CTaskManager实现ITaskManager,并由CMainFrame聚合它以表现出CMainFrame实现了ITaskManager。由于代码较长,本篇只罗列CMainFrame::OnCreate和CMainFrame的定义,其中实现了获取部门组件的实例(通过COM的组件类别功能进行记录,而非通过注册表),并进行管理。<BR>
如果欲查看本样例的所有代码,可于文末下载。而本样例的可执行文件也请于文末下载。由于本样例只是我很早以前编的一个程序精简修改而成,代码中可能有不少幼稚的地方,我现在也没兴致再仔细修改,只是大致修整了一下,还请见谅。</P>
<P><BR><FONT face=楷体_GB2312
size=4><STRONG>CMainFrame的定义</STRONG></FONT></P>
<P><SPAN style="COLOR: blue">#include</SPAN>
"NewStatusBar.h"<BR><BR><SPAN style="COLOR: blue">class</SPAN>
CMainFrame : <SPAN style="COLOR: blue">public</SPAN>
CFrameWnd<BR>{<BR><SPAN style="COLOR: green">//
MFC定义宏</SPAN><BR> DECLARE_DYNCREATE( CMainFrame
)<BR> DECLARE_MESSAGE_MAP()<BR>
DECLARE_INTERFACE_MAP()<BR><BR><SPAN style="COLOR: green">//
辅助结构</SPAN><BR><SPAN
style="COLOR: blue">private</SPAN>:<BR> <SPAN
style="COLOR: blue">struct</SPAN> TEMPSTRUCT<BR>
{<BR>
HWND
m_hWnd;<BR>
HMENU
m_hMenu;<BR> IModule
*m_pModule;<BR>
CLSID
m_CLSID;<BR> TEMPSTRUCT()
: m_hWnd( NULL ), m_hMenu( NULL ), m_pModule( NULL
)<BR>
{<BR> <SPAN
style="COLOR: green">//
什么都不做</SPAN><BR>
}<BR>
~TEMPSTRUCT()<BR>
{<BR>
SafeRelease( m_pModule
);<BR>
}<BR> };<BR><BR><SPAN style="COLOR: green">//
构造、析构</SPAN><BR><SPAN
style="COLOR: blue">public</SPAN>:<BR>
CMainFrame();<BR>
~CMainFrame();<BR> <BR><SPAN style="COLOR: green">//
操作</SPAN><BR><SPAN
style="COLOR: blue">public</SPAN>:<BR> <SPAN
style="COLOR: blue">void</SPAN> UpdateErrorState() <SPAN
style="COLOR: green">//
更新状态条上的错误标志以表示指示最新错误的发生</SPAN><BR>
{<BR> ASSERT_VALID( <SPAN
style="COLOR: blue">this</SPAN>
);<BR><BR> <SPAN
style="COLOR: blue">if</SPAN>( m_wndStatusBar.GetSafeHwnd()
)<BR>
m_wndStatusBar.Invalidate();<BR> }<BR><BR><SPAN
style="COLOR: green">// 辅助函数</SPAN><BR><SPAN
style="COLOR: blue">protected</SPAN>:<BR><SPAN
style="COLOR: green"> //
根据菜单项ID确定是否是基本框架的菜单命令</SPAN><BR> BOOL
BeMenuOfBase( DWORD nID ) <SPAN
style="COLOR: blue">const</SPAN>;<BR><BR><SPAN
style="COLOR: green">// 成员变量</SPAN><BR><SPAN
style="COLOR: blue">protected</SPAN>:<BR>
CNewStatusBar m_wndStatusBar;<BR>
CToolBar
m_wndToolBar;<BR>
DWORD
m_Selected;<BR> <SPAN
style="COLOR: blue">long</SPAN>
m_OldViewID;<BR>
IUnknown
*m_pTaskManager;<BR><BR> CTypedPtrList<
CPtrList, TEMPSTRUCT* > m_ModuleList;<BR><BR><SPAN
style="COLOR: green">// 重载</SPAN><BR><SPAN
style="COLOR: blue">protected</SPAN>:<BR> <SPAN
style="COLOR: blue">void</SPAN> GetMessageString( UINT nID, CString
&rMessage ) <SPAN
style="COLOR: blue">const</SPAN>;<BR> BOOL
OnCommand( WPARAM wParam, LPARAM lParam );<BR><BR><SPAN
style="COLOR: green">// 窗口消息</SPAN><BR><SPAN
style="COLOR: blue">protected</SPAN>:<BR> afx_msg
<SPAN style="COLOR: blue">int</SPAN> OnCreate( LPCREATESTRUCT
lpCreateStruct );<BR> afx_msg <SPAN
style="COLOR: blue">void</SPAN> OnActivate( UINT nState, CWnd*
pWndOther, BOOL bMinimized );<BR> afx_msg <SPAN
style="COLOR: blue">void</SPAN> OnSetFocus( CWnd *pOldWnd
);<BR> afx_msg <SPAN
style="COLOR: blue">void</SPAN> OnInitMenuPopup( CMenu *pPopupMenu,
UINT nIndex, BOOL bSysMenu );<BR> afx_msg <SPAN
style="COLOR: blue">void</SPAN> OnInitMenu( CMenu *pMenu
);<BR> afx_msg BOOL OnEraseBkgnd( CDC *pDC
);<BR> afx_msg <SPAN
style="COLOR: blue">void</SPAN> OnClose();<BR><BR><SPAN
style="COLOR: green">// 菜单消息</SPAN><BR><SPAN
style="COLOR: blue">protected</SPAN>:<BR> <SPAN
style="COLOR: blue">void</SPAN> OnModule( UINT nID
);<BR> <SPAN style="COLOR: blue">void</SPAN>
OnUpdateModule( CCmdUI *pCmdUI );<BR><BR><SPAN
style="COLOR: green">// 自定消息</SPAN><BR><SPAN
style="COLOR: blue">protected</SPAN>:<BR> afx_msg
LRESULT OnAllTaskTerminated( WPARAM, LPARAM );<BR><BR><SPAN
style="COLOR: green">// 接口映射</SPAN><BR><SPAN
style="COLOR: blue">public</SPAN>:<BR><SPAN style="COLOR: green">//
IModuleSite</SPAN><BR> BEGIN_INTERFACE_PART(
ModuleSite, IModuleSite
)<BR> INIT_INTERFACE_PART(
CMainFrame, ModuleSite
)<BR>
STDMETHOD(ChangeModule)( REFCLSID
clsid,<BR>
WCHAR
*pModuleName,<BR>
ULONG
command,<BR>
ULONG param );<BR>
STDMETHOD(GetFrameWindow)( HWND *pHwnd );<BR>
END_INTERFACE_PART_STATIC( ModuleSite )<BR><BR><SPAN
style="COLOR: green">// IErrorReport</SPAN><BR>
BEGIN_INTERFACE_PART( ErrorReport, IErrorReport
)<BR> INIT_INTERFACE_PART(
CMainFrame, ErrorReport
)<BR>
STDMETHOD(ReportSoftError)( WCHAR
*fileName,<BR>
ULONG
row,<BR>
WCHAR *errorString );<BR>
STDMETHOD(ReportHardError)( WCHAR
*fileName,<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -