SendMessageW函数主要用来向窗口发送消息。下面就是它的实现代码:
#001 LRESULT WINAPI
#002 SendMessageW(HWND Wnd,
#003 UINT Msg,
#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;
执行进程间的通讯消息,主要是WM_DDE_ACK,WM_DDE_EXECUTE,WM_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}
原文地址:https://www.jb51.cc/react/308343.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。