Jump to content

_FileDisplayProperties() UDF


TehWhale
 Share

Recommended Posts

I wanted your opinions on this.

;===============================================================================
;
; Function Name:   _FileDisplayProperties
; Description::    Uses a DLL to call the properties window of a file
; Parameter(s):    $a_CallFile = The file to display the properties of
;                  $a_Wait = 1, wait until the user closes the dialog
;                            0, automatically return when it opens
; Requirement(s):  Shell32.dll
; Return Value(s): Returns the DLL call value, 1 if it was a success
; Author(s):       Alienware (Swift) and LarryDalooza
; Examples(s):
;                  #Include <File.au3>
;                  $FilePropReturnValue = _FileDisplayProperties(@ScriptFullPath)
;                  MsgBox(0, "_FileDisplayProperties return value", "The return value of _FileDisplayProperties is: " & $FilePropReturnValue)
;
;===============================================================================

Func _FileDisplayProperties($sCallFile, $iWait = 1)
    If Not FileExists($sCallFile) Then Return SetError(1, 0, 0)
    Local $iReturn = DllCall("shell32.dll", "int", _
            "SHObjectProperties", "hwnd", 0, "dword", 0x00000002, _
            "wstr", $sCallFile, "wstr", 0)
    If $iWait = 1 Then
        $bOriginalOpt = Opt("WinTitleMatchMode", 2)
        WinWaitActive("Properties", "Cancel")
        WinWaitClose("Properties", "Cancel")
        Opt("WinTitleMatchMode", $bOriginalOpt)
    EndIf
    Return $iReturn[0]
EndFunc   ;==>_FileDisplayProperties

I think that it should be included in the File.au3 file, included with the AutoIt3 Install set.

What do you think?

Edited by Alienware
Link to comment
Share on other sites

Hmm, that works, when you have 1 as the $iWait. If you have anything else, it just goes into a infinity loop?

And never returns?

I tried JScript's version and worked great with 0 or 1.

I'm on XP w/ SP3.

Edit: Think I found the problem with JScript's version:

The WinWaitActive() is actually case sensitive.

If I call the fuction with _FileDisplayProperties("c:\ test.txt",0)

The properties window title starts with Test.text and the WinWaitActive never returns true.

Fix the function by changing

$bOriginalOpt = Opt("WinTitleMatchMode",2)

to

$bOriginalOpt = Opt("WinTitleMatchMode",-2)

Changed the Match mode to -2.

Edited by ResNullius
Link to comment
Share on other sites

Another solution:

_ShowFileProperties("c:\boot.ini")

Func _ShowFileProperties($sFile, $sVerb = "properties", $hWnd = 0)
    If Not FileExists($sFile) Then Return SetError(1, 0, 0)
    
    Local Const $SEE_MASK_INVOKEIDLIST = 0xC
    Local Const $SEE_MASK_NOCLOSEPROCESS = 0x40
    Local Const $SEE_MASK_FLAG_NO_UI = 0x400
    
    Local $PropBuff, $FileBuff, $SHELLEXECUTEINFO
    
    $PropBuff = DllStructCreate("char[256]")
    DllStructSetData($PropBuff, 1, $sVerb)
    
    $FileBuff = DllStructCreate("char[256]")
    DllStructSetData($FileBuff, 1, $sFile)
    
    $SHELLEXECUTEINFO = DllStructCreate("int cbSize;long fMask;hwnd hWnd;ptr lpVerb;ptr lpFile;ptr lpParameters;ptr lpDirectory;" & _
                                        "int nShow;int hInstApp;ptr lpIDList;ptr lpClass;hwnd hkeyClass;int dwHotKey;hwnd hIcon;" & _
                                        "hwnd hProcess")
                                        
    DllStructSetData($SHELLEXECUTEINFO, "cbSize", DllStructGetSize($SHELLEXECUTEINFO))
    DllStructSetData($SHELLEXECUTEINFO, "fMask", BitOR($SEE_MASK_NOCLOSEPROCESS, $SEE_MASK_INVOKEIDLIST, $SEE_MASK_FLAG_NO_UI))
    DllStructSetData($SHELLEXECUTEINFO, "hwnd", $hWnd)
    DllStructSetData($SHELLEXECUTEINFO, "lpVerb", DllStructGetPtr($PropBuff, 1))
    DllStructSetData($SHELLEXECUTEINFO, "lpFile", DllStructGetPtr($FileBuff, 1))
    
    $aRet = DllCall("shell32.dll", "int", "ShellExecuteEx", "ptr", DllStructGetPtr($SHELLEXECUTEINFO))
    If $aRet[0] = 0 Then Return SetError(2, 0, 0)
    
    Local $iPrevMode = Opt("WinTitleMatchMode", 2)
    Local $iTitle = StringRegExpReplace($sFile, "^.*\\(.*)\..*", "\1")
    
    WinWait($iTitle)
    
    Do
        Sleep(10)
    Until WinExists($iTitle) = 0
    
    Opt("WinTitleMatchMode", $iPrevMode)
    
    Return $aRet[0]
