本文介绍了谁能告诉我,是我犯错误的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
公共部分类Form1中:形态
{
[的DllImport(coredll.dll中)]
静态外部INT的SetWindowLong(IntPtr的的HWND,国际nIndex,INT dwNewLong);
const int的GWL_WNDPROC = -4;
市民代表INT WindProc(IntPtr的的HWND,UINT味精,长期的wParam,长LPARAM);
公共Form1中()
{
的InitializeComponent();
WindProc SampleProc =新WindProc(SubclassWndProc);
SetWindowLong函数(这.handle的,GWL_WNDPROC,
SampleProc.Method .MethodHandle.Value.ToInt32());
}
公众诠释SubclassWndProc(IntPtr的HWND,UINT味精,长期的wParam,长LPARAM)
{
返回1;
}
下面是我试图采取一种形式的窗口过程的样品,我就是这样做的在C ++中,我得到了windwproc easlily如果我尝试用C#.net 3.5一样我无法得到窗口过程,,调用SetWindowLong函数API,应用程序挂起,它会弹出一些不发送报告后...我已阅读,这是方式来获得窗口过程..请让我知道是我作出错误...
解决方案
只需使用 SampleProc
。如果失败,尝试编组到 FunctionPointer
。
public partial class Form1 : Form
{
[DllImport("coredll.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
const int GWL_WNDPROC = -4;
public delegate int WindProc(IntPtr hWnd, uint msg, long Wparam, long lparam);
public Form1()
{
InitializeComponent();
WindProc SampleProc = new WindProc (SubclassWndProc);
SetWindowLong(this .Handle , GWL_WNDPROC,
SampleProc.Method .MethodHandle.Value.ToInt32());
}
public int SubclassWndProc(IntPtr hwnd, uint msg, long Wparam, long lparam)
{
return 1;
}
Here is the sample which i was trying to take the window procedure of a form, this is how i do in C++ i get the windwproc easlily if i try the same in C# .net 3.5 i am unable to get the window proc,, after calling SetWindowLong API application hangs and it pops up some dont send report... i have read this is the way to get the window proc.. please let me know were i am making mistake...
解决方案
Just use SampleProc
. If that fails, try marshalling it to a FunctionPointer
.
这篇关于谁能告诉我,是我犯错误的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!