Jump to content

Elevated Drag & Drop


Nine
 Share

Recommended Posts

I spent few hours trying to figure out how to get results from the _WinAPI_DragQueryPoint when the script runs on elevated rights with a WM_DROPFILES registered message.  I searched everywhere but I wasn't able to find the right message to allow on my GUI.  So I finally decided to allow all messages under 0x400, to finally find THE ONE that makes it work.  It was really a surprise to find out that it is $WM_NCHITTEST !!!

To test you start Windows  Explorer and you simply Drag & Drop anywhere into the GUI.  If you remove any of the _WinAPI_ChangeWindowMessageFilterEx it will not fully work.  Anyway since I was not able to find it on the Web may as well document it here.

#include <GUIConstantsEx.au3>
#include <WinAPIEx.au3>
#include <WindowsConstants.au3>
#RequireAdmin

Global $hGUI = GUICreate('WM_DROPFILES', 400, 200, -1, -1, -1, $WS_EX_ACCEPTFILES)
GUISetState()
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES")

_WinAPI_ChangeWindowMessageFilterEx($hGUI, $WM_NCHITTEST, $MSGFLT_ALLOW)
_WinAPI_ChangeWindowMessageFilterEx($hGUI, $WM_DROPFILES, $MSGFLT_ALLOW)
_WinAPI_ChangeWindowMessageFilterEx($hGUI, $WM_COPYGLOBALDATA, $MSGFLT_ALLOW)
;_WinAPI_ChangeWindowMessageFilterEx ($hGUI, $WM_COPYDATA, $MSGFLT_ALLOW) ; useless ?

While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Exit
  EndSwitch
WEnd

Func WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam)
  #forceref $iMsg, $lParam
  Local $aFileList
  Switch $hWnd
    Case $hGUI
      $tPoint = _WinAPI_DragQueryPoint($wParam)
      $iXpos = DllStructGetData($tPoint, 1)
      $iYpos = DllStructGetData($tPoint, 2)
      ConsoleWrite ($iXpos & "/" & $iYpos & @CRLF)
      $aFileList = _WinAPI_DragQueryFileEx($wParam)
      If IsArray($aFileList) Then
        For $i = 1 To $aFileList[0]
          ConsoleWrite($aFileList[$i] & @CRLF)
        Next
      EndIf
      _WinAPI_DragFinish($wParam)
      Return 0
  EndSwitch
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DROPFILES

Tested on Win7.

Link to comment
Share on other sites

Thanks for sharing.

Had to remove #RequireAdmin for it to write to the console for me - Win 7 32 bit. Shows up in my added msgbox though, with or without.

If I recall rightly, drag & drop with the usual function does not work when #RequireAdmin is used, so very good that it can with your function/code.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

16 minutes ago, TheSaint said:

Had to remove #RequireAdmin for it to write to the console for me

Spoiler
#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Compile_Both=y
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WinAPIEx.au3>
#include <WindowsConstants.au3>

Global $hGUI = GUICreate('WM_DROPFILES', 400, 200, -1, -1, -1, $WS_EX_ACCEPTFILES)
Global $edit = GUICtrlCreateEdit("", 0, 100, 400, 100) ; I cheat it TheSaint  =P
GUISetState()
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES")

_WinAPI_ChangeWindowMessageFilterEx($hGUI, $WM_NCHITTEST, $MSGFLT_ALLOW)
_WinAPI_ChangeWindowMessageFilterEx($hGUI, $WM_DROPFILES, $MSGFLT_ALLOW)
_WinAPI_ChangeWindowMessageFilterEx($hGUI, $WM_COPYGLOBALDATA, $MSGFLT_ALLOW)
;_WinAPI_ChangeWindowMessageFilterEx ($hGUI, $WM_COPYDATA, $MSGFLT_ALLOW) ; useless ?

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $lParam
    Local $aFileList, $sFileList
    Switch $hWnd
        Case $hGUI
            $tPoint = _WinAPI_DragQueryPoint($wParam)
            $iXpos = DllStructGetData($tPoint, 1)
            $iYpos = DllStructGetData($tPoint, 2)
            ConsoleWrite($iXpos & "/" & $iYpos & @CRLF)
            $aFileList = _WinAPI_DragQueryFileEx($wParam)
            If IsArray($aFileList) Then
                For $i = 1 To $aFileList[0]
                    ConsoleWrite($aFileList[$i] & @CRLF)
                    $sFileList &= $aFileList[$i] & @CRLF
                Next
                GUICtrlSetData($edit, $sFileList)
            EndIf
            _WinAPI_DragFinish($wParam)
            Return 0
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DROPFILES

 

:P 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

I suspected as much. :P 

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...