FindWindowEx

FindWindowEx是在視窗列表中尋找與指定條件相符的第一個子視窗 。

基本介紹

  • 外文名:FindWindowEx
  • 功能:尋找指定子視窗
  • 類別:計算機函式
  • 原型:HWND FindWindowEx
函式說明,函式功能,參數;,返回值,聲明,速查,相關例子,

函式說明

函式功能

在視窗列表中尋找與指定條件相符的第一個子視窗 。
該函式獲得一個視窗的句柄,該視窗的類名和視窗名與給定的字元串相匹配。這個函式查找子視窗,從排在給定的子視窗後面的下一個子視窗開始。在查找時不區分大小寫。

參數;

(1)hwndParent:要查找的子視窗所在的視窗句柄(如果設定了hwndParent,則表示從這個hwndParent指向的父視窗中搜尋子視窗)。
如果hwndParent為 0 ,則函式以桌面視窗為父視窗,查找桌面視窗的所有子視窗。
Windows NT5.0 and later:如果hwndParent是HWND_MESSAGE,函式僅查找所有訊息視窗。
(2)hwndChildAfter :子視窗句柄。查找從在Z序中的下一個子視窗開始。子視窗必須為hwndParent視窗的直接子視窗而非後代視窗。如果HwndChildAfter為NULL,查找從hwndParent的第一個子視窗開始。如果hwndParent 和 hwndChildAfter同時為NULL,則函式查找所有的頂層視窗及訊息視窗。
(3)lpszClass:指向一個指定了類名的空結束字元串,或一個標識類名字元串的成員的指針。如果該參數為一個成員,則它必須為前次調用theGlobaIAddAtom函式產生的全局成員。該成員為16位,必須位於lpClassName的低16位,高位必須為0。
(4)lpszWindow:指向一個指定了視窗名(視窗標題)的空結束字元串。如果該參數為 NULL,則為所有視窗全匹配。

返回值

Long,找到的視窗的句柄。如未找到相符視窗,則返回零。會設定GetLastError
如果函式成功,返回值為具有指定類名和視窗名的視窗句柄。如果函式失敗,返回值為NULL。
若想獲得更多錯誤信息,請調用GetLastError函式。

聲明

1.VB 聲明
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
2.C# 聲明
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
3.VB .NET 聲明
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _
ByVal childAfter As IntPtr, _
ByVal lclassName As String, _
ByVal windowTitle As String) As IntPtr
End Function

速查

NT:4.0對以上版本;Windows:95以上版本;Windows CE:不支持;頭檔案:winuser.h;庫檔案:user32.lib;Unicode:在Windows NT上實現為Unicode和ANSI兩種版本。

相關例子

'Example Name: Changing a VB Toolbar to a Rebar-Style Toolbar
BAS Moduel Code
Option Explicit
Public Const WM_USER= &H400
Public Const TB_SETSTYLE = WM_USER + 56
Public Const TB_GETSTYLE = WM_USER + 57
Public Const TBSTYLE_FLAT = &H800
Public Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Public Declare Function FindWindowEx Lib "user32" _
Alias "FindWindowExA" _
(ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
'--end block--'
' Form Code
Option Explicit
Private Sub Form_Load()
With Combo1
.Width = Toolbar1.Buttons("combo1").Width
.Top = (Toolbar1.Height - Combo1.Height) \ 2
.Left = Toolbar1.Buttons("combo1").Left
.AddItem "Black" ' Add colours for text.

相關詞條

熱門詞條

聯絡我們