顽固不化 发表于 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")
    DllCall("user32.dll", "int", "GetClassName", "hwnd", $winHD, "ptr", DllStructGetPtr($pClassName), "int", 255)
      GUICtrlSetData($Input3,$pClassName)
EndFunc      

zghwelcome 发表于 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")
        ;DllCall("user32.dll", "int", "GetClassName", "hwnd", $winHD, "ptr", DllStructGetPtr($pClassName), "int", 255)
        GUICtrlSetData($Input3, _WinAPI_GetClassName($winHD))
EndFunc   ;==>_check





顽固不化 发表于 2024-5-10 19:42:29

zghwelcome 发表于 2024-5-10 19:29


高手,有效果,非常感谢,
页: [1]
查看完整版本: [已解决]如何通过外拖,获取文件夹(含桌面)真实路径?