2011年7月4日 星期一

用視窗標題激活視窗

//最大化視窗無法使用
using System.Runtime.InteropServices;

[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern int FindWindow(string lpClassName, string
        lpWindowName);

[DllImport("user32.dll")]
static extern bool ShowWindow(int hWnd, int nCmdShow);

private void SetActiveWindow()
{
            //If the window state of the inactive window is maximize, this code doesn't work.
            int WINDOW_HANDLER = FindWindow(null, @"Piriform CCleaner");
            if (WINDOW_HANDLER == 0)
            { }
            else
            {
                ShowWindow(WINDOW_HANDLER, 3);
            }
}

沒有留言: