首页
社区
课程
招聘
SendMessage(HWND_BROADCAST, uMsg, 0, 0)... 怎么没用?
2006-6-14 19:59 7659

SendMessage(HWND_BROADCAST, uMsg, 0, 0)... 怎么没用?

2006-6-14 19:59
7659
我用uMsg = RegisterWindowMessage("xxxxxxxx") 注册了一个窗口消息
然后用SendMessage(HWND_BROADCAST, uMsg, 0, 0)发送这个消息,
为什么别的窗口收不到啊?
谁能个我讲讲。 谢谢了!

[CTF入门培训]顶尖高校博士及硕士团队亲授《30小时教你玩转CTF》,视频+靶场+题目!助力进入CTF世界

收藏
点赞0
打赏
分享
最新回复 (7)
雪    币: 291
活跃值: (208)
能力值: ( LV12,RANK:210 )
在线值:
发帖
回帖
粉丝
thebutterfly 5 2006-6-15 12:28
2
0
你是发给另一个进程的窗口吗?如果是,那是因为别的窗口不认识这个消息,也不知道如何处理这个消息
雪    币: 208
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
yoshimitsu 2006-6-15 12:40
3
0
是发给其他窗口的哈。
但是我安装了一个WH_GETMESSAGE挂钩,
我想在挂钩函数里面处理这个消息。
但是挂钩函数根本收不到这个消息。
这是怎么回事呢。
请指教。
雪    币: 603
活跃值: (617)
能力值: ( LV12,RANK:660 )
在线值:
发帖
回帖
粉丝
prince 16 2006-6-15 14:28
4
0
用SPY++监视目标窗体,看它是否真的收到消息。
雪    币: 236
活跃值: (26)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
红火蚁 3 2006-6-16 10:37
5
0
找了个时间
给你把这个搞定了
首先说明以下
你在窗口Test中定义的消息
你想把它发送到GetMsg这个窗口中
TestMsg这个是个钩子Dll
TestDll是调用这个全局钩子的程序

首先你在Test中定义全局的消息
UINT uMsg = RegisterWindowMessage("xxx");
在它上面加上一个按扭Button1
(由于我是在那个getMsg的View类中定义的消息处理
所以我在按扭中要找到TestMsg的客户窗口
在按扭的消息处理函数中写上:
void CTestDlg::OnButton1()
{
        // TODO: Add your control notification handler code here
        if (uMsg == 0)
        {
                MessageBox(TEXT("NO message"));
                return ;
        }
        HWND hWnd = ::FindWindow(NULL, "无标题 - GetMsg");
        if (hWnd == NULL)
        {
                MessageBox(TEXT("No Window"));
                return ;
        }
        ::SetForegroundWindow(hWnd);
//找到客户窗口
        HWND hwnd = ::FindWindowEx(hWnd, NULL, "AfxFrameOrView42d", NULL);
        if (hwnd == NULL)
        {
                MessageBox(TEXT("没有找到客户窗口"));
        }
        CWnd *pWnd = CWnd::FromHandle(hwnd);
//发送消息
        pWnd->SendMessage(uMsg);
}
染后在来看看这个TestMsg程序
我在它的View里定义全局消息
UINT uMsg2 = ::RegisterWindowMessage("xxx");
在GetMsgView.h中定义
protected:
        //{{AFX_MSG(CGetMsgView)
                // NOTE - the ClassWizard will add and remove member functions here.
                //    DO NOT EDIT what you see in these blocks of generated code !
        //}}AFX_MSG
        afx_msg void OnMsg2();
        DECLARE_MESSAGE_MAP()

在GetMsgView.cpp中定义
BEGIN_MESSAGE_MAP(CGetMsgView, CView)
        //{{AFX_MSG_MAP(CGetMsgView)
                // NOTE - the ClassWizard will add and remove mapping macros here.
                //    DO NOT EDIT what you see in these blocks of generated code!
        //}}AFX_MSG_MAP
        // Standard printing commands
        ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
        ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
        ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
        ON_REGISTERED_MESSAGE(uMsg2, OnMsg2)//这个一定要用这个ON_REGISTERED_MESSAGE,其他的什么ON_MESSAGE是不行的,我就在这花了一些时间,最后在MSDN里查到了
END_MESSAGE_MAP()

void CGetMsgView::OnMsg2()
{
//消息处理
        MessageBox(TEXT("收到消息"));
}

在哪个TestMsg中写上
HHOOK g_hook = NULL;
UINT uMsg1 = ::RegisterWindowMessage("xxx");

LRESULT CALLBACK CallWndProc(
                                                  int nCode,      // hook code
                                                  WPARAM wParam,  // current-process flag
                                                  LPARAM lParam   // address of structure with message data
                                                )
{
    if (nCode == HC_ACTION)
        {
                CWPSTRUCT *pMsg = (CWPSTRUCT*)lParam;
                if (pMsg->message == uMsg1)
                {
                    MessageBox(NULL, TEXT("拦截到消息"), NULL, MB_OK);
                }
        }
        return CallNextHookEx(g_hook, nCode, wParam, lParam);
}

extern "C" _declspec(dllexport) void SetHook()
{
        g_hook = SetWindowsHookEx(
                                                          WH_CALLWNDPROC,        // type of hook to install
                                                          CallWndProc,     // address of hook procedure
                                                          theApp.m_hInstance,    // handle to application instance
                                                          0   // identity of thread to install hook for
                                                        );
        if (g_hook == NULL)
        {
                MessageBox(NULL, TEXT("failed Set Hook"), NULL, MB_OK);
                return ;
        }

}

extern "C" _declspec(dllexport) void EndHook()
{
        if (g_hook != NULL)
        {
       UnhookWindowsHookEx(g_hook);
           g_hook = NULL;
        }
}

然后你在哪个TestDll中加2个按扭
extern "C" _declspec(dllimport) void SetHook();
extern "C" _declspec(dllimport) void EndHook();

void CTestDllDlg::OnButton1()
{
        // TODO: Add your control notification handler code here
        SetHook();
}

void CTestDllDlg::OnButton2()
{
        // TODO: Add your control notification handler code here
        EndHook();
}

OK
雪    币: 208
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
yoshimitsu 2006-6-17 22:18
6
0
辛苦了红火蚁, 能加我QQ吗? 我想在QQ上和你聊聊。。
雪    币: 208
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
yoshimitsu 2006-6-17 22:19
7
0
忘了留QQ号,  QQ:260**** E-MAIL: liche*******
雪    币: 2367
活跃值: (756)
能力值: (RANK:410 )
在线值:
发帖
回帖
粉丝
小虾 10 2006-6-17 22:37
8
0
莫违规。
http://bbs.pediy.com/showthread.php?s=&threadid=27565
7. 别要求私下答复  
   不要随便留下Email或QQ,要求别人私下与你联系
游客
登录 | 注册 方可回帖
返回