找回密码
 加入
搜索
查看: 2110|回复: 2

[AU3基础] [已解决]怎样在系统部署时获取正在运行的程序名或窗口名

[复制链接]
发表于 2010-11-12 10:59:01 | 显示全部楼层 |阅读模式
本帖最后由 学习一下 于 2010-11-15 11:58 编辑

在系统部署时怎样获取正在运行的程序名或窗口名(不是进程名),试用窗口管理函数来获取无效。

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-11-12 16:42:49 | 显示全部楼层
本帖最后由 yhxhappy 于 2010-11-12 16:46 编辑

不太明白楼主的意思,希望以下代码对你有帮助
#include <WinAPI.au3>
#Include <WinAPIEx.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

;创建主窗口
$GUI = GUICreate("EnumWindows",  1000, 700)

;绘制并生成数据表
$listview = GUICtrlCreateListView("", 15, 10, 970, 640)
        _GUICtrlListView_SetExtendedListViewStyle($listview, BitOR($LVS_REPORT, $LVS_EX_FULLROWSELECT)) 
        _GUICtrlListView_AddColumn($listview, "窗口句柄", 85)
        _GUICtrlListView_AddColumn($listview, "窗口标题", 450)
        _GUICtrlListView_AddColumn($listview, "窗口文本", 250)
        ;_GUICtrlListView_AddColumn($listview, "CLASS", 50)
        _GUICtrlListView_AddColumn($listview, "PID", 55)
        _GUICtrlListView_AddColumn($listview, "进程名称", 100)

;刷新按钮
$Installa_Button = GUICtrlCreateButton("刷新", 835, 655, 150, 35)        

AddListviewItem()
GUISetState()

While 1
    $msg = GUIGetMsg()
        Switch $Msg
        Case $GUI_EVENT_CLOSE
                Exit
        Case $Installa_Button
                AddListviewItem()
        EndSwitch
WEnd

        
Func AddListviewItem()
        _GUICtrlListView_DeleteAllItems($listview)
        $aWindows = _WinAPI_EnumWindows()
        For $i = 1 To $aWindows[0][0]
                $WindowHandle = $aWindows[$i][0]
                $WindowsClass = $aWindows[$i][1]
                $WindowTitle = WinGetTitle($aWindows[$i][0])
                $WindowText = WinGetText($aWindows[$i][0])
                $ProcessPID = WinGetProcess($aWindows[$i][0])
                $e = StringSplit(_WinAPI_GetModuleFileNameEx($ProcessPID), "")                          ;提取进程名称,也可以取进程的路径
                $ProcessName = $e[$e[0]]
                If $WindowTitle <> "" Then GUICtrlCreateListViewItem($WindowHandle & "|" & $WindowTitle& "|" & $WindowText & "|" & $ProcessPID & "|" & $ProcessName, $listview)                  ;如果窗口标题为空,则不添加进表格,去掉判断则会全部添加
        Next
EndFunc

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2010-11-15 11:57:48 | 显示全部楼层
回复 2# yhxhappy

谢谢你的帮助,在你的源码中找到了我需要的
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-3 00:29 , Processed in 0.084000 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表