比如 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);
}
我用以下代码没办法获得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);
}
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;
}