C 查詢視窗,FindWindow用法

2021-06-10 20:18:19 字數 1424 閱讀 6063

findwindow 用來根據類名和視窗名來得到視窗控制代碼的。但是這個函式不能查詢子視窗,也不區分大小寫。

如果要從乙個視窗的子視窗中查詢需要使用findwindowex。

函式原型:hwnd findwindowex(hwnd hwndparent,hwnd hwndchildafter,lpctstr lpszclass,lpctstr lpszwindow);

引數:hwndparent:要查詢子視窗的父視窗控制代碼。    如果hwnjparent為null,則函式以桌面視窗為父視窗,查詢桌面視窗的所有子視窗。    windows nt5.0 and later:如果hwndparent是hwnd_message,函式僅查詢所有訊息視窗。

hwndchildafter :子視窗控制代碼。查詢從在z序中的下乙個子視窗開始。子視窗必須為hwndparert視窗的直接子視窗而非後代視窗。如果hwndchildafter為null,查詢從hwndparent的第乙個子視窗開始。如果hwndparent 和 hwndchildafter同時為null,則函式查詢所有的頂層視窗及訊息視窗。

lpszclass:指向乙個指定了類名的空結束字串,或乙個標識類名字串的成員的指標。如果該引數為乙個成員,則它必須為前次呼叫theglobaiaddatom函式產生的全域性成員。該成員為16位,必須位於lpclassname的低16位,高位必須為0。

lpszwindow:指向乙個指定了視窗名(視窗標題)的空結束字串。如果該引數為 null,則為所有視窗全匹配。返回值:如果函式成功,返回值為具有指定類名和視窗名的視窗控制代碼。如果函式失敗,返回值為null。

c#中使用該函式首先匯入命名空間:

using system.runtime.interopservices;

然後寫api引用部分的**,放入 class 內部

//查詢窗體

[dllimport("user32.dll", entrypoint = "findwindow")]

public extern static intptr findwindow(string lpclassname, string lpwindowname);

[dllimport("user32.dll", entrypoint = "findwindowex")]

public static extern intptr findwindowex(intptr hwndparent, intptr hwndchildafter, string lpclassname, string lpwindowname);

例如:查詢qq2012視窗

private void button2_click(object sender, eventargs e)

else

}

C 查詢視窗,FindWindow用法

findwindow 用來根據類名和視窗名來得到視窗控制代碼的。但是這個函式不能查詢子視窗,也不區分大小寫。如果要從乙個視窗的子視窗中查詢需要使用findwindowex。函式功能 該函式獲得乙個視窗的控制代碼,該視窗的類名和視窗名與給定的字串相匹配。這個函式查詢子視窗,從排在給定的子視窗後面的下乙...

c 裡FindWindow的用法

findwindow 函式的用法。要在c 裡使用該api,寫出findwindow 函式的宣告 dllimport coredll.dll entrypoint findwindow private extern static intptr findwindow string lpclassname...

c 裡FindWindow的用法

findwindow 函式的用法。要在c 裡使用該api,寫出findwindow 函式的宣告 dllimport coredll.dll entrypoint findwindow private extern static intptr findwindow string lpclassname...