📄 csdn_文档中心_com样例(四)——客户端代码.htm
字号:
style="COLOR: blue">if</SPAN>( FAILED(
pStruct->m_pModule->InitialModule(
pSite,<BR>
IDC_MODULE_VIEW
+<BR>
index
–<BR>
1 ) ) )<BR>
{<BR>
WriteSoftErrorLog(
__LINE__,<BR>
__WFILE__,<BR>
IDS_MAINFRM_CREATEMODULE
);<BR>
<SPAN style="COLOR: blue">delete</SPAN>
pStruct;<BR>
<SPAN
style="COLOR: blue">continue</SPAN>;<BR>
}<BR><BR> <SPAN style="COLOR: green">//
获取模块窗口</SPAN><BR> <SPAN
style="COLOR: blue">if</SPAN>( FAILED(
pStruct->m_pModule->QueryInterface(<BR>
IID_IModuleUI,<BR>
<SPAN style="COLOR: blue">reinterpret_cast</SPAN>< <SPAN
style="COLOR: blue">void</SPAN>** >( &pUI ) ) )
)<BR>
{<BR>
WriteSoftErrorLog(
__LINE__,<BR>
__WFILE__,<BR>
IDS_MAINFRM_GETMODULEWND
);<BR>
<SPAN style="COLOR: blue">delete</SPAN>
pStruct;<BR>
<SPAN
style="COLOR: blue">continue</SPAN>;<BR>
}<BR> <SPAN
style="COLOR: blue">if</SPAN>( FAILED( pUI->GetMainWindow(
&pStruct->m_hWnd ) ) || !pStruct->m_hWnd
)<BR>
{<BR>
WriteSoftErrorLog(
__LINE__,<BR>
__WFILE__,<BR>
IDS_MAINFRM_GETMODULEWND
);<BR>
pUI->Release();<BR>
<SPAN style="COLOR: blue">delete</SPAN>
pStruct;<BR>
<SPAN
style="COLOR: blue">continue</SPAN>;<BR>
}<BR>
pUI->Release();<BR><BR>
{<BR> <SPAN
style="COLOR: green">//
修改窗口风格,确保模块窗口具有WS_EX_CLIENTEDGE风格</SPAN><BR>
<SPAN style="COLOR: blue">if</SPAN>( !::SetWindowLong(
pStruct->m_hWnd,<BR>
GWL_EXSTYLE,<BR>
::GetWindowLong(
pStruct->m_hWnd,<BR>
GWL_EXSTYLE )
|<BR>
WS_EX_CLIENTEDGE )
)<BR>
WriteSoftErrorLog(
__LINE__,<BR>
__WFILE__,<BR>
IDS_SETWINDOWSTYLE );<BR>
}<BR><BR> <SPAN style="COLOR: green">//
隐藏模块窗口</SPAN><BR>
::ShowWindow( pStruct->m_hWnd, SW_HIDE
);<BR><BR> <SPAN style="COLOR: green">//
获取模块的菜单句柄,并插入到MainFrame</SPAN><BR>
<SPAN style="COLOR: blue">if</SPAN>( SUCCEEDED(
pStruct->m_pModule->QueryInterface(<BR>
IID_IMenuUpdate,<BR>
<SPAN style="COLOR: blue">reinterpret_cast</SPAN>< <SPAN
style="COLOR: blue">void</SPAN>** >( &pMenuUp ) ) )
)<BR>
{<BR> <SPAN
style="COLOR: green">//
模块提供了菜单,获取菜单句柄</SPAN><BR>
<SPAN style="COLOR: blue">if</SPAN>( FAILED( pMenuUp->GetMenu(
&pStruct->m_hMenu ) )
)<BR>
WriteSoftErrorLog(
__LINE__,<BR>
__WFILE__,<BR>
IDS_MAINFRM_CREATEMODULEMENU
);<BR>
pMenuUp->Release();<BR>
}<BR><BR>
m_ModuleList.AddTail( pStruct );<BR>
}<BR> pSite->Release();<BR>
pEnum->Release();<BR><BR><SPAN style="COLOR: green">//
一个模块都不激活</SPAN><BR> m_Selected = <SPAN
style="COLOR: blue">static_cast</SPAN>< ULONG >( -1
);<BR><BR> ULONG count =
m_ModuleList.GetCount();<BR> <SPAN
style="COLOR: blue">if</SPAN>( count )<BR>
{<BR> <SPAN style="COLOR: green">//
获取模块的图标,并将其插入到模块工具条和菜单中</SPAN><BR>
m_wndToolBar.SetSizes( CSize( 23, 22 ), CSize( 16, 15 )
);<BR> <SPAN
style="COLOR: blue">if</SPAN>( !m_wndToolBar.SetButtons( NULL, count
)
)<BR>
WriteSoftErrorLog(
__LINE__,<BR>
__WFILE__,<BR>
IDS_CREATETOOLBARBUTTON
);<BR> <SPAN
style="COLOR: blue">else</SPAN><BR>
{<BR> <SPAN
style="COLOR: green">//
将图标画到位图中</SPAN><BR>
CBitmap
bitmap;<BR>
CDC *pScreen = CDC::FromHandle( ::GetDC( NULL )
);<BR>
CDC
sdc;<BR>
<SPAN style="COLOR: blue">if</SPAN>( !bitmap.CreateCompatibleBitmap(
pScreen,<BR>
ICONWIDTH *
count,<BR>
ICONHEIGHT )
||<BR>
!sdc.CreateCompatibleDC( pScreen )
)<BR>
{<BR>
WriteSoftErrorLog(
__LINE__,<BR>
__WFILE__,<BR>
L"创建缓冲位图失败!"
);<BR>
<SPAN style="COLOR: blue">return</SPAN>
0;<BR>
}<BR>
sdc.SelectObject( &bitmap
);<BR>
sdc.FillSolidRect(
0,<BR>
0,<BR>
ICONWIDTH *
count,<BR>
ICONHEIGHT,<BR>
RGB( 0xC0, 0xC0, 0xC0 )
);<BR>
HICON hIcon =
NULL;<BR>
ULONG i =
0;<BR>
POSITION pos =
m_ModuleList.GetHeadPosition();<BR>
CMenu *pMenu =
GetMenu()->GetSubMenu(0)->GetSubMenu(0);<BR>
ASSERT_VALID( pMenu
);<BR><BR> <SPAN
style="COLOR: green">//
清空原来的占位符</SPAN><BR>
<SPAN style="COLOR: blue">while</SPAN>( pMenu->DeleteMenu( 0,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -