VB findwindowex 参数为数组里的值,怎么输入
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETTEXT = &HC
Private Sub Command1_Click()
Dim NotepadHwnd As Long, hwnd As Long
NotepadHwnd = FindWindow("notepad", vbNullString)
hwnd = FindWindowEx(NotepadHwnd, 0, "Edit", vbNullString) '得到窗口类名为Edit的窗口句柄
SendMessage hwnd, WM_SETTEXT, 0, ByVal "123"
End Sub
Private Sub Form_Load()
Shell "notepad.exe", vbNormalFocus
End Sub
VB中findwindowex函数的用法。。
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 声明
_
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _
ByVal childAfter As IntPtr, _
ByVal lclassName As String, _
ByVal windowTitle As String) As IntPtr
End Function
相关例子:
'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.
vb 隐藏已知句柄的窗口 & vb FindWindowEx的用法
Public Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Long, ByVal nCmdShow As Long) 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
'以上两个申明放标准模块中。
ShowWindow a,0 '0隐藏,5显示。
hWindow = FindWindowEx(b, 0, "SHELLDLL_DefView", "")
以下一个实例共参考
利用VB完全控制你的桌面图标
Windows中的桌面图标的排列方式是否让你感到厌倦而想按照自己的想法排列图标。是否想改变桌面图标文字的背景而不
使在图标文字下出现一个个难看的色块。这里我要介绍如何通过VB来对桌面的图标进行彻底的改变。
其实在Windows下的桌面以及任务栏等都是窗口对象,我们可以利用Windows API函数FindWindow和FindWindowEx来获得
它们的句柄,然后再调用其它相应的API函数来控制它们。而放置桌面图标的窗口是一个ListView对象,利用SendMessage函数
向该窗口发送相应的消息,就可以对图标进行修改了。下面是具体的程序实现。
首先在VB中建立一个新的工程,在Form1中加入三个CommandButton控件,然后在Form1的代码窗口中加入以下代码:
Option Explicit
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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
Private Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) _
As Long
Private Declare Function SendMessageP Lib "user32" Alias "SendMessageA" (ByVal _
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) _
As Long
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function SetSysColors Lib "user32" (ByVal nChanges As Long, _
lpSysColor As Long, lpColorValues As Long) As Long
Const LVM_FIRST = &H1000
Const LVM_GETITEMCOUNT = LVM_FIRST + 4
Const LVM_SETTEXTCOLOR = LVM_FIRST + 36
Const LVM_REDRAWITEMS = LVM_FIRST + 21
Const LVM_SETTEXTBKCOLOR = LVM_FIRST + 38
Const LVM_SETITEMPOSITION = LVM_FIRST + 15
Const COLOR_DESKTOP = 1
'RestoreColor函数回复默认的图标文字颜色和背景
Sub RestoreColor()
Dim lColor As Long
lColor = GetSysColor(COLOR_DESKTOP)
SetSysColors 1, COLOR_DESKTOP, lColor
End Sub
Sub SetIconText(clFore, clBack As Long, bTrans As Boolean)
Dim hWindow As Long
Dim lItemCount As Long
'通过三步查找到放置桌面图表的窗口
hWindow = FindWindow("Progman", "Program Manager")
hWindow = FindWindowEx(hWindow, 0, "SHELLDLL_DefView", "")
hWindow = FindWindowEx(hWindow, 0, "SysListView32", "")
If bTrans Then '透明背景
SendMessage hWindow, LVM_SETTEXTBKCOLOR, 0, &HFFFFFFFF
Else '非透明背景
SendMessage hWindow, LVM_SETTEXTBKCOLOR, 0, clBack
End If
'设置图标文字的颜色
SendMessage hWindow, LVM_SETTEXTCOLOR, 0, clFore
'重新绘制所有的图标
lItemCount = SendMessage(hWindow, LVM_GETITEMCOUNT, 0, 0)
SendMessage hWindow, LVM_REDRAWITEMS, 0, lItemCount - 1
'更新窗口
UpdateWindow hWindow
End Sub
Sub ArrangeDesktopIcon(iWidth As Integer, iHeight As Integer)
Dim hWindow As Long
Dim i1, i2, i, iCount As Integer
Dim po As POINTAPI
'通过三步查找到放置桌面图表的窗口
hWindow = FindWindow("Progman", "Program Manager")
hWindow = FindWindowEx(hWindow, 0, "SHELLDLL_DefView", "")
hWindow = FindWindowEx(hWindow, 0, "SysListView32", "")
i1 = 20: i2 = 20
iCount = SendMessage(hWindow, LVM_GETITEMCOUNT, 0, 0)
For i = 0 To iCount - 1
po.x = i1: po.y = i2
'发送LVM_SETITEMPOSITION消息排列图标
Call SendMessage(hWindow, LVM_SETITEMPOSITION, i, i2 * 65536 + i1)
i1 = i1 + iWidth
If i1 > ((Screen.Width / 15) - 32) Then
i1 = 20
i2 = i2 + iHeight
End If
Next i
SendMessage hWindow, LVM_REDRAWITEMS, 0, iCount - 1
'更新窗口
UpdateWindow hWindow
End Sub
Private Sub Command1_Click()
'设置图标文字的颜色为蓝色,背景色为黑色,背景为透明
SetIconText vbBlue, vbBlack, True
End Sub
Private Sub Command2_Click()
RestoreColor
End Sub
Private Sub Command3_Click()
'以100x100像素为单位排列图标
ArrangeDesktopIcon 100, 100
End Sub
Private Sub Form_Load()
Command1.Caption = "设置文字背景"
Command2.Caption = "恢复文字背景"
Command3.Caption = "排列桌面图标"
End Sub
运行程序,点击Command1,可以看到桌面图标的文本景色变成了蓝色,如果你设置了桌面图片,还可以看到文字
的背景变成了透明的而不是在下面有一个难看的色块,点击Command2可以恢复Windows的默认设置,点击Command3可以
使你的桌面图标以横排的方式排列,不过前提是要将桌面图标的自动排列属性设置为False。
以上程序在VB6,Windows98,Windows2000下运行通过。
VB在已知句柄的窗口画圆并清除。
vb-画圆创建一个工程,窗口上面放一个PictureBox,大小相对大一些,将其ScaleMode属性设为3。然后放一个按钮,其中加入以下代码: '这段代码演示了如何使用VB的Circle方法绘制各种各样的圆。 Form1.Picture1.Circle (60, 60), 40, vbRed '画一个圆心(60,60)半径40的红色的圆(默认空心)Form1.Picture1.FillStyle = 0 '设定填充模式为实心 Form1.Picture1.FillColor = vbBlue '设定填充色蓝色 Form1.Picture1.Circle (190, 60), 40, vbRed '下来画出来的就是填充了实心蓝色的圆了Form1.Picture1.DrawWidth = 3 '设定边框宽度为3 Form1.Picture1.Circle (60, 190), 40, vbRed '这次绘制出来的圆边框粗细为3 Form1.Picture1.DrawStyle = 5 '设定边框不可见 Form1.Picture1.FillColor = vbRed '设定填充色红色 Form1.Picture1.Circle (190, 190), 40 '这次绘制出来一个无边框、填充颜色是红色的圆 Form1.Picture1.Refresh然后试试看,对照注释应该就明白了。