如何遍历桌面上的所有窗口,一定给分

tele 2002-01-29 04:56:54
我想察看桌面是否打开了word,最好有源代码
...全文
183 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
skydg 2002-01-29
收藏
回复
shawls 2002-01-29
+

使用回调枚举窗体!
回复
tele 2002-01-29
结账,给分
回复
jett 2002-01-29
收藏
回复
playyuer 2002-01-29
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q183009
HOWTO: Enumerate Windows Using the WIN32 API (Q183009)
回复
uguess 2002-01-29
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Const SW_SHOWNORMAL = 1
Const WM_CLOSE = &H10
Const gcClassnameMSWord = "OpusApp"
Const gcClassnameMSExcel = "XLMAIN"
Const gcClassnameMSIExplorer = "IEFrame"
Const gcClassnameMSVBasic = "wndclass_desked_gsk"
Const gcClassnameNotePad = "Notepad"
Const gcClassnameMyVBApp = "ThunderForm"
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
'Ask for a Window title
Ret = InputBox("Enter the exact window title:" + Chr$(13) + Chr$(10) + "Note: must be an exact match")
'Search the window
WinWnd = FindWindow(vbNullString, Ret)
If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
'Show the window
ShowWindow WinWnd, SW_SHOWNORMAL
'Create a buffer
lpClassName = Space(256)
'retrieve the class name
RetVal = GetClassName(WinWnd, lpClassName, 256)
'Show the classname
MsgBox "Classname: " + Left$(lpClassName, RetVal)
'Post a message to the window to close itself
PostMessage WinWnd, WM_CLOSE, 0&, 0&
End Sub
回复
Azi03 2002-01-29
HWND BlurFindWindow(char* BlurTitleText)
{
HWND CurWindowHandle=GetTopWindow(NULL);
do
{
char TitleText[500];
GetWindowText(CurWindowHandle,TitleText,500);
if(!strncmp(TitleText,BlurTitleText,strlen(BlurTitleText)))
return CurWindowHandle;
}while((CurWindowHandle=GetNextWindow(CurWindowHandle,GW_HWNDNEXT))!=NULL);
return NULL;
}
这是一个用C编的函数,你可以参考,都用API,一样
回复
ferrytang 2002-01-29
Dim hToolbar As Long
'获的工具条窗口句柄
hToolbar = FindWindowEx(tb.hwnd,0&,"ToolBarWindow32",vbNullString)
你只要把ToolBarWindow32换成word窗体的类就可以了!
回复
tele 2002-01-29
你怎么吧msdn翻译了一下
有没有程序?
回复
ferrytang 2002-01-29
FindWindowEx

VB声明
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
说明
在窗口列表中寻找与指定条件相符的第一个子窗口
返回值
Long,找到的窗口的句柄。如未找到相符窗口,则返回零。会设置GetLastError
参数表
参数 类型及说明
hWnd1 Long,在其中查找子的父窗口。如设为零,表示使用桌面窗口(通常说的顶级窗口都被认为是桌面的子窗口,所以也会对它们进行查找)
hWnd2 Long,从这个窗口后开始查找。这样便可利用对FindWindowEx的多次调用找到符合条件的所有子窗口。如设为零,表示从第一个子窗口开始搜索
lpsz1 String,欲搜索的类名。零表示忽略
lpsz2 String,欲搜索的类名。零表示忽略

Top

回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7485

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2002-01-29 04:56
社区公告
暂无公告