我想订阅 Application 类的激活和取消激活事件,但似乎做错了什么。
一定是我做错了什么,因为它不起作用。我搜索了一些内容,找到了这个链接:http://www.csharphelp.com/2006/08/get-current-window-handle-and-caption-with-windows-api-in-c/,但是对于如此简单的任务来说,它似乎太复杂了。
我在 MSDN 上寻找了一些内容,最终尝试了这个链接:http://msdn.microsoft.com/en-us/library/ms366768.aspx,但还是不起作用...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace derp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Width = 250;
this.Height = 250;
this.Title = "derp";
Application app = new Application();
app.Activated += Active;
app.Activated += new EventHandler(Active);
}
void Active(object sender, EventArgs args)
{
//Do stuff
}
void Passive(object sender, EventArgs args)
{
//Do stuff
}
}
}