在继承的窗体中,可以重写WndProc方法。
但我现在要做一个控件,通过Form f=this.FindForm()来获得控件在窗体
而且我还想重写f的WndProc方法,但这个方法是受保护的虚方法,不在派生类中,无法看到。这时该如何做?
但我现在要做一个控件,通过Form f=this.FindForm()来获得控件在窗体
而且我还想重写f的WndProc方法,但这个方法是受保护的虚方法,不在派生类中,无法看到。这时该如何做?
解决方案 »
- 各位大神啊!请为小弟解决一个很棘手很诡异的问题吧!标题继续长。。。。。。。。。。。。。
- C#中DataGridView选中行问题.. 疑惑半天了.. 在线求解..急...
- 关于.net打包的方法
- 【急】使用c#产生数据发往指定服务器
- 获得数组中值的类型
- 从数据库中读取控件的属性,然后对控件赋属性,这步如何做?
- 怎么用Session 做登陆状态跟踪? 急急急急急急!!!100分求!!
- C# 能否实现从C++的dll中LoadLibrary,调用其中的API返回Form显示
- 求一个正则表达式
- VS2017,怎么设置成这样:关闭启动web调试后自动打开的浏览器不退出调试
- C#(WinForm) + MySQL的中文编码问题(希望找到MySQL中文编码的终极解决方案)
- 泛型参数的构造函数的问题
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
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;
private IntPtr prevWndFunc;
private const int WM_MOUSEMOVE = 0x0200; private IntPtr newWndProc(IntPtr hWnd, int iMsg, IntPtr wParam, IntPtr lParam)
{
switch (iMsg)
{
case WM_MOUSEMOVE:
Text = "MouseMove: " + DateTime.Now.ToString();
break;
}
return CallWindowProc(prevWndFunc, hWnd, iMsg, wParam, lParam);
} private void Form1_Load(object sender, EventArgs e)
{
prevWndFunc = new IntPtr(GetWindowLong(button1.Handle, GWL_WNDPROC));
Text = prevWndFunc.ToString();
WndProcCallBack vWndProcCallBack = new WndProcCallBack(newWndProc);
SetWindowLong(button1.Handle, GWL_WNDPROC,
Marshal.GetFunctionPointerForDelegate(vWndProcCallBack).ToInt32());
} private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
SetWindowLong(button1.Handle, GWL_WNDPROC, prevWndFunc.ToInt32());
prevWndFunc = IntPtr.Zero;
}
}
}
有没有不调用API的方法?
不过不要记 ReleaseHandle(); 否则会出怪异的问题。以前VS2002写过,现在找不到了已经