ãã®åãhttp://d.hatena.ne.jp/gsf_zero1/20070509/p1 ã«ã¦Microsoft.VisualBasic.Interactionã
å©ç¨ãããµã³ãã«ãè¨è¿°ãã¾ããããååã®ãµã³ãã«ã§ã¯
ã¢ã¯ãã£ãã«ãããããã»ã¹ãæå°åç¶æ ã«ãªã£ã¦ããå ´åä½æ ãã¢ã¯ãã£ãã«åºæ¥ãªã
ã¨ããç¶æ ãç§ã®ç°å¢ã§ã¯èµ·ããã¾ããã»ã»ã
ã¦ãã¨ã§ãwin-apiãç´æ¥ã³ã¼ã«ãã¦å¦çããæ¹æ³ãããã¿ãããªã®ã§
以ä¸ã«ãµã³ãã«ãè¨è¿°ãã¾ãã
å©ç¨ããwin-apiã¯ã
ShowWindow(int hWnd, int nCmdShow); SetForegroundWindow(int hWnd);
ã®äºã¤ã§ãã
以ä¸ãµã³ãã«ã§ãã
using System; using System.Runtime.InteropServices; using System.Diagnostics; namespace Gsf.Samples.CSharp { class EntryPoint{ ///////////////////////////////////// // // å©ç¨ããwin-apiã®å®£è¨. // // [åç §URL] // â WinAPI Database for VB Programmer // http://www.winapi-database.com/Window/Change/index.html // // â C#,VB.NETå ¥é(äºéèµ·åãããæã«æ¢ã«èµ·åä¸ã®ã¢ããªã±ã¼ã·ã§ã³ãã¢ã¯ãã£ãã«ãã) // http://jeanne.wankuma.com/tips/process/activewindow.html // // ////// æå®ããã¦ã£ã³ãã¦ã®è¡¨ç¤ºç¶æ ãè¨å®ãã¾ãã /// /// ãã³ãã« /// 表示ç¶æ ///ç´åã«ã¦ã£ã³ãã¦ã表示ããã¦ããå ´å, 0以å¤ãããã§ãªãå ´åã¯0 [DllImport("user32.dll")] static extern int ShowWindow(IntPtr handle, int command); ////// æå®ããã¦ã£ã³ãã¦ãzãªã¼ãã¼ã®æåé¢ã«ç§»åããã¾ãã /// /// ãã³ãã« ///æ£å¸¸ï¼0以å¤, ãã以å¤:0 [DllImport("user32.dll")] static extern int SetForegroundWindow(IntPtr handle); ////// ShowWindowé¢æ°ã«ä½¿ç¨ããWindowç¶æ å¤ /// ////// å¤9ã¯ãwindowã®ç¶æ ã復å ãããã¨ãæå³ãã¾ãã /// const int SW_RESTORE = 9; ////// ã¢ã¯ãã£ãã«ããããã»ã¹å /// const string APP_NAME = "AFX"; ////// ã¢ããªã±ã¼ã·ã§ã³ã¡ã¤ã³ã¨ã³ããªãã¤ã³ãã¡ã½ããã§ãã /// ////// æ¢ã«èµ·åãã¦ããç¹å®ã®ããã»ã¹ãã¢ã¯ãã£ãã«ãã¾ãã /// /// ã»å®æ°APP_NAMEã«ã¢ã¯ãã£ãã«ãããããã»ã¹åãã»ãããã¦å®è¡ãã¦ãã ããã /// ã»ã¢ã¯ãã£ãã«ããããã»ã¹ãèµ·åãã¦ããªãã¨ä½ãèµ·ããã¾ããã /// static void Main(){ foreach(Process aProcess in Process.GetProcessesByName(APP_NAME)){ IntPtr handle = aProcess.MainWindowHandle; // // ã¦ã£ã³ãã¦ã®è¡¨ç¤ºç¶æ ã復å // ShowWindow(handle, SW_RESTORE); // // æåé¢ã«ã¦ã£ã³ãã¦ã移å // SetForegroundWindow(handle); } } } }