Sign in to follow this  
Followers 0
Yashied

Run Dialog Replacement

10 posts in this topic

#1 ·  Posted (edited)

LAST VERSION - 1.0

24-May-09

Project closed.

A simple script to replace the native Run dialog in Windows XP.

NoImage.png

Files to download

Binary

Redirection to Run_bin.zip, 431 KB

Run_bin.html

Source

To run this example you need to download >MRU UDF library.

Run.au3

Edited by Yashied

Share this post


Link to post
Share on other sites



#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         Yashied

 Script Function:
    Run Dialog.

#ce ----------------------------------------------------------------------------

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=Run.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Description=Opens a program, folder, document, or Web site
#AutoIt3Wrapper_Res_Fileversion=1.0
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Run_AU3Check=n
#AutoIt3Wrapper_Run_After=Utilities\ResHacker\ResHacker.exe -delete %out%, %out%, DIALOG, 1000,
#AutoIt3Wrapper_Run_After=Utilities\ResHacker\ResHacker.exe -delete %out%, %out%, MENU, 166,
#AutoIt3Wrapper_Run_After=Utilities\ResHacker\ResHacker.exe -delete %out%, %out%, ICON, 161,
#AutoIt3Wrapper_Run_After=Utilities\ResHacker\ResHacker.exe -delete %out%, %out%, ICON, 162,
#AutoIt3Wrapper_Run_After=Utilities\ResHacker\ResHacker.exe -delete %out%, %out%, ICON, 164,
#AutoIt3Wrapper_Run_After=Utilities\ResHacker\ResHacker.exe -delete %out%, %out%, ICON, 169,
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#NoTrayIcon

#Include <ComboConstants.au3>
#Include <GUIComboBoxEx.au3>
#Include <GUIConstantsEx.au3>
#Include <GUIEdit.au3>
#Include <Misc.au3>
#Include <WinAPI.au3>
#Include <WindowsConstants.au3>

#Include <MRU.au3>

Opt('MustDeclareVars', 1)
Opt('MouseCoordMode', 2)
Opt('WinTitleMatchMode', 3)

const $GUI_NAME = 'Run'
const $REG_KEY_NAME = 'HKCU\SOFTWARE\' & $GUI_NAME

const $GCL_HICON = -14
const $GCL_HICONSM = -34

const $WIN_LEFT_TOP = 0
const $WIN_RIGHT_TOP = 1
const $WIN_LEFT_BOTTOM = 2
const $WIN_RIGHT_BOTTOM = 3

const $WM_DROPFILES = 0x0233

if _Singleton('RunDlg', 1) = 0 then
    WinActivate('Run')
    exit
endif

local $Form, $GUIMsg, $Combo, $Input, $ButtonOk, $ButtonCancel, $ButtonBrowse
local $Cmd, $pCmd = '', $Parameters = StringStripWS(_RegRead($REG_KEY_NAME, 'Parameters', 'REG_SZ', ''), 3)
local $Mru = _MRU_Create($REG_KEY_NAME & '\MRU'), $Fn, $Path = @MyDocumentsDir
local $Width, $Height

; Main

if $CmdLine[0] > 0 then
    select
        case StringLower($CmdLine[1]) = '/reset'
            _MRU_Reset($Mru)
            _MRU_RegWrite($Mru)
            _MRU_Release($Mru)
            RegWrite($REG_KEY_NAME, 'Parameters', 'REG_SZ', '')
            exit
        case else
            $pCmd = $CmdLine[1]
            $Parameters = ''
    endselect
endif

CreateForm()

