Jump to content

ReFran

Active Members
  • Posts

    548
  • Joined

  • Last visited

  • Days Won

    1

Reputation Activity

  1. Like
    ReFran got a reaction from dogisay in Treeview Read to / from File   
    Here an example how
    - to read treeview items from file or save to.
    - Move treeview items up/down - left/right


    Enjoy, Reinhard

    edit: Inserted _GUICtrlTreeView_Begin../..EndUpdate($hTree)



    ;; ReFran (3.2.12.1) ;; Move treeview items up/down - left/right ;; Read treeview items from file or save to. #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUITreeView.au3> #include <StaticConstants.au3> DIM $Childs DIM $TvFileNm = @scriptDir &"\" &"TvItems.txt" $hMain = GUICreate("Treeview", 342, 183, 341, 278, -1798701056, 256) $hTree = GUICtrlCreateTreeView(6, 6, 200, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) $generalitem = GUICtrlCreateTreeViewItem("General", $hTree) $aboutitem = GUICtrlCreateTreeViewItem("About", $generalitem) $compitem = GUICtrlCreateTreeViewItem("Computer", $generalitem) $useritem = GUICtrlCreateTreeViewItem("User", $generalitem) $useritem1 = GUICtrlCreateTreeViewItem("1.User", $useritem) $useritem2 = GUICtrlCreateTreeViewItem("2.User", $useritem) $compitem3 = GUICtrlCreateTreeViewItem("Schmuser", $generalitem) $compitem4 = GUICtrlCreateTreeViewItem("Looser", $generalitem) $displayitem = GUICtrlCreateTreeViewItem("Display", $hTree) $resitem = GUICtrlCreateTreeViewItem("Resolution", $displayitem) $otheritem = GUICtrlCreateTreeViewItem("Other", $displayitem) $Btn_TvToFile = GUICtrlCreateButton("To file", 240, 10, 50, 25) $Btn_TvClear = GUICtrlCreateButton("Clear", 240, 37, 50, 25) $Btn_TvFromFile = GUICtrlCreateButton("From file", 240, 65, 50, 25) $Btn_up = GUICtrlCreateButton("Up", 240, 110, 25, 25) $Btn_dn = GUICtrlCreateButton("Dn", 270, 110, 25, 25) $Btn_left = GUICtrlCreateButton("<-", 240, 140, 25, 25) $Btn_right = GUICtrlCreateButton("->", 270, 140, 25, 25) GUICtrlSetState($generalitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "General"-item and paint in bold GUICtrlSetState($displayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "Display"-item and paint in bold GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE Exit ;; TV Read from / Write to example Case $Btn_TvToFile $item = _GUICtrlTreeView_GetFirstItem($hTree) If $item = 0 Then MsgBox(64, "Treeview", "No item in TV") Else TV_Save() endif Case $Btn_TvClear _GuiCtrlTreeView_DeleteAll($hTree) Case $Btn_TvFromFile TV_ReadData() ;; TV move items example Case $Btn_Up TV_ItemMove("up") Case $Btn_Dn TV_ItemMove("dn") Case $Btn_left TV_ItemMove("left") Case $Btn_right TV_ItemMove("right") EndSwitch Sleep(10) WEnd #Region TVMoveItems Func TV_ItemMove($dir);;; Moves Treeview Items $item = _GuiCtrlTreeView_GetSelection($hTree) If $item = 0 Then MsgBox(64, "Treeview", "No item currently selected") Return;;==> return from function Endif $itemText = _GuiCtrlTreeView_GetText($htree,$item) $itemPA = _GUICtrlTreeView_GetParentHandle($hTree, $item) ;; check and prepare to move up if $dir = "up" then ;;new UdF - item will be inserted after, so get prev of prev $itemToPrev = _GuiCtrlTreeView_GetPrevSibling($hTree, $item) $itemTo = _GuiCtrlTreeView_GetPrevSibling($hTree, $itemToPrev) if $itemPa = 0 then;; get the first sibiling item $itemFirstSib = _GUICtrlTreeView_GetFirstItem($hTree) Else $itemFirstSib = _GUICtrlTreeView_GetFirstChild($hTree,$itemPA) endif if $itemFirstSib = $item Then;; first item can not moved up msgbox(0,"","Moving up is not possible") Return;;==> return from function EndIf endif ;; check and prepare to move down if $dir = "dn" then; item will be inserted after, so get next $itemTo = _GuiCtrlTreeView_GetNextSibling($hTree,$item) $itemToNext = _GuiCtrlTreeView_GetNextSibling($hTree,$item) $itemLastSib =_GuiCtrlTreeView_GetLastChild($hTree,$itemPA) if $itemLastSib = $item or $itemto = 0 Then msgbox(0,"","Moving down not possible") return;;==> return from function endif endif ;; check and prepare to move left if $dir = "left" then $itemLevel = _GuiCtrlTreeView_Level($hTree, $item) $itemLevelPa = $itemLevel - 1 if $itemLevel = 0 then msgbox(0,"","Not possible") return;;==> return from function endif $itemTo = $itemPa endif ;; check and prepare to move right if $dir = "right" then $itemLevel = _GuiCtrlTreeView_Level($hTree, $item) if $itemlevel = 0 then $itemFirstSib = _GUICtrlTreeView_GetFirstItem($hTree) Else $itemFirstSib = _GUICtrlTreeView_GetFirstChild($hTree,$itemPa) endif if $item = $itemFirstSib Then msgbox(0,"","Not possible") return;;==> return from function endif $itemTo = _GuiCtrlTreeView_GetPrevSibling($hTree,$item) endif ;;check for children and get it $itemIsParent = _GUICtrlTreeView_GetChildCount($hTree, $item);0 = no childs if $itemIsParent > 0 then $itemLevel = _GuiCtrlTreeView_Level($hTree, $item) $Childs = GetTree($item,$itemLevel,$itemText) endif ;; start to move if $dir = "dn" and $itemToNext = $itemLastSib then $itemInsert = _GuiCtrlTreeView_Add($hTree, $item, $itemText) elseif $dir = "up" and $itemToPrev = $itemFirstSib then $itemInsert = _GuiCtrlTreeView_AddFirst($hTree, $itemtoPrev, $itemText) elseif $dir = "right" then $itemInsert = _GuiCtrlTreeView_AddChild($hTree,$itemto,$itemtext) elseif $dir = "left" and $itemLevelPa > 0 Then $itemPaPa = _GUICtrlTreeView_GetParentHandle($hTree, $itemPA) $itemInsert = _GUICtrlTreeView_InsertItem($htree,$itemText,$itemPaPa,$itemPA) else if $dir = "left" then $itemPa = 0 $itemInsert = _GUICtrlTreeView_InsertItem($htree,$itemText,$itemPA,$itemTo) endif _GuiCtrlTreeView_Delete($htree,$item) ;; add Childs from selected Item to Inserted Item if $itemIsParent > 0 then ;msgbox(0,"",$childs) Dim $hNode[50] $aChilds = StringSplit($Childs, ";") for $i = 1 to $achilds[0]-1 $level = $aChilds[$i] $itemText = $aChilds[$i+1] if $level = $itemLevel then $hNode[$level] = $itemInsert else $hNode[$level]= _GuiCtrlTreeView_AddChild($hTree, $hNode[$level-1],$itemText ) endif $i +=1 next $Childs="" endif _GuiCtrlTreeView_SelectItem($hTree, $itemInsert) EndFunc func GetTree($item,$itemLevel,$itemText);; Get the Tree for Children $itemLevelPa = $itemLevel Do $Childs &= $itemLevel &";" &$itemText &";"; &@lf $item = _GuiCtrlTreeView_GetNext($hTree, $item) $itemLevel = _GuiCtrlTreeView_Level($hTree, $item) $itemText = _GuiCtrlTreeView_GetText($htree,$item) until $itemLevel <= $itemLevelPa; or $itemText = 0 ;MsgBox(0,"",$Childs) return $childs endfunc #EndRegion TVMoveItems #Region TvReadWrite ;;;; Save Treeview Items to file;;;;; func TV_Save();;# added for better reading, one space is added for level $item = _GUICtrlTreeView_GetFirstItem($hTree) $TvList = "" Do $itemText = _GuiCtrlTreeView_GetText($htree, $item) $itemlevel = _GuiCtrlTreeView_Level($htree, $item) $itemSpace = stringleft(" ",$itemlevel) $TvList &= $itemSpace &"#" & $itemText &@LF $item = _GuiCtrlTreeView_GetNext($htree, $item) until $item = 0 msgBox(0,$TvFileNM,$TvList) $FileId = Fileopen($TvFileNM,2) FileWrite($FileId,StringstripWS($TvList,2)) FileClose($FileId) endfunc;;=> TVSave ;;;; Read Treeview Items from file;;;;; ;; # is used as start sign (will not diplayed), space is used for level;; Func TV_ReadData();; Read Data from a TvFile (# as start sign, space for level if not FileExists($TvFileNm) Then MsgBox(0,"","File with TV-Items don't exists!") EndIf Dim $aTree = StringSplit(FileRead($TvFileNM, FileGetSize($TvFileNM)), @LF) TV_Display($aTree) endFunc Func TV_Display($aTree);; Read from variable to TV Dim $hNode[50];Keep Parent on Level _GUICtrlTreeView_BeginUpdate($hTree) For $i = 1 to $aTree[0] $line = StringStripCR($aTree[$i]) ;msgbox(0,"",$line) $level = StringInStr($line, "#") if $level = 0 then exitloop if $level = 1 then $hNode[$level] =_GuiCtrlTreeView_Add($hTree, 0, StringMid($line, $level+1)) Else $hNode[$level]= _GuiCtrlTreeView_AddChild($hTree, $hNode[$level-1], StringMid($line, $level+1)) Endif Next _GUICtrlTreeView_EndUpdate($hTree) EndFunc;;==>End of TV_ReadData #endRegion TvReadWrite
  2. Like
    ReFran got a reaction from hemal in PDF merge   
    You may have a look at the free command-line tools PDFTK or mbtPdfAsm

    http://www.accesspdf.com/pdftk/
    http://thierry.schmit.free.fr/spip/spip.ph...e15&lang=en

    I prefer mbtPdfAsm, because it also can write bookmarks (PDFTK can only read).

    If you don't want to write your own GUI you may also have a look on BeCyPdfAsm:
    http://www.becyhome.de/download_eng.htm#becypdfasm

    HTH, Reinhard
  3. Like
    ReFran got a reaction from Spined in Display PDF in GUI   
    If I remember right you need a Version >= 7 (Acrobat or Reader).

    HTH, Reinhard

    PS: By the way you shouldn't use .. = $oPDF.GetVersions. Adobe will discontinue, but in actual versions it works.
  4. Like
    ReFran got a reaction from Spined in Display PDF in GUI   
    Works with Acrobat and Reader (versions >= 7). Will be installed from both apps.
    br, Reinhard
  5. Like
    ReFran got a reaction from Spined in Display PDF in GUI   
    Also with Acrobat/Reader 7 and higher you get this error message if the viewer is not configured to show the PDF in (IE) Browser, what normally is set as standard.
    Under "Edit" choose "BasicSetting" (last menuitem), select "Internet" and then mark [x] PDF in Viewer (MenuItem Free translated from a german version).
    For scripter this means, if you want to make shure that "embedded" works, you first have to check/influence the registry key.

    HTH, Reinhard
  6. Like
    ReFran got a reaction from Spined in Display PDF in GUI   
    You should update (see under help) at least to 7.0.9.
    However, with an embeded object like Reader and some other -direct with dll or indirect with IE - you get a repain problem.
    There has been a discussion here about this, but no solution.
    So I start it direct and move it to the position and size I want and influence the Reader direct.

    HTH, Reinhard
  7. Like
    ReFran got a reaction from Spined in Display PDF in GUI   
    Does this IE based solution work for you?



    #include <GUIConstants.au3> $Form1 = GUICreate("Browse PDF", 400,300,400,300) $Obj = ObjCreate("Shell.Explorer.2") $browser = GUICtrlCreateObj($Obj, 0, 0, 400, 300) GUISetState(@SW_SHOW) $Obj.Navigate('C:\Program Files\Adobe\Acrobat 7.0\Help\ENU\Reader.pdf') ;; $Obj.Navigate('C:\Programme\Adobe\Acrobat 7.0\Help\ENU\Reader.pdf') While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;;;;;; EndSelect WEnd Exit
  8. Like
    ReFran got a reaction from Spined in Display PDF in GUI   
    Which Acrobat/Reader version (exact) you work with.
    Can you show your code-snippet you work with.

    br, reinhard
  9. Like
    ReFran got a reaction from Spined in Display PDF in GUI   
    I don't know what the problem is, but what happens if you type: "C:\Program Files\Adobe\Acrobat 7.0\Help\ENU\Reader.pdf"
    into the IE address line.

    Reinhard
  10. Like
    ReFran got a reaction from Skysnake in [Solved] Start /max PDF - very slow problem   
    Hi, you could check the file association and get the executable.
    If the executable is Adobe Reader you can start it direct with the command line option /n. That means Reader will start the file in a new instance.
    If you find another PDF viewer you can start it also direct. If you find nothing you can give a hint or a link to a PDF viewer.
     
    br, Reinhard
     
    PS.: In cmd you can use "assoc .pdf" and then use the result in "ftype ....." to get the program, but I think I saw also examples here.
  11. Like
    ReFran got a reaction from mLipok in how to fill a Pdf form   
    OK,

    here one short example how you can fill a form with Adobe Acrobat $$$ version from 5-X using JS:


    ;; user settings $FilePath = "C:\temp.pdf" ; fillable pdf with one form field $fieldname = "Test1" ;form field name $fileOut = "c:\temp_filled.pdf" ;; application $App = ObjCreate("AcroExch.App") ;; start Adobe Acrobat $App.Show ;; show Acrobat or comment out for hidden mode ;; actions $AVDoc = ObjCreate("AcroExch.AVDoc") ;; connect to Ac Viewer If $AVDoc.Open($FilePath,"") Then ;; open the file $PDDoc = $AVDoc.GetPDDoc ;; get PdDoc from AvDoc $AForm = ObjCreate("AFormAut.App") ;;connect to AForm API $EX = "" _ ;; write some JS-code to a variable & ' var f = this.getField("'&$fieldname&'")' & @LF _ & ' f.value = "hello"' ;msgbox(0,"",$ex) $AForm.Fields.ExecuteThisJavaScript($EX) ;;execute the Js-Code $PDDoc.save(1,$fileOut) $app.closeAlldocs() $app.exit() Else msgbox(0,"","Coudn't open report") endif ;; release objects $AForm = 0 $AvDoc = 0 $PdDoc = 0 $App = 0
    If you want to fill a pdf only with free Reader you can write and execute an FDF-File:


    #include <GUIConstants.au3> ; Setting variables Global $sFilename = "C:\Temp.pdf" If FileExists($sFilename) Then $sX = StringReplace($sFilename,"\","/") $sX = StringReplace($sX,":","") $sPdfNM = "/" &$sX $FdfNM = FileOpen( "C:\Temp.FDF",2) $Ex = "%FDF-1.2 %% Fill Form Fields %%" &@CRLF _ &"1 0 obj << /FDF << /F (" &$sPdfNM &") /Fields " &@CRLF _ &"[" &@CRLF _ & '<</T(Test1)/V(MyTestValue)>>' &@CRLF _ &"]>>>>" &@CRLF _ & "endobj" &@CRLF _ & "trailer" &@CRLF _ & "<</Root 1 0 R >>" &@CRLF _ & "%%EOF" FileWrite($FdfNM,$Ex) FileClose($FdfNM) RunWait(@ComSpec & " /c " & 'start c:\Temp.fdf' , "", @SW_HIDE) ;FileDelete("C:\temp.fdf") endif
    But with Reader you can only save it if the rights are enabled. That normaly not or not ever.
    The free commandline tool pdftk.exe (well known and tested) can read pdf field-values, prefill or fill and save it. In the next example I added that:


    #include <GUIConstants.au3> ; Setting variables Global $sFilename = "C:\Temp.pdf" If FileExists($sFilename) Then $sX = StringReplace($sFilename,"\","/") $sX = StringReplace($sX,":","") $sPdfNM = "/" &$sX $FdfNM = FileOpen( "C:\Temp.FDF",2) $Ex = "%FDF-1.2 %% Fill Form Fields %%" &@CRLF _ &"1 0 obj << /FDF << /F (" &$sPdfNM &") /Fields " &@CRLF _ &"[" &@CRLF _ & '<</T(Test1)/V(MyTestValue)>>' &@CRLF _ &"]>>>>" &@CRLF _ & "endobj" &@CRLF _ & "trailer" &@CRLF _ & "<</Root 1 0 R >>" &@CRLF _ & "%%EOF" FileWrite($FdfNM,$Ex) FileClose($FdfNM) RunWait(@ComSpec & " /c " & 'start c:\Temp.fdf' , "", @SW_HIDE) ;FileDelete("C:\temp.fdf") endif if FileExists(@scriptdir&"/pdftk.exe") Then $OK=msgbox(51,"Pdf-Fill","Do you want "&@lf&" only to pre-fill (keep editable) or "&@lf&" pre-fill and flatten (fix content)?"&@lf&@lf&"Keep editable?") consolewrite($OK&@lf) select case $OK = 6 ;yes if FileExists("C:\temp_fe.pdf") then FileDelete("C:\temp_fe.pdf") Runwait(@ComSpec & " /c " &@scriptdir&"\pdftk.exe "&$sFilename&" fill_form c:\Temp.fdf output C:\temp_fe.pdf", "", @SW_HIDE) shellexecute("C:\temp_fe.pdf") case $OK = 7 ; no if FileExists("C:\temp_ff.pdf") then FileDelete("C:\temp_ff.pdf") RunWait(@ComSpec & " /c " &@scriptdir&"\pdftk.exe "&$sFilename&" fill_form c:\Temp.fdf output C:\temp_ff.pdf flatten", "", @SW_HIDE) shellexecute("C:\temp_ff.pdf") case $OK = 2 ; cancel msgbox(0,"Pdf-Fill","Job canceled") EndSelect endif
    If you don't have a fillable PDF-Form to test it, you just can set it up with Adobe Acrobat. If you don't want to spent money for that you can also use free Open-Office, which can also write fillable PDF-forms.

    HTH, Reinhard
  12. Like
    ReFran got a reaction from SupaNewb in Set Default Printer   
    Just saw this and just worked with printers.
    Took the following code and change it to your need.

    HTH, Reinhard


    ;----------------------------------------------------------- ; Get specific information from all installed printers ; Refran based on a VBS from Christoph Basedau ;----------------------------------------------------------- $oWMI = ObjGet("winmgmts:") GetPrinter ("Win32_Printer") Func GetPrinter($sID) $colWBEMSet = $oWMI.InstancesOf($sID) msgbox(0,"",$colWBEMSet.count) If $colWBEMSet.count = 0 Then MsgBox(0,"", "No elements in Win32_Printer found") exit Else For $oElem in $colWBEMSet $xFind = "" $xtxt = $oElem.GetObjectText_ ;msgbox(0,"",$xTxt);= show all information $aTxt = Stringsplit($xTxt,";") for $x in $atxt; Filter specific information if stringInstr(stringleft($x,9),"Name = ") then $xfind = $xfind &$x &"; " if stringInstr($x,"DriverName = ") then $xfind = $xFind &$x &"; " if stringInstr($x,"PortName = ") then $xfind = $xFind &$x &"; " if stringInstr($xfind,"PortName") then exitLoop;=PortName = last to find next msgbox(0,"",$xFind) Next EndIf EndFunc
  13. Like
    ReFran got a reaction from PsiLink in How to get "toolsbar" text like with Wininfo tool   
    "..Or is there another way?.."

    Ok, found the other way in a script by Melba23.
    Reading the text like WinInfo seems not to be possible.

    best regards, Reinhard


    ;; by Melba23 #Include <GuiToolBar.au3> Global $hSysTray_Handle, $iSystray_ButtonNumber Global $sToolTipTitle = "" ; <<<<<<<<<<<<<<<< Enter some tooltip text for the icon you want here $iSystray_ButtonNumber = Get_Systray_Index($sToolTipTitle) If $iSystray_ButtonNumber = 0 Then MsgBox(16, "Error", "Icon not found in system tray") Exit Else Sleep(500) _GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right") EndIf Exit ;............ Func Get_Systray_Index($sToolTipTitle) ; Find systray handle $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]') If @error Then MsgBox(16, "Error", "System tray not found") Exit EndIf ; Get systray item count Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle) If $iSystray_ButCount = 0 Then MsgBox(16, "Error", "No items found in system tray") Exit EndIf ; Look for wanted tooltip For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1 If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) = 1 Then ExitLoop Next If $iSystray_ButtonNumber = $iSystray_ButCount Then Return 0 ; Not found Else Return $iSystray_ButtonNumber ; Found EndIf EndFunc ;;The script is not foolproof - sometimes it does not find the icon. ;;I have found that using the first word/words of the tooltip text gives the best results.
  14. Like
    ReFran got a reaction from Spenhouet in ListView_deleteitem won't work   
    At lest for DeleteItem you have to use the handle (not the control ID).
    $hWndListView2 = GUICtrlGetHandle($testselection)
    _GUICtrlListView_DeleteItem($hWndListView2 , $inde)

    HTH, Reinhard
×
×
  • Create New...