根據窗體的Caption和Class獲取窗體的控制代碼

2021-06-03 13:55:22 字數 1155 閱讀 2812

private const int32 max_window_text = 1024;

private const int32 max_window_class = 1024;

private const uint32 gw_hwndnext = (uint32)2;

// private const uint32 gw_hwndfirst = 0;

private const uint32 gw_child = 5;

[dllimport("user32.dll")]

private static extern intptr getdesktopwindow();//獲得桌面上的控制代碼

[dllimport("user32.dll", charset = charset.auto)]

private static extern int32 getwindowtext(intptr hwnd, stringbuilder lpstring, int32 nmaxcount);//根據控制代碼獲取caption

[dllimport("user32.dll", charset = charset.auto)]

private static extern int32 getclassname(intptr hwnd, stringbuilder lpclassname, int32 nmaxcount);//根據控制代碼獲取class

[dllimport("user32.dll")]

private static extern intptr getwindow(intptr hwnd, uint32 ucmd);//檢索父窗體的控制代碼

public static string getwindowcaption(intptr handle)

public static string getwindowclass(intptr handle)

設計思路

1,需要呼叫的api ,在正個桌面窗體中查詢到所有窗體的控制代碼。

2,根據窗體控制代碼獲取窗體的catpion,

3,根據窗體控制代碼獲取窗體的class,

4,比對caption和class是否相等,

5,把相等的結果加入到陣列中。

6,還可以進行模糊查詢,用到string.contains()

窗體傳值中的顯示和關閉窗體

private showinfomsg form if this.form null 判斷是否例項化 form new showinfomsg form.show else if this.form.isdisposed 判斷子窗體是否關閉 from null 如果關閉先釋放資源 form new ...

VC 下WIN窗體和MFC窗體的區別

winform 是基於託管c 的,程式設計效率高,開發程式簡單方便,但需要.net支援。且計算機開機後首次執行需要.net支援的程式時需要載入.net執行庫,啟動速度較慢。mfc在進行設定後就可以生成只需要windows xp以下系統自帶的動態庫就可以執行了,相當於綠色軟體。win窗體 form 是...

有關模式窗體和無(非)模式窗體的區別

在客戶端和網頁的開發過程中,我們都會或多或少遇到過模式窗體和無 非 模式窗體 以下簡稱無模式窗體 在傳統的windows窗體開發過程中,對話方塊有兩種模式 模式窗體和無模式窗體。模式窗體為建立後,只能在當前窗體進行相關操作。除非關閉後,才能使得其他窗體獲得控制權。net 中建立呼叫方法為 form ...