使用Win API查找並關閉窗口


介紹 本文解釋了如何使用Win API查找和關閉窗口。 找到並關閉窗口 發現窗戶 FindWindow函數檢索頂級窗口的句柄,該頂級窗口的類名和窗口名與指定的字符串匹配。此函數不搜索子窗口。此函數不執行區分大小寫的搜索。 隱藏,復制Code

FindWindow(string lpClassName,string lpWindowName) 

使用spy++查找類名和窗口名 是一個基於win32的實用程序,它提供了系統進程、線程、窗口和窗口消息的圖形化視圖。使用窗口查找工具,您可以找到所選窗口的屬性。 步驟1:安排你的窗口,使Spy++和主題窗口可見。 第二步:從“間諜”菜單中,選擇“查找窗口”,打開“查找窗口”對話框。 第三步:拖動Finder工具到所需的窗口。當您拖動該工具時,對話框中將顯示窗口詳細信息。(句柄、標題(窗口名)、類名) 隱藏,復制Code

using Microsoft.Win32;

[DllImport("user32.dll")]
        public static extern int FindWindow(string lpClassName,string lpWindowName);
        [DllImport("user32.dll")]
        public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
            
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_CLOSE = 0xF060;

private void closeWindow()
        {
            // retrieve the handler of the window  
            int iHandle = FindWindow("Notepad", "Untitled - Notepad");
            if (iHandle > 0)
            {
                // close the window using API        
                SendMessage(iHandle, WM_SYSCOMMAND, SC_CLOSE, 0);
            }  
        }	

歷史 2007年12月19日:初任 本文轉載於:http://www.diyabc.com/frontweb/news8465.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM