windows api,一个窗体激活的时候给另外一个发消息
view plaincopy to clipboardprint?
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication43
{
public partial class Form1 : Form
{
Form frm =null;
public Form1()
{
InitializeComponent();
this.Activated += Form_Activated;
}
const int WM_NCACTIVATE = 0x86;
const int WA_ACTIVE = 0x1;
[DllImport("user32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
private void button1_Click(object sender, EventArgs e)
{
frm = new Form();
frm.Text = "jinjazz";
frm.Activated += Form_Activated;
frm.Show();
frm.Location = new System.Drawing.Point(this.Left + this.Width, this.Top);
SendMessage(this.Handle, WM_NCACTIVATE, WA_ACTIVE, 0);
}
void Form_Activated(object sender, EventArgs e)
{
SendMessage(this.Handle, WM_NCACTIVATE, WA_ACTIVE, 0);
if (frm != null)
SendMessage(frm.Handle, WM_NCACTIVATE, WA_ACTIVE, 0);
}
}
}
本文介绍了一个使用C#实现的Windows窗体应用程序示例,该示例演示了如何在一个窗体被激活时通过Windows API向另一个窗体发送消息。通过调用`SendMessage`函数并指定特定的消息类型和参数,可以实现窗体间的交互。
1886

被折叠的 条评论
为什么被折叠?



