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

[AU3基础] [已解决]如何通过外拖,获取文件夹(含桌面)真实路径?

[复制链接]
发表于 2024-5-10 13:02:00 | 显示全部楼层 |阅读模式
本帖最后由 顽固不化 于 2024-5-10 19:58 编辑

按照《windows Finder》瞎编一段代码,意思是想获取一个打开的文件夹窗口的标题(路径),但发现用_WinAPI_WindowFromPoint获取到的句柄是窗口控件的句柄,不知哪位大师能指点一二,不胜感激。

#NoTrayIcon
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPISysWin.au3>
Local $Search = False
Global $g_tStruct = DllStructCreate($tagPOINT)
$Form1 = GUICreate("Form1", 436, 131,-1, -1,-1,$WS_EX_TOPMOST)
$Label1 = GUICtrlCreateLabel("标题", 48, 16, 36, 17)
$Label2 = GUICtrlCreateLabel("句柄", 48, 48, 36, 17)
$Label3 = GUICtrlCreateLabel("类名", 48, 80, 36, 17)
$Input1 = GUICtrlCreateInput("", 80, 16, 337, 21)
$Input2 = GUICtrlCreateInput("", 80, 48, 337, 21)
$Input3 = GUICtrlCreateInput("", 80, 80, 337, 21)
$ico=GUICtrlCreateIcon(@SystemDir&'\shell32.dll',-23,10,48,30,30)
GUISetState(@SW_SHOW)

GUIRegisterMsg ($WM_LBUTTONUP, "_check")
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case  $ico
                        $Search=True
                        DllCall("user32.dll", "hwnd", "SetCapture", "hwnd", $Form1)
        EndSwitch
WEnd
Func Position()
        DllStructSetData($g_tStruct, "x", MouseGetPos(0))
        DllStructSetData($g_tStruct, "y", MouseGetPos(1))
EndFunc   ;==>Po
Func _check()
        $Search = False
        DllCall("user32.dll", "int", "ReleaseCapture")
        Local $winHD=''
        Position()
        $winHD= _WinAPI_WindowFromPoint($g_tStruct)
        ;$winHD=_WinAPI_GetParent ( $winHD1 )
        GUICtrlSetData($Input1,_WinAPI_GetWindowText ( $winHD ))
        GUICtrlSetData($Input2,$winHD)
        $pClassName = DllStructCreate("char[256]")
    DllCall("user32.dll", "int", "GetClassName", "hwnd", $winHD, "ptr", DllStructGetPtr($pClassName), "int", 255)
        GUICtrlSetData($Input3,$pClassName)
EndFunc        

发表于 2024-5-10 19:29:02 | 显示全部楼层


#NoTrayIcon
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
;~ #include <WinAPISysWin.au3>
Local $Search = False
Global $g_tStruct = DllStructCreate($tagPOINT)
$Form1 = GUICreate("Form1", 436, 131, -1, -1, -1, $WS_EX_TOPMOST)
$Label1 = GUICtrlCreateLabel("标题", 48, 16, 36, 17)
$Label2 = GUICtrlCreateLabel("句柄", 48, 48, 36, 17)
$Label3 = GUICtrlCreateLabel("类名", 48, 80, 36, 17)
$Input1 = GUICtrlCreateInput("", 80, 16, 337, 21)
$Input2 = GUICtrlCreateInput("", 80, 48, 337, 21)
$Input3 = GUICtrlCreateInput("", 80, 80, 337, 21)
$ico = GUICtrlCreateIcon(@SystemDir & '\shell32.dll', -23, 10, 48, 30, 30)
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_LBUTTONUP, "_check")
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $ico
                        $Search = True
                        DllCall("user32.dll", "hwnd", "SetCapture", "hwnd", $Form1)
        EndSwitch
WEnd
Func Position()
        DllStructSetData($g_tStruct, "x", MouseGetPos(0))
        DllStructSetData($g_tStruct, "y", MouseGetPos(1))
EndFunc   ;==>Position
Func _check()
        $Search = False
        DllCall("user32.dll", "int", "ReleaseCapture")
        Local $winHD = '',$hParent
        Position()
        $winHD = _WinAPI_WindowFromPoint($g_tStruct)
        While 1
                $hParent = _WinAPI_GetParent($winHD)
                If $hParent = 0 Then ExitLoop
                $winHD = $hParent
        WEnd        
        ;$winHD=_WinAPI_GetParent ( $winHD1 )
        GUICtrlSetData($Input1, _WinAPI_GetWindowText($winHD))
        GUICtrlSetData($Input2, $winHD)
        ;$pClassName = DllStructCreate("char[256]")
        ;DllCall("user32.dll", "int", "GetClassName", "hwnd", $winHD, "ptr", DllStructGetPtr($pClassName), "int", 255)
        GUICtrlSetData($Input3, _WinAPI_GetClassName($winHD))
EndFunc   ;==>_check





评分

参与人数 1金钱 +50 收起 理由
顽固不化 + 50 赞一个!

查看全部评分

 楼主| 发表于 2024-5-10 19:42:29 | 显示全部楼层

高手,有效果,非常感谢,
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-2 20:26 , Processed in 0.078595 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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