好久沒有寫博客了,最近在做項目時,客戶強烈要求同樣的報表不能出多個界面,要直接更改報表顯示的內容,然後就想到了之前做過一個使用C# 控制 Ctrl + alt + delete 的小程序,可以使用Win Api來控制,但是有些東西記的不太清楚了,所以又重新回顧了一下,先把目前用到的幾個先記錄下來.以後用到其它的再不斷的更新.

 

在使用C# 調用 Window Api

 

引用:using System.Runtime.InteropServices;

 

[DllImport("User32.dll", EntryPoint = "FindWindow")]

private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

 

[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

 

[DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Auto)]
private static extern int ShowWindow(IntPtr hWnd, int nCmdShow);

 

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);