EndFunc

:P

Edited by rasim
Link to comment
Share on other sites

Another solution:

_ShowFileProperties("c:\boot.ini")

Func _ShowFileProperties($sFile, $sVerb = "properties", $hWnd = 0)
    If Not FileExists($sFile) Then Return SetError(1, 0, 0)
    
    Local Const $SEE_MASK_INVOKEIDLIST = 0xC
    Local Const $SEE_MASK_NOCLOSEPROCESS = 0x40
    Local Const $SEE_MASK_FLAG_NO_UI = 0x400
    
    Local $PropBuff, $FileBuff, $SHELLEXECUTEINFO
    
    $PropBuff = DllStructCreate("char[256]")
    DllStructSetData($PropBuff, 1, $sVerb)
    
    $FileBuff = DllStructCreate("char[256]")
    DllStructSetData($FileBuff, 1, $sFile)
    
    $SHELLEXECUTEINFO = DllStructCreate("int cbSize;long fMask;hwnd hWnd;ptr lpVerb;ptr lpFile;ptr lpParameters;ptr lpDirectory;" & _
                                        "int nShow;int hInstApp;ptr lpIDList;ptr lpClass;hwnd hkeyClass;int dwHotKey;hwnd hIcon;" & _
                                        "hwnd hProcess")
                                        
    DllStructSetData($SHELLEXECUTEINFO, "cbSize", DllStructGetSize($SHELLEXECUTEINFO))
    DllStructSetData($SHELLEXECUTEINFO, "fMask", BitOR($SEE_MASK_NOCLOSEPROCESS, $SEE_MASK_INVOKEIDLIST, $SEE_MASK_FLAG_NO_UI))
    DllStructSetData($SHELLEXECUTEINFO, "hwnd", $hWnd)
    DllStructSetData($SHELLEXECUTEINFO, "lpVerb", DllStructGetPtr($PropBuff, 1))
    DllStructSetData($SHELLEXECUTEINFO, "lpFile", DllStructGetPtr($FileBuff, 1))
    
    $aRet = DllCall("shell32.dll", "int", "ShellExecuteEx", "ptr", DllStructGetPtr($SHELLEXECUTEINFO))
    If $aRet[0] = 0 Then Return SetError(2, 0, 0)
    
    Local $iPrevMode = Opt("WinTitleMatchMode", 2)
    Local $iTitle = StringRegExpReplace($sFile, "^.*\\(.*)\..*", "\1")
    
    WinWait($iTitle)
    
    Do
        Sleep(10)
    Until WinExists($iTitle) = 0
    
    Opt("WinTitleMatchMode", $iPrevMode)
    
    Return $aRet[0]
EndFunc

:D

That one must of took some work! ;)

Thanks for your help guys.

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...