判斷ActiveX控件是Desgin Mode還是Runtime Mode
阿新 • • 發佈:2017-05-23
ram targe turn cti trie com port section ont in design mode.
) or design-mode (FALSE).
對於MFC
COleControl::AmbientUserMode
Determines if the Container is in design mode or user mode.
BOOL AmbientUserMode( );
Return Value
Nonzero if the container is in user mode; otherwise 0 (in design mode). If this property is not supported, this function returns 0.
Remarks
For example, a container might set this to FALSE
根據當前ActiveX控件當前所處的模式,修改OnDraw函數:
BOOL bUserMode = FALSE; bUserMode = AmbientUserMode(); if(bUserMode) { LPCTSTR pszText = _T("MFC 3.0 : User Mode"); TextOut(di.hdcDraw, (rc.left + rc.right) / 2, (rc.top + rc.bottom) / 2, pszText, lstrlen(pszText)); }else { LPCTSTR pszText = _T("MFC 3.0 : Design Mode"); TextOut(di.hdcDraw, (rc.left + rc.right) / 2, (rc.top + rc.bottom) / 2, pszText, lstrlen(pszText)); }
對於ATL
CComControlBase::GetAmbientUserMode
Retrieves DISPID_AMBIENT_USERMODE, a flag indicating whether the container is in run-mode (TRUE
HRESULT GetAmbientUserMode(BOOL& bUserMode);
Parameters
- bUserMode :
The property DISPID_AMBIENT_USERMODE.
Return Value :One of the standard HRESULT values.
OnDraw中判斷
BOOL bUserMode = FALSE; HRESULT hr = GetAmbientUserMode(bUserMode); if(bUserMode) { LPCTSTR pszText = _T("ATL 3.0 : User Mode"); TextOut(di.hdcDraw, (rc.left + rc.right) / 2, (rc.top + rc.bottom) / 2, pszText, lstrlen(pszText)); } else { LPCTSTR pszText = _T("ATL 3.0 : Design Mode"); TextOut(di.hdcDraw, (rc.left + rc.right) / 2, (rc.top + rc.bottom) / 2, pszText, lstrlen(pszText)); }
判斷ActiveX控件是Desgin Mode還是Runtime Mode