up.我想windows的消息应该能标识消息发送者句柄的,可是找来找去没结果。

解决方案 »

  1.   

    这个只能通过m的后两个参数来确定,你自己在发送消息时将这些放入到后两个参数里就可以了。系统只会指出发送给谁(即接收方的句柄),MessageID(什么Message),后两个参数则是传输的数据,你可以通过它来区别。
      

  2.   

    举个例子,我在窗体上放置了100个panel,点击其中的一个panel,首先运行WndProc(ref Message m){},查看m,可以看到m中包含窗体句柄,具体消息内容,还有一个lparam和wparam。运行完WndProc后才开始运行panel的鼠标点击事件处理子程。调试了一下,发现点击不同panel产生的消息m,只有lparam不同,其他的都一样。怎么从这个lparam判断到底是哪个panel被点击了呢。谢谢。
      

  3.   

    以下是点击时产生的Message 我试了一下,有528和33,可以从528来得到
    if(m.Msg == 528)
    {
      请参看MSDN VC++中的WM_PARENTNOTIFY ,它的
    lParam参数在鼠标左键点下时为控件句柄WM_LBUTTONDOWN()
    Handle of the child window.}
      

  4.   

    to isaacyh(Ipig) 它的
    lParam参数在鼠标左键点下时为控件句柄
    我发现这个值和 MyControl.handle 对不上。
      

  5.   

    点击鼠标左键对应的WM_PARENTNOTIFY ,它的lParam参数有两种解释:
    1。 Handle of the child window.
    2。The x-coordinate of the cursor is the low-order word, and the y-coordinate of the cursor is the high-order word.
      

  6.   

    是的,我看到了,代码如下:protected override void WndProc(ref Message m)
    {
    if(!this.DesignMode)
    {
    if(m.Msg == 528)
    {
    try
    {
    if(m.WParam.ToString() == "513")
    {
    int i = m.LParam.ToInt32();
    string temps = Convert.ToString(i,16);
    string PointX = temps.Substring(temps.Length-4);
    string PointY = temps.Substring(0,temps.Length-4);
    Point p = new Point();
    p.X = Convert.ToInt32(PointX,16);
    p.Y = Convert.ToInt32(PointY,16);
    Panel temp = (Panel)this.GetChildAtPoint(p);
    MessageBox.Show(temp.Name);
    }
    }
    catch(Exception E)
    {
    string sss = E.Message;
    }
    }
    }
    base.WndProc (ref m);
    }
    }