reactos操作系统实现(178)

SendMessageW函数主要用来向窗口发送消息。下面就是它的实现代码

#001 LRESULT WINAPI

#002 SendMessageW(HWND Wnd,

#003 UINT Msg,

#004 WParaM wParam,

#005 LParaM lParam)

#006 {

#007 MSG UMMsg,KMMsg;

#008 NTUSERSENDMESSAGEINFO Info;

#009 LRESULT Result;

#010

如果不是广播消息,并且在合适范围的消息,就可以直接发送过去。

#011 if (Wnd != HWND_broADCAST && (Msg < WM_DDE_FirsT || Msg > WM_DDE_LAST))

#012 {

#013 PWINDOW Window;

获取当前线程的结构。

#014 PW32THREADINFO ti = GetW32ThreadInfo();

#015

检查窗口句柄是否有效,并获取窗口指针。

#016 Window = ValidateHwnd(Wnd);

#017 if (Window != NULL && SharedPtrToUser(Window->ti) == ti && !IsThreadHooked(ti))

#018 {

#019 /* NOTE: We can directly send messages to the window procedure

#020 if *all* the following conditions are met:

#021

#022 * Window belongs to calling thread

#023 * The calling thread is not being hooked

#024 */

#025

直接发送给窗口处理函数

#026 return IntCallMessageProc(Window,Wnd,Msg,wParam,lParam,FALSE);

#027 }

#028 }

#029

填写消息结构。

#030 UMMsg.hwnd = Wnd;

#031 UMMsg.message = Msg;

#032 UMMsg.wParam = wParam;

#033 UMMsg.lParam = lParam;

执行进程间的通讯消息,主要是WM_DDE_ACKWM_DDE_EXECUTEWM_copYDATA

#034 if (! MsgiUMToKMMessage(&UMMsg,&KMMsg,FALSE))

#035 {

#036 return FALSE;

#037 }

#038 Info.Ansi = FALSE;

调用内核函数NtUserSendMessage来发送消息给窗口。

#039 Result = NtUserSendMessage(KMMsg.hwnd,KMMsg.message,

#040 KMMsg.wParam,KMMsg.lParam,&Info);

#041 if (! Info.HandledByKernel)

#042 {

如果内核发送不成功,就需要直接调用窗口消息函数

#043 MsgiUMToKMCleanup(&UMMsg,&KMMsg);

#044 /* We need to send the message ourselves */

#045 Result = IntCallWindowProcW(Info.Ansi,Info.Proc,UMMsg.hwnd,UMMsg.message,

#046 UMMsg.wParam,UMMsg.lParam);

#047 }

#048 else if (! MsgiUMToKMReply(&UMMsg,&Result))

#049 {

#050 return FALSE;

#051 }

#052

#053 return Result;

#054}

相关文章

一、前言 在组件方面react和Vue一样的,核心思想玩的就是组件...
前言: 前段时间学习完react后,刚好就接到公司一个react项目...
前言: 最近收到组长通知我们项目组后面新开的项目准备统一技...
react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...