while 1
    $Cmd = GUICtrlRead($Combo)
    if $pCmd <> $Cmd then
        $pCmd = $Cmd
        GUICtrlSetData($Input, '')
    endif
    $GUIMsg = GUIGetMsg()
    select
        case ($GUIMsg = $ButtonCancel) or ($GUIMsg = $GUI_EVENT_CLOSE)
            _MRU_Release($Mru)
            exit
        case ($GUIMsg = $ButtonOk)
            $Fn = StringStripWS(GUICtrlRead($Combo), 3)
            $Parameters = StringStripWS(GUICtrlRead($Input), 3)
            if $Fn > '' then
                ShellExecute($Fn, $Parameters)
                if not @error then
                    _MRU_AddItem($Mru, $Fn)
                    _MRU_RegWrite($Mru)
                    _MRU_Release($Mru)
                    RegWrite($REG_KEY_NAME, 'Parameters', 'REG_SZ', $Parameters)
                    exit
                endif
            endif
        case ($GUIMsg = $ButtonBrowse)
            $Fn = FileOpenDialog('Select File', $Path, 'All files (*.*)', 1 + 2, '', $Form)
            if $Fn > '' then
                $Path = StringMid($Fn, 1, StringInStr($Fn, '\', 0, -1) - 1)
                GUICtrlSetState($Combo, $GUI_FOCUS)
                _GUICtrlComboBox_SetEditText($Combo, $Fn)
                _GUICtrlComboBox_SetEditSel($Combo, 0, -1)
            endif
    endselect
wend

; Main

func WM_COMMAND($hWnd, $msgID, $wParam, $lParam)

    switch $lParam
        case GUICtrlGetHandle($Combo)
            if BitShift($wParam, 0x10) = $CBN_EDITCHANGE then
                _GUICtrlComboBox_AutoComplete($Combo)
            endif
        case else

    endswitch

    return $GUI_RUNDEFMSG
endfunc; WM_COMMAND
        
func WM_DROPFILES($hWnd, $msgID, $wParam, $lParam)

    local $Data, $Drag, $Size, $Name, $File
    local $Amt = DllCall('shell32.dll', 'int', 'DragQueryFile', 'hwnd', $wParam, 'int', 0xFFFFFFFF, 'ptr', 0, 'int', 255)
    
    if $Amt[0] = 0 then
        return
    endif
    $Drag = DllCall('shell32.dll', 'int', 'DragQueryFile', 'hwnd', $wParam, 'int', 0, 'ptr', 0, 'int', 0)
    $Size = $Drag[0] + 1
    $Name = DllStructCreate('char[' & $Size & ']')
    DllCall('shell32.dll', 'int', 'DragQueryFile', 'hwnd', $wParam, 'int', 0, 'ptr', DllStructGetPtr($Name), 'int', $Size)
    $File = DllStructGetData($Name, 1)
    $Name = 0
    GUISetState(@SW_RESTORE)
    if _MouseIn(56, 86, 366 + (_GetWindowWidth($Form) - $Width), 107) then
        if StringInStr($File, ' ') then
            $File = '"' & $File & '"'
        endif
        GUICtrlSetState($Input, $GUI_FOCUS)
        GUICtrlSetData($Input, GUICtrlRead($Input) & $File)
        _GUICtrlEdit_SetSel($Input, -1, -1)
    else
        GUICtrlSetState($Combo, $GUI_FOCUS)
        _GUICtrlComboBox_SetEditText($Combo, $File)
        _GUICtrlComboBox_SetEditSel($Combo, 0, -1)
    endif
endfunc; WM_DROPFILES

func WM_GETMINMAXINFO($hWnd, $msgID, $wParam, $lParam)
    
    local $tMINMAXINFO = DllStructCreate('int ptReserved[2];int ptMaxSize[2];int ptMaxPosition[2];int ptMinTrackSize[2];int ptMaxTrackSize[2]', $lParam)
    
    DllStructSetData($tMINMAXINFO, 'ptMinTrackSize', $Width, 1)
    DllStructSetData($tMINMAXINFO, 'ptMinTrackSize', $Height, 2)
    DllStructSetData($tMINMAXINFO, 'ptMaxTrackSize', @DesktopWidth, 1)
    DllStructSetData($tMINMAXINFO, 'ptMaxTrackSize', $Height, 2)
    
    return 0
endfunc; WM_GETMINMAXINFO

func CreateForm()

    local $Parent
    
    $Form = _GUICreateDlgFrame('Run', 380, 160, -1, -1, $WS_SIZEBOX, $WS_EX_ACCEPTFILES, GUICreate('', 0, 0, 0, 0, 0, $WS_EX_TOOLWINDOW))
    GUISetIcon(@SystemDir & '\shell32.dll', 25)

    GUISetFont(8.5, 400, 0, 'Tahoma', $Form)

    GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
    GUIRegisterMsg($WM_DROPFILES, 'WM_DROPFILES')
    GUIRegisterMsg($WM_GETMINMAXINFO, 'WM_GETMINMAXINFO')
    
    GUICtrlCreateIcon(@SystemDir & '\shell32.dll', 25, 12, 16, 32, 32)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetResizing(-1, 802)
    GUICtrlCreateLabel('Type the name of a program, folder, document, or Internet resource, and Windows will open it for you.', 56, 16, 310, 41)
    GUICtrlSetResizing(-1, 550)
    GUICtrlCreateLabel('Open:', 12, 61, 42, 14)
    GUICtrlSetResizing(-1, 802)
    $Combo = GUICtrlCreateCombo('', 56, 58, 310, 21, BitOR($CBS_AUTOHSCROLL, $CBS_DROPDOWN))
    GUICtrlSetData(-1, _MRU_GetAsString($Mru, '|'))
    GUICtrlSetResizing(-1, 550)
    GUICtrlCreateLabel('With:', 12, 89, 42, 14)
    GUICtrlSetResizing(-1, 802)
    $Input = GUICtrlCreateInput($Parameters, 56, 86, 310, 21)
    GUICtrlSetResizing(-1, 550)
    GUICtrlSetResizing(-1, 550)
    if $pCmd = '' then
        $pCmd = _Mru_GetItem($Mru, 1)
    endif
    _GUICtrlComboBox_SetEditText($Combo, $pCmd)
    if $CmdLine[0] > 0 then
        GUICtrlSetState($Input, $GUI_FOCUS)
        _GUICtrlEdit_SetSel($Input, -1, -1)
    else
        GUICtrlSetState($Combo, $GUI_FOCUS)
        _GUICtrlComboBox_SetEditSel($Combo, 0, -1)
    endif
    $ButtonOk = GUICtrlCreateButton('OK', 130, 129, 75, 23)
    GUICtrlSetState(-1, $GUI_DEFBUTTON)
    GUICtrlSetResizing(-1, 804)
    $ButtonCancel = GUICtrlCreateButton('Cancel', 211, 129, 75, 23)
    GUICtrlSetResizing(-1, 804)
    $ButtonBrowse = GUICtrlCreateButton('Browse...', 292, 129, 75, 23)
    GUICtrlSetResizing(-1, 804)

    $Width = _GetWindowWidth($Form)
    $Height = _GetWindowHeight($Form)
    
    _SetWindowPos($Form, 3, 3, $Width, $Height, $WIN_LEFT_BOTTOM)
    
    GUISetState()
    
endfunc; CreateForm

func _GetDesktopArea()

    const $SPI_GETWORKAREA = 48

    local $tRect = DllStructCreate('long Left;long Top;long Right;long Bottom')
    local $aRect[4], $aRet
    
    $aRet = DllCall('user32.dll', 'int', 'SystemParametersInfo', 'uint', $SPI_GETWORKAREA, 'uint', 0, 'ptr', DllStructGetPtr($tRect), 'uint', 0)
    if (@error) or ($aRet[0] = 0) then
        return SetError(1, 0, 0)
    endif
    
    $aRect[0] = DllStructGetData($tRect, 'Left')
    $aRect[1] = DllStructGetData($tRect, 'Top')
    $aRect[2] = DllStructGetData($tRect, 'Right')
    $aRect[3] = DllStructGetData($tRect, 'Bottom')

    return SetError(0, 0, $aRect)
endfunc; _GetDesktopArea

func _GetTaskbarHeight()

    local $Desktop = _GetDesktopArea()
    
    if @error then
        return SetError(1, 0, 0)
    endif
    
    return SetError(0, 0, @DesktopHeight - $Desktop[3])
endfunc; _GetTaskbarHeight

func _GetWindowWidth($hWnd)
    
    local $tRet, $iWidth
    
    $tRet = _WinAPI_GetWindowPlacement($hWnd)
    if @error then
        return SetError(1, 0, 0)
    endif
    $iWidth = DllStructGetData($tRet, 'rcNormalPosition', 3) - DllStructGetData($tRet, 'rcNormalPosition', 1)
    $tRet = 0
    
    return SetError(0, 0, $iWidth)
endfunc; _GetWindowWidth

func _GetWindowHeight($hWnd)
    
    local $tRet, $iHeight
    
    $tRet = _WinAPI_GetWindowPlacement($hWnd)
    if @error then
        return SetError(1, 0, 0)
    endif
    $iHeight = DllStructGetData($tRet, 'rcNormalPosition', 4) - DllStructGetData($tRet, 'rcNormalPosition', 2)
    $tRet = 0
    
    return SetError(0, 0, $iHeight)
endfunc; _GetWindowHeight

func _GUICreateDlgFrame($sTitle, $iWidth = -1, $iHeight = -1, $iLeft = -1, $iTop = -1, $iStyle = 0, $iExStyle = 0, $hParent = 0)

    local $hWnd = GUICreate($sTitle, $iWidth, $iHeight, $iLeft, $iTop, BitOR($WS_CAPTION, $WS_SYSMENU, $iStyle), BitOR($WS_EX_DLGMODALFRAME, $iExStyle), $hParent)
    
    if (@error) or ($hWnd = 0) then
        return SetError(1, 0, 0)
    endif
    
    local $hIcon = _WinAPI_GetClassLong($hWnd, $GCL_HICON)
    
    if IsPtr($hIcon) then
        _WinAPI_DestroyIcon($hIcon)
    endif
    
    _WinAPI_SetClassLong($hWnd, $GCL_HICON, 0)
    _WinAPI_SetClassLong($hWnd, $GCL_HICONSM, 0)
    
    return SetError(0, 0, $hWnd)
endfunc; _GUICreateDlgFrame

func _RegRead($Key, $Value, $Type, $Default)
    
    local $Val = RegRead($Key, $Value)

    if @error then
        RegWrite($Key, $Value, $Type, $Default)
        return $Default
    endif
    
    switch StringUpper($Type)
        case 'REG_SZ', 'REG_MULTI_SZ', 'REG_EXPAND_SZ'
            if not IsString($Val) then
                return SetError(1, 0, $Default)
            endif
        case 'REG_BINARY'
            if not IsBinary($Val) then
                return SetError(1, 0, $Default)
            endif
        case 'REG_DWORD'
            if not IsInt($Val) then
                return SetError(1, 0, $Default)
            endif
        case else
            return SetError(1, 0, $Default)
    endswitch
    return $Val
endfunc; _RegRead

func _SetWindowPos($hWnd, $iX, $iY, $iWidth = -1, $iHeight = -1, $iFlag = $WIN_LEFT_TOP)
    
    local $tRet
    
    $tRet = _WinAPI_GetWindowPlacement($hWnd)
    if @error then
        return SetError(1, 0, 0)
    endif
    if $iWidth < 0 then
        $iWidth = DllStructGetData($tRet, 'rcNormalPosition', 3) - DllStructGetData($tRet, 'rcNormalPosition', 1)
    endif
    if $iHeight < 0 then
        $iHeight = DllStructGetData($tRet, 'rcNormalPosition', 4) - DllStructGetData($tRet, 'rcNormalPosition', 2)
    endif
    switch $iFlag
        case $WIN_LEFT_TOP
            DllStructSetData($tRet, 'rcNormalPosition', $iX, 1)
            DllStructSetData($tRet, 'rcNormalPosition', $iY, 2)
            DllStructSetData($tRet, 'rcNormalPosition', $iX + $iWidth, 3)
            DllStructSetData($tRet, 'rcNormalPosition', $iY + $iHeight, 4)
        case $WIN_RIGHT_TOP
            DllStructSetData($tRet, 'rcNormalPosition', @DesktopWidth - $iWidth - $iX, 1)
            DllStructSetData($tRet, 'rcNormalPosition', $iY, 2)
            DllStructSetData($tRet, 'rcNormalPosition', DllStructGetData($tRet, 'rcNormalPosition', 1) + $iWidth, 3)
            DllStructSetData($tRet, 'rcNormalPosition', $iY + $iHeight, 4)
        case $WIN_LEFT_BOTTOM
            DllStructSetData($tRet, 'rcNormalPosition', $iX, 1)
            DllStructSetData($tRet, 'rcNormalPosition', @DesktopHeight - $iHeight - _GetTaskbarHeight() - $iY, 2)
            DllStructSetData($tRet, 'rcNormalPosition', $iX + $iWidth, 3)
            DllStructSetData($tRet, 'rcNormalPosition', DllStructGetData($tRet, 'rcNormalPosition', 2) + $iHeight, 4)
        case $WIN_RIGHT_BOTTOM
            DllStructSetData($tRet, 'rcNormalPosition', @DesktopWidth - $iWidth - $iX, 1)
            DllStructSetData($tRet, 'rcNormalPosition', @DesktopHeight - $iHeight - _GetTaskbarHeight() - $iY, 2)
            DllStructSetData($tRet, 'rcNormalPosition', DllStructGetData($tRet, 'rcNormalPosition', 1) + $iWidth, 3)
            DllStructSetData($tRet, 'rcNormalPosition', DllStructGetData($tRet, 'rcNormalPosition', 2) + $iHeight, 4)
        case else
            
    endswitch
    _WinAPI_SetWindowPlacement($hWnd, DllStructGetPtr($tRet))
    $tRet = 0
    
    return SetError(0, 0, 1)
endfunc; _SetWindowPos

func _WinAPI_GetClassLong($hWnd, $nIndex)
    
    local $ret = DllCall('user32.dll', 'int', 'GetClassLong', 'hwnd', $hWnd, 'int', $nIndex)
    
    if (@error) or ($ret[0] = 0) then
        return 0
    endif
    return $ret[0]
endfunc; _WinAPI_GetClassLong

func _WinAPI_SetClassLong($hWnd, $nIndex, $dwNewLong)
    
    local $ret = DllCall('user32.dll', 'int', 'SetClassLong', 'hwnd', $hWnd, 'int', $nIndex, 'long', $dwNewLong)
    
    if (@error) or ($ret[0] = 0) then
        return 0
    endif
    return $ret[0]
endfunc; _WinAPI_SetClassLong

Also needed MRU.au3

This is realy nice code, I wonder how come no comments on it

Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Definitely better than the Windows Run option :)

A small suggestion: I think it needs 2 browse buttons.

For example, I tried to open file which I found by browsing, and then I wanted to open it with an application which I wanted to find by browsing.

mgrefyashiedrun

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Great app, it didn't like drag n drop though

Error:

---------------------------

AutoIt Error

---------------------------

Line 149 (File "C:\Documents and Settings\Ricky\Desktop\Run.au3"):

if _MouseIn(56, 86, 366 + (_GetWindowWidth($Form) - $Width), 107) then

if ^ ERROR

Error: Unknown function name.

---------------------------

OK

---------------------------

Edited by colafrysen

[font="Impact"]Use the helpfile, It´s one of the best exlusive features of Autoit.[/font]http://support.microsoft.com/kb/q555375ALIBI Run - a replacement for the windows run promptPC Controller - an application for controlling other PCs[size="1"]Science flies us to the moon. Religion flies us into buildings.[/size][size="1"]http://bit.ly/cAMPZV[/size]

Share this post


Link to post
Share on other sites

Same as above

ERROR: _MouseIn(): undefined function.

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

It's a great script, definitely better than the built in windows Run dialog. I agree with lsakizada another browse button would be great.

Share this post


Link to post
Share on other sites

Hi Yashied,

When I try to run this I get the following errormessage:

---------------------------

AutoIt Error

---------------------------

Line 642 (File "C:\Users\michael\Downloads\UDFs\MRU.au3"):

$str &= $MruArray[Asc(StringLeft(StringTrimLeft($MruArray[0], $j - 1), 1)) - 96]

$str &= $MruArray[^ ERROR

Error: Array variable subscript badly formatted.

---------------------------

OK

---------------------------

I'm running the latest beta on win7.

br /michael

Share this post


Link to post
Share on other sites

AutoIt Error

---------------------------

Line 642 (File "C:\Users\michael\Downloads\UDFs\MRU.au3"):

$str &= $MruArray[Asc(StringLeft(StringTrimLeft($MruArray[0], $j - 1), 1)) - 96]

$str &= $MruArray[^ ERROR

Error: Array variable subscript badly formatted.

I'm getting this same error. Can someone suggest a simplifying construct that might pass the syntax check?

Share this post


Link to post
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
Sign in to follow this  
Followers 0