1. using System; using System.Runtime.InteropServices;public delegate bool CallBack(int hwnd, int lParam);public class EnumReportApp { [DllImport("user32")] public static extern int EnumWindows(CallBack x, int y); public static void Main() { CallBack myCallBack = new CallBack(EnumReportApp.Report); EnumWindows(myCallBack, 0); } public static bool Report(int hwnd, int lParam) { Console.Write("Window handle is "); Console.WriteLine(hwnd); return true; } } 2.见FAG中 用SendMessage
2:给你个示例
public class MsgEventArgs : System.EventArgs
{
private string dataStr ;
public MsgEventArgs()
{}
}public class ExampleClass
{
public delegate void ExampleEventMsgHandler(object sender,MainFrame.MsgEventArgs e);
public event ExampleEventMsgHandler ExampleEvent; public void TigerEvent(){ MsgEventArgs msg = new MsgEventArgs ();
msg.dataStr = ...; if( ExampleEvent != null ){
ExampleEvent( null , msg );
}
}
}
//在这个类中定义了上面类的事件
public class ExampleEventClass
{
ExampleClass exa = new ExampleClass(); public ExampleEventClass ()
{
exa . ExampleEvent += new ExampleEventMsgHandler( EventProcess );
}
public void EventProcess (object sender,MainFrame.MsgEventArgs e){
//use e
//Controls.WriteLine( e.dataStr );
}
}
//供参考
你找一个没有系统的消息里面没有用过的数值,然后这样定义:
const int WM_MYMSG = 0x0101;
不过发送方和接收方要有同样的定义。
第二个问题好像kerlw(科尔)似乎已经了解了,问题是请问如何传送消息和接收消息
以上两个问题请都举例
using System;
using System.Runtime.InteropServices;public delegate bool CallBack(int hwnd, int lParam);public class EnumReportApp { [DllImport("user32")]
public static extern int EnumWindows(CallBack x, int y); public static void Main()
{
CallBack myCallBack = new CallBack(EnumReportApp.Report);
EnumWindows(myCallBack, 0);
} public static bool Report(int hwnd, int lParam) {
Console.Write("Window handle is ");
Console.WriteLine(hwnd);
return true;
}
}
2.见FAG中
用SendMessage