wolfbartels Posted March 8, 2007 Share Posted March 8, 2007 Purpose of this script is explained on its beginning. Maybe it is useful for somebody. expandcollapse popup; AutoIt script enhancing 16-bit applications for long file name usage. ; This script adds 2 Buttons 'LFN Open' and 'LFN SaveAs' to a 16-bit application main window. ; These buttons open dialogs for entering or selecting LongFileNames and type the corresponding ShortFileNames into the respective applications dialogs. ; The script or its compiled Exe must be present in the applications directory ; Working directory in link to compiled EXE must be set to appl. data files directory ; Author: Wolf Bartels Dec. 2006 #notrayicon #include <GuiConstants.au3> Opt("MustDeclareVars", 1) AutoItSetOption("WinTitleMatchMode",4 ) ; -------------- adjust the following lines according to your application ---------------- ; -------------- As an example, this script is adjusted for CADVANCE 6.5 (freeware at http://www.cadvance.com/65form.htm) --------------- ;Properties of Applications Const $ApplName="CADVANCE.EXE" ;Applications Name Const $AMWtit="CADVANCE - [Untitled]";Appl. Main Window title (partial) Const $AMWtxt="Untitled" ;Appl. Main Window text (partial) Const $ApplFileExt=".vwf" ;Appl. File Extension (lower case with dot) ;Properties of Applications FileOpenDialog for short filenames Const $FODkeys="!fo" ;FOD opening keys = [Alt] [F] [O] Const $FODtit="Open" ;FOD title Const $FODtxt="File &Name:" ;FOD text (partial) Const $FODfilter="Drawings (*.vwf)|All files (*.*)";FOD file filters Const $FODentry="Edit1" ;FOD entry control for file names Const $FODopen="Button1" ;FOD OpenButton Const $FODcancel="Button2" ;FOD CancelButton ;Properties of Applications FileSaveAsDialog for short filenames Const $FSDkeys="!fa" ;FOD opening keys = [Alt] [F] [A] Const $FSDtit="Save As" ;FSD title Const $FSDtxt="File &Name:" ;FSD text (partial) Const $FSDentry="Edit1" ;FSD entry control Const $FSDsave="Button1" ;FSD SaveButton Const $FSDcancel="Button2" ;FSD CancelButton ;Properties of Applications FileOverwriteMessageBox Const $FOMtit="Save As" ;FOM title Const $FOMtxt="" ;FOM text (partial) Const $FOMyes="Button1" Const $FOMno= "Button2" ; Position of new Buttons relative to Appl.Main Window Const $tbleft=600 ; Pixels from left Const $tbtop=27 ; Pixels from top ; -------------- nothing more to adjust below this line ---------------- Global $AMWhdl ;Appl. Main Window handle Global $AMWpos ;Appl. Main Window position Global $FODhdl ;FileOpenDialog handle Global $FSDhdl ;FileSaveAsDialog handle Global $FOMhdl ;FileOverwriteMessageBox handle Global $ApplDir, $ApplPath, $ApplDataDir If @Compiled Then $ApplDir=StringLeft(@AutoItExe,StringInStr(@AutoItExe,"\",0,-1)-1) Else $ApplDir=@ScriptDir EndIf $ApplPath=$ApplDir & "\" & $ApplName If $CmdLine[0] then $ApplPath = $ApplPath & " " & FileGetShortName($CmdLine[1]) $ApplDataDir=@WorkingDir ; ------------- main start --------------- Run($ApplPath, $ApplDir) WinWait($AMWtit) $AMWhdl=WinGetHandle($AMWtit,$AMWtxt) $AMWpos = WinGetPos($AMWhdl) Dim $tbhdl, $Btn_open, $Btn_saveas $tbhdl=GuiCreate("", 150,20,$AMWpos[0]+$tbleft,$AMWpos[1]+$tbtop,$WS_POPUP, -1,$AMWhdl) $Btn_open = GuiCtrlCreateButton("LFN Open", 0, 0, 70, 20) $Btn_saveas = GuiCtrlCreateButton("LFN Save as", 80, 0, 70, 20) GUISetState() Dim $msg, $state, $statenew, $AMWposnew[4] WinActivate($AMWhdl) While WinExists($AMWhdl) $msg = GUIGetMsg() Select Case $msg = $Btn_open DoFileOpen() Case $msg = $Btn_saveas DoFileSaveAs() EndSelect $AMWposnew = WinGetPos($AMWhdl); Appl. window moved? If IsArray($AMWposnew) And $AMWposnew <> $AMWpos Then $AMWpos = $AMWposnew WinMove($tbhdl, "", $AMWpos[0] + $tbleft, $AMWpos[1] + $tbtop) EndIf WEnd Exit ; ------------- main end --------------- Func DoFileOpen() Local $initdir, $openfilelong, $openfileshort, $text, $jnchdl, $result $initdir=$ApplDir $openfilelong = FileOpenDialog($FODtit, $initdir, $FODfilter,2) If (Not @error) And ($openfilelong <> "") Then $openfileshort = FileGetShortName($openfilelong) DoSend($FODkeys) ;open Appl. FileOpenDialog for short file names WinWaitActive($FODtit, $FODtxt) $FODhdl = WinGetHandle($FODtit, $FODtxt) ControlSetText($FODhdl, "", $FODentry, $openfileshort) ControlClick($FODhdl, "", $FODopen) EndIf Endfunc Func DoFileSaveAs() Local $initdir, $savelong, $saveshort, $fhdl, $new, $FOMhdl $initdir = $ApplDir $savelong = FileSaveDialog($FSDtit, $initdir, $FODfilter, 2) If (Not @error) And ($savelong <> "") Then If StringRight(StringLower($savelong), StringLen($ApplFileExt))<>$ApplFileExt Then $savelong=$savelong & $ApplFileExt EndIf If Not FileExists($savelong) Then;Create empty file to define short file name $fhdl = FileOpen($savelong, 1) FileClose($fhdl) $new = 1 EndIf $saveshort = FileGetShortName($savelong) DoSend($FSDkeys);open Appl. FileSaveAsDialog for short file names WinWaitActive($FSDtit, $FSDtxt) $FSDhdl = WinGetHandle($FSDtit, $FSDtxt) ControlSetText($FSDhdl, "", $FSDentry, $saveshort) ControlClick($FSDhdl, "", $FSDsave) If $new Then; yes to overwrite empty file WinWaitActive($FOMtit, $FOMtxt) $FOMhdl = WinGetHandle($FOMtit, $FOMtxt) ControlClick($FOMhdl, "", $FOMyes) EndIf EndIf Endfunc Func DoSend($x) WinActivate($AMWhdl) Send($x) endfunc Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now