1、构造send_message_info结构体,然后调用send_message函数。 SendMessageA和SendMessageW的区别有两处:info.type一个是MSG_ASCII,一个是MSG_UNICODE;send_message函数的第三个参数一个为TRUE一个为FALSE。
LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
DWORD_PTR res = 0;
struct send_message_info info;
info.type = MSG_ASCII;
info.hwnd = hwnd;
info.msg = msg;
info.wparam = wparam;
info.lparam = lparam;
info.flags = SMTO_NORMAL;
info.timeout = 0;
info.wm_char = WMCHAR_MAP_SENDMESSAGE;
send_message( &info, &res, FALSE );
return res;
}
2、send_message
首先判断是不是广播消息,从is_broadcast函数代码来看,目的窗口句柄为HWND_BROADCAST或HWND_TOPMOST的是广播消息。对于广播消息,它使用EnumWindows通过回调函数broadcast_message_callback,将消息发给每一个窗体。
GetWindowThreadProcessId函数,通过目的窗口句柄获取窗口所在进程和线程id
如果目的窗口线程和当前发送线程相同,它直