在delphi中,我可以这样创建自己的消息,
const MY_MESSAGE = WM_USER+100;
procedure MyMessage(var Msg: TMessage); message MY_MESSAGE;
procedure TForm1.MyMessage(var Msg: TMessage);
begin
....
end;
在 c# 中我可以这样做
public static uint ms;
protected override void WndProc(ref Message m)
{
if(m.Msg == ms)
MessageBox.Show("example");
else
base.WndProc(ref m);
}
void Button1Click(object sender, EventArgs e)
{
PostMessage(HWND_BROADCAST,ms,IntPtr.Zero,IntPtr.Zero);
}
但我不想覆盖 WndProc(),我想创建自己的 MyMessage() 函数,当我发布消息时它会运行。
我该怎么做? 谢谢。
最佳答案
这是 Delphi 的一个特殊功能,C# 中没有类似功能。在 C# 中,您需要覆盖 WndProc()
。
关于c# - C# 是否具有与 Delphi 的消息关键字等效的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5707832/