比如我用SendMessage(handle1 , 5000 , 0 , 0)
然后我在消息循环中用什么语句识别是handle1发送的消息5000呢?其中handle1是一个BUTTON的句柄!
是SDK程序!谁帮下忙?谢谢!

解决方案 »

  1.   

    SendMessage是绕过消息队列直接发给WndProc的,消息循环里取不到,只能在handle1窗体的WndProc里去switch
      

  2.   

    handle1是一个button句柄,
    那么首先的处理message的代码应该在button的回调函数中完成
    在回调中加入:
    case 5000:
    ...
    break;
    就可以了
      

  3.   

    The SendMessage member function calls the window procedure directly and does not return until that window procedure has processed the message. This is in contrast to the PostMessage member function, which places the message into the window's message queue and returns immediately.
    在窗体的WndProc函数中对消息进行处理
      

  4.   

    上面说的都对,按照oldn_CC_bird的方法就行了
      

  5.   

    SendMessage是绕过消息队列直接发给WndProc的,消息循环里取不到,只能在handle1窗体的WndProc里去switch
    switch(message)
    case 5000:
    代码处理;
    break;
      

  6.   

    谢谢!如果按照oldn_CC_bird的方法,button的回调函数怎么写,怎么判断是button的回调函数呀?
      

  7.   

    不知道你的button是怎么来的
      

  8.   

    回调可以这样加
    LRESULT CALLBACK BtnProc(
      HWND hwnd,      // handle to window
      UINT uMsg,      // message identifier
      WPARAM wParam,  // first message parameter
      LPARAM lParam   // second message parameter
    )
    {
     switch (uMsg)
    {
     case 5000;
    ...
    break;
    ...
    }
    return DefWindowProc(...);
    }在窗口的init里加
    SetWindowLong(hBtnHandle, GWL_WNDPROC, BtnProc);
      

  9.   

    The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message. The PostMessage function, in contrast, posts a message to a thread's message queue and returns immediately. If the specified window was created by the calling thread, the window procedure is called immediately as a subroutine. If the specified window was created by a different thread, the system switches to that thread and calls the appropriate window procedure. Messages sent between threads are processed only when the receiving thread executes message retrieval code. The sending thread is blocked until the receiving thread processes the message. 
      

  10.   

    谢谢你!
    我的是SDK程序!LRESULT CALLBACK WndProc(HWND hwnd , UINT message, WPARAM wParam , LPARAM lParam) 

       switch(message) 
       { 
         case WM_CREATE: 
                handle = CreateWindow("button","New",WS_VISIBLE|WS_CHILD, 
                                          0,0,40,30,hwnd,(HMENU)2000,NULL,NULL);  
     SendMessage(handle, 5000, 0 , 0) ;   //我是在这里发送消息,那怎么捕获呢?
                break; 
        case WM_COMMAND: 
            { 
                             break ; 
            } 
       case  5000:                            //这样能捕获吗?该怎么捕获?
    {
        //do anything!
    }
         case WM_DESTROY : 
                PostQuitMessage(0) ;       
         default : 
                return  DefWindowProc(hwnd , message , wParam , lParam);  
       }    return (0) ; 
    }
      

  11.   

    case  5000:                          
    {
        if(hwnd != dlgwnd)//判断是否是你发的
         break;
    }
      

  12.   

    LRESULT CALLBACK BtnProc(
    HWND hwnd, // handle to window
    UINT uMsg, // message identifier
    WPARAM wParam, // first message parameter
    LPARAM lParam // second message parameter
    )
    {
    switch (uMsg)
    {
    case 5000;
    ...
    break;
    ...
    }
    return DefWindowProc(...);
    }LRESULT CALLBACK WndProc(HWND hwnd , UINT message, WPARAM wParam , LPARAM lParam)
    {
    switch(message)
    {
    case WM_CREATE:
    handle = CreateWindow("button","New",WS_VISIBLE|WS_CHILD,
    0,0,40,30,hwnd,(HMENU)2000,NULL,NULL);
    SetWindowLong(handle, GWL_WNDPROC, BtnProc);
    SendMessage(handle, 5000, 0 , 0) ; //我是在这里发送消息,那怎么捕获呢?
    break;
    case WM_COMMAND:
    {
    break ;
    }
    case WM_DESTROY :
    PostQuitMessage(0) ;
    default :
    return DefWindowProc(hwnd , message , wParam , lParam);
    }return (0) ;
    }这样就可以了
      

  13.   

    照我看,这里应该没有什么必要发送SendMessage(handle, 5000, 0 , 0),就把下面的case 5000:改成 case "BUTTON的ID":应该就可以以响应BUTTON的消息了。具体没试过,试试看行不行?
      

  14.   

    你用系统的窗口类创建的BUTTON
    系统已经准备好一个消息处理程序啦!
    这个WndProc不用你去管,是系统给你准备的
    你可以自己指定一个 可以用SetWindowLong来自己准备一个!
      

  15.   

    你用系统的窗口类创建的BUTTON
    系统已经准备好一个消息处理程序啦!
    这个WndProc不用你去管,是系统给你准备的
    你可以自己指定一个 可以用SetWindowLong来自己准备一个!
    谢谢!xiaoQ008(女人,是个坏东西,虚荣心是她们的重要组成部分!) :
    我大概明白你的意思!不过有几个不是很明白的地方,希望大家帮个忙!非常的感谢大家!不明白之处有:(1)就是如果要自己指定一个,那该怎么指定?
    毕竟这样:
      handle = CreateWindow("button","New",WS_VISIBLE|WS_CHILD,
                          0,0,40,30,hwnd,(HMENU)2000,NULL,NULL);
      SendMessage(handle, 5000, 0 , 0) ;
    这个handle还是button的,还是去调用系统的窗口函数?(2)如果是自己指定,那不就是一个应用程序里有两个回调函数,那可以吗?
    (3)SetWindowLong(handle, GWL_WNDPROC, BtnProc);这个函数的作用是什么?看了MSDN还是不是很明白?谢谢!!!谢谢!!!
      

  16.   

    回答
    第一个问题
    系统定义好的,自然不用你去调用,系统自己会处理所有BUTTON的消息!
    第二个问题
    可以
    第三个问题
    SetWindowLong,他的作用在MSDN写的很清楚
    他有3个参数
    如果把第2个参数设置为 GWL_WNDPROC
    则表示为窗口设置新的窗口过程,这种技术称为"窗口子类化"技术!
    该技术能够让应用程序给原有的窗口过程设置"钩子".以便在程序中首先用自定义的窗口过程处理一些感兴趣的消息,然后再将这些消息传递给原有的窗口过程(可能是系统为你提供的窗口过程)进行处理.
      

  17.   

    谢谢!明白了!
    但是我想做个实验判断是否是系统自己调用自己的回调函数处理BUTTON的消息!没有头续??
    大家有没有办法呀?判断系统自己的确调用的自己的回调函数处理BUTTON的消息
      

  18.   

    回调都是系统给你调的,没自己调的..
    自己可以提供一个回调安装在自己指定的window上..
      

  19.   

    你判断他干什么,系统都自动给你调用了,为何要判断呢!
    既然系统给你处理了,那它肯定调用自己的回调函数处理你的BUTTON消息!
      

  20.   

    这个回调函数是系统自己的回调函数还是BUTTON自己的回调函数?
    如果我是创建Combobox,那么也是去调用系统的回掉函数呀??
      

  21.   

    可能你能回调的理解有些问题
    LZ最好找本win32的基础编程之类的书看看
    应该有助于对这类问题的理解
    有一个window就有一个回调存在,回调都是系统调的。。