📄 ctlevent.cpp
字号:
if (m_hWnd != hWndSave)
return;
}
if (nCharShort != 0)
{
if (nCharSave != nCharShort)
{
nChar = nCharShort;
// Event handler has changed the character.
BOOL bNewLeadByte = IsDBCSLeadByte(HIBYTE(nCharShort));
if (bLeadByte)
{
if (bNewLeadByte)
{
// Event handler changed character from DBCS to DBCS:
// Remove the old trail byte and post the new one.
VERIFY(::PeekMessage(&msg, m_hWnd, WM_CHAR, WM_CHAR,
PM_NOYIELD | PM_REMOVE));
_AfxPostTrailByte(this, LOBYTE(nCharShort));
nChar = HIBYTE(nCharShort);
}
else
{
// Event handler changed character from DBCS to SBCS:
// Remove the second byte from the queue, and forward
// along the new single-byte character.
VERIFY(::PeekMessage(&msg, m_hWnd, WM_CHAR, WM_CHAR,
PM_NOYIELD | PM_REMOVE));
}
}
else
{
if (bNewLeadByte)
{
// Event handler changed character from SBCS to DBCS:
// Post the new trail byte.
_AfxPostTrailByte(this, LOBYTE(nCharShort));
nChar = HIBYTE(nCharShort);
}
}
}
DefWindowProc(WM_CHAR, nChar, MAKELONG(nRepCnt, nFlags));
}
if (bLeadByte)
{
// Cleanup after processing a DBCS character:
// Remove the next WM_CHAR message (containing the second byte) from
// the message queue, UNLESS we're subclassing an Edit, ListBox, or
// ComboBox control.
TCHAR szClassName[10];
if ((!::GetClassName(m_hWnd, szClassName, 10)) || // didn't get class
(lstrcmpi(szClassName, _T("Edit")) && // not Edit
lstrcmpi(szClassName, _T("ListBox")) && // not ListBox
lstrcmpi(szClassName, _T("ComboBox")))) // not ComboBox
{
VERIFY(::PeekMessage(&msg, m_hWnd, WM_CHAR, WM_CHAR,
PM_NOYIELD | PM_REMOVE));
}
}
}
void COleControl::OnKeyPressEvent(USHORT)
{
// Can be overridden by subclass
}
void COleControl::OnKeyDownEvent(USHORT, USHORT)
{
// Can be overridden by subclass
}
void COleControl::OnKeyUpEvent(USHORT, USHORT)
{
// Can be overridden by subclass
}
void COleControl::ButtonDown(USHORT iButton, UINT, CPoint point)
{
DWORD dwStockEventMask = GetStockEventMask();
if ((dwStockEventMask & STOCKEVENTS_MOUSE) || m_bPendingUIActivation)
{
if (m_iButtonState == 0)
SetCapture();
m_iButtonState |= iButton;
if (dwStockEventMask & STOCKEVENT_MOUSEDOWN)
FireMouseDown(iButton, _AfxShiftState(), point.x, point.y);
m_iDblClkState &= ~iButton;
}
}
void COleControl::ButtonUp(USHORT iButton, UINT, CPoint point)
{
if (m_iButtonState != 0)
{
m_iButtonState &= ~iButton;
if (m_iButtonState == 0)
ReleaseCapture();
DWORD dwStockEventMask = GetStockEventMask();
if (dwStockEventMask & STOCKEVENT_MOUSEUP)
FireMouseUp(iButton, _AfxShiftState(), point.x, point.y);
if ((dwStockEventMask & STOCKEVENT_CLICK) &&
!(m_iDblClkState & iButton))
{
CRect rect;
GetClientRect(&rect);
if (rect.PtInRect(point))
OnClick(iButton);
}
m_iDblClkState &= ~iButton;
}
}
void COleControl::ButtonDblClk(USHORT iButton, UINT, CPoint)
{
DWORD dwStockEventMask = GetStockEventMask();
if (dwStockEventMask & STOCKEVENTS_MOUSE)
{
SetCapture();
m_iButtonState |= iButton;
if (dwStockEventMask & STOCKEVENT_DBLCLICK)
{
FireDblClick();
m_iDblClkState |= iButton;
}
}
}
void COleControl::OnMouseMove(UINT /*nFlags*/, CPoint point)
{
if (GetStockEventMask() & STOCKEVENT_MOUSEMOVE)
{
HWND hWndSave = m_hWnd;
FireMouseMove((short)m_iButtonState, _AfxShiftState(), point.x, point.y);
if (m_hWnd != hWndSave)
return;
}
Default();
}
void COleControl::OnLButtonDown(UINT nFlags, CPoint point)
{
OnButtonDown(LEFT_BUTTON, nFlags, point);
}
void COleControl::OnLButtonUp(UINT nFlags, CPoint point)
{
OnButtonUp(LEFT_BUTTON, nFlags, point);
}
void COleControl::OnLButtonDblClk(UINT nFlags, CPoint point)
{
OnButtonDblClk(LEFT_BUTTON, nFlags, point);
}
void COleControl::OnMButtonDown(UINT nFlags, CPoint point)
{
OnButtonDown(MIDDLE_BUTTON, nFlags, point);
}
void COleControl::OnMButtonUp(UINT nFlags, CPoint point)
{
OnButtonUp(MIDDLE_BUTTON, nFlags, point);
}
void COleControl::OnMButtonDblClk(UINT nFlags, CPoint point)
{
OnButtonDblClk(MIDDLE_BUTTON, nFlags, point);
}
void COleControl::OnRButtonDown(UINT nFlags, CPoint point)
{
OnButtonDown(RIGHT_BUTTON, nFlags, point);
}
void COleControl::OnRButtonUp(UINT nFlags, CPoint point)
{
OnButtonUp(RIGHT_BUTTON, nFlags, point);
}
void COleControl::OnRButtonDblClk(UINT nFlags, CPoint point)
{
OnButtonDblClk(RIGHT_BUTTON, nFlags, point);
}
void COleControl::OnButtonDown(USHORT nButton, UINT nFlags, CPoint point)
{
HWND hWndSave = m_hWnd;
if (nButton == LEFT_BUTTON)
SetFocus();
ButtonDown(nButton, nFlags, point);
if (m_hWnd != hWndSave)
return;
Default();
}
void COleControl::OnButtonUp(USHORT nButton, UINT nFlags, CPoint point)
{
HWND hWndSave = m_hWnd;
Default();
ButtonUp(nButton, nFlags, point);
if (m_hWnd != hWndSave)
return;
if (m_bInPlaceActive && !m_bUIActive && m_bPendingUIActivation)
{
m_bPendingUIActivation = FALSE;
HWND hWndFocus = ::GetFocus();
if (hWndFocus == m_hWnd || ::IsChild(m_hWnd, hWndFocus))
OnActivateInPlace(TRUE, NULL);
}
}
void COleControl::OnButtonDblClk(USHORT nButton, UINT nFlags, CPoint point)
{
HWND hWndSave = m_hWnd;
ButtonDblClk(nButton, nFlags, point);
if (m_hWnd != hWndSave)
return;
Default();
}
void COleControl::OnCancelMode()
{
CWnd::OnCancelMode();
if ((m_iButtonState != 0) || (m_iDblClkState != 0))
{
ReleaseCapture();
m_iButtonState = 0;
m_iDblClkState = 0;
}
}
void COleControl::OnClick(USHORT /*iButton*/)
{
// May be overridden by subclass
if (GetStockEventMask() & STOCKEVENT_CLICK)
FireClick();
}
/////////////////////////////////////////////////////////////////////////////
// Error event
#define ERROR_PARAMS \
EVENT_PARAM(VTS_I2 VTS_PBSTR VTS_SCODE VTS_BSTR VTS_BSTR VTS_I4 VTS_PBOOL)
void COleControl::FireError(SCODE scode, LPCTSTR lpszDescription, UINT nHelpID)
{
USES_CONVERSION;
ExternalAddRef(); // "Insurance" addref -- keeps control alive.
BSTR bstrDescription = ::SysAllocString(T2COLE(lpszDescription));
LPCTSTR lpszSource = AfxGetAppName();
LPCTSTR lpszHelpFile = _T("");
if (nHelpID != 0)
lpszHelpFile = AfxGetApp()->m_pszHelpFilePath;
if (lpszHelpFile == NULL)
lpszHelpFile = _T("");
BOOL bCancelDisplay = FALSE;
FireEvent(DISPID_ERROREVENT, ERROR_PARAMS, (WORD)SCODE_CODE(scode),
&bstrDescription, scode, lpszSource, lpszHelpFile, (DWORD)nHelpID,
&bCancelDisplay);
if (!bCancelDisplay)
DisplayError(scode, OLE2CT(bstrDescription), lpszSource, lpszHelpFile, nHelpID);
::SysFreeString(bstrDescription);
ExternalRelease();
}
void COleControl::DisplayError(SCODE /*scode*/, LPCTSTR lpszDescription,
LPCTSTR lpszSource, LPCTSTR /*lpszHelpFile*/, UINT /*nHelpID*/)
{
// May be overridden by subclass.
MessageBox(lpszDescription, lpszSource);
}
/////////////////////////////////////////////////////////////////////////////
// Force any extra compiler-generated code into AFX_INIT_SEG
#ifdef AFX_INIT_SEG
#pragma code_seg(AFX_INIT_SEG)
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -