windows窗口消息内部处理机制
LRESULT WINAPI
RealDefWindowProcA(HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam)
{
LRESULT Result = 0;
PWND Wnd;
// spy++的入口
SPY_EnterMessage(SPY_DEFWNDPROC, hWnd, Msg, wParam, lParam);
switch (Msg)
{
case WM_NCCREATE:
{
if (lParam)
{
LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
/* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
* may have child window IDs instead of window name */
if (HIWORD(cs->lpszName))
{
// 这个和setwindowtext是一样的, 只是将cs中的名字拷贝到窗口对象中的windowname而已
DefSetText(hWnd, (PCWSTR)cs->lpszName, TRUE);
}
Result = 1;
}
break;
}
case WM_GETTEXTLENGTH:
{
PWSTR buf;
ULONG len;
Wnd = ValidateHwnd(hWnd);
if (Wnd != NULL && Wnd->strName.Length != 0)
{
buf = DesktopPtrToUser(Wnd->strName.Buffer);
if (buf != NULL &&
NT_SUCCESS(RtlUnicodeToMultiByteSize(&len,
buf,
Wnd->strName.Length)))
{
Result = (LRESULT) len;
}
}
else Result = 0L;
break;
}
case WM_GETTEXT:
{
PWSTR buf = NULL;
PSTR outbuf = (PSTR)lParam;
UINT copy;
Wnd = ValidateHwnd(hWnd);
if (Wnd != NULL && wParam != 0)
{
if (Wnd->strName.Buffer != NULL)
buf = DesktopPtrToUser(Wnd->strName.Buffer);
else
outbuf[0] = L'\0';
if (buf != NULL)
{
if (Wnd->strName.Length != 0)
{
copy = min(Wnd->strName.Length / sizeof(WCHAR), wParam - 1);
Result = WideCharToMultiByte(CP_ACP,
0,
buf,
copy,
outbuf,
wParam,
NULL,
NULL);
outbuf[Result] = '\0';
}
else
outbuf[0] = '\0';
}
}
break;
}
case WM_SETTEXT:
{
DefSetText(hWnd, (PCWSTR)lParam, TRUE);
if ((GetWindowLongPtrW(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION)
{
DefWndNCPaint(hWnd, HRGN_WINDOW, -1);
}
Result = 1;
break;
}
case WM_IME_KEYDOWN:
{
Result = PostMessageA(hWnd, WM_KEYDOWN, wParam, lParam);
break;
}
case WM_IME_KEYUP:
{
Result = PostMessageA(hWnd, WM_KEYUP, wParam, lParam);
break;
}
case WM_IME_CHAR:
{
if (HIBYTE(wParam))
PostMessageA(hWnd, WM_CHAR, HIBYTE(wParam), lParam);
PostMessageA(hWnd, WM_CHAR, LOBYTE(wParam), lParam);
break;
}
case WM_IME_STARTCOMPOSITION:
case WM_IME_COMPOSITION:
case WM_IME_ENDCOMPOSITION:
case WM_IME_SELECT:
case WM_IME_NOTIFY:
{
HWND hwndIME;
hwndIME = DefWndImmGetDefaultIMEWnd(hWnd);
if (hwndIME)
Result = SendMessageA(hwndIME, Msg, wParam, lParam);
break;
}
case WM_IME_SETCONTEXT:
{
HWND hwndIME;
hwndIME = DefWndImmGetDefaultIMEWnd(hWnd);
if (hwndIME)
Result = DefWndImmIsUIMessageA(hwndIME, Msg, wParam, lParam);
break;
}
/* fall through */
default:
Result = User32DefWindowProc(hWnd, Msg, wParam, lParam, FALSE);
}
SPY_ExitMessage(SPY_RESULT_DEFWND, hWnd, Msg, Result, wParam, lParam);
return Result;
}
只要一深入到用户对象, 就进入了win32k子系统层
windows消息定义 win32k层
static MSGMEMORY MsgMemory[] =
{
{ WM_CREATE, MMS_SIZE_SPECIAL, MMS_FLAG_READWRITE },
{ WM_DDE_ACK, sizeof(KMDDELPARAM), MMS_FLAG_READ },
{ WM_DDE_EXECUTE, MMS_SIZE_WPARAM, MMS_FLAG_READ },
{ WM_GETMINMAXINFO, sizeof(MINMAXINFO), MMS_FLAG_READWRITE },
{ WM_GETTEXT, MMS_SIZE_WPARAMWCHAR, MMS_FLAG_WRITE },
{ WM_NCCALCSIZE, MMS_SIZE_SPECIAL, MMS_FLAG_READWRITE },
{ WM_NCCREATE, MMS_SIZE_SPECIAL, MMS_FLAG_READWRITE },
{ WM_SETTEXT, MMS_SIZE_LPARAMSZ, MMS_FLAG_READ },
{ WM_STYLECHANGED, sizeof(STYLESTRUCT), MMS_FLAG_READ },
{ WM_STYLECHANGING, sizeof(STYLESTRUCT), MMS_FLAG_READWRITE },
{ WM_COPYDATA, MMS_SIZE_SPECIAL, MMS_FLAG_READ },
{ WM_COPYGLOBALDATA, MMS_SIZE_WPARAM, MMS_FLAG_READ },
{ WM_WINDOWPOSCHANGED, sizeof(WINDOWPOS), MMS_FLAG_READ },
{ WM_WINDOWPOSCHANGING, sizeof(WINDOWPOS), MMS_FLAG_READWRITE },
};