WndProc如何获得某个XX的消息。

wlllll 2008-02-08 01:58:45
比如 RichTextBox 的消息。
我用以下代码没办法获得RichTextBox 的消息,只能获得窗口的消息。没办法获得窗口内部件的消息。
protected override void WndProc(ref Message m) {
System.String MText = "";
MText += " m.Msg:" + m.Msg.ToString() + " ";
MText += " m.HWnd:" + m.HWnd.ToString() + " ";
MText += " m.LParam:" + m.LParam.ToString() + " ";
MText += " m.WParam:" + m.WParam.ToString() + " ";
MText += " m.Result:" + m.Result.ToString() + " ";
Console.WriteLine(MText);
base.WndProc(ref m);
}
...全文
59 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wlllll 2008-02-08
  • 打赏
  • 举报
回复
谁来回复一下,我好结帖。

无满意结帖,不知道怎么结不了。
wlllll 2008-02-08
  • 打赏
  • 举报
回复
this.Load += new System.EventHandler(this.Form1_Load);
this.Unload += new System.EventHandler(this.Form1_FormClosed);



#region *******************载入Dll文件信息*******************
//WindowPro监视
private delegate IntPtr WndProcCallBack(IntPtr hwnd, int Msg, IntPtr wParam, IntPtr lParam);

[DllImport("User32.dll ", SetLastError = true)]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("User32.dll ", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("User32.dll ")]
private static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
private const int GWL_WNDPROC = -4;
#endregion


private IntPtr newWndProc(IntPtr hWnd, int iMsg, IntPtr wParam, IntPtr lParam) {
System.String MText = "";
MText += " m.Msg:" + iMsg.ToString() + " ";
MText += " m.HWnd:" + hWnd.ToString() + " ";
MText += " m.LParam:" + lParam.ToString() + " ";
MText += " m.WParam:" + wParam.ToString() + " ";
Console.WriteLine(MText);
return CallWindowProc(prevWndFunc, hWnd, iMsg, wParam, lParam);
}


private IntPtr prevWndFunc;
private void Form1_Load(object sender, EventArgs e) {
prevWndFunc = new IntPtr(GetWindowLong(MyText.Handle, GWL_WNDPROC));
WndProcCallBack vWndProcCallBack = new WndProcCallBack(newWndProc);
SetWindowLong(MyText.Handle, GWL_WNDPROC,Marshal.GetFunctionPointerForDelegate(vWndProcCallBack).ToInt32());
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e) {
SetWindowLong(MyText.Handle, GWL_WNDPROC, prevWndFunc.ToInt32());
prevWndFunc = IntPtr.Zero;
}

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