Jump to content

Recommended Posts

This UDF is because I'm tired of trying to use UI Automation and Send to automate Adobe Acrobat. I often need to read the contents of PDFs and Acrobat is not easy to work with as a window.  The functions are based on the API Reference from Adobe located here.

Acrobat Pro is required for all functions.

It's very beta right now, but it still seems to work. Currently, the functions are based around page level manipulation of PDF documents: re-arranging, swapping, deleting, and moving pages as this is what I use the most.

Please feel free to request/suggest features! :)

 

 

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

Link to post
Share on other sites

You mean that you can't create a AcroExch.PDDoc without Pro? (_Acro_DocOpen would return error 1) I can't test this at work as I have Pro installed everywhere 😐

I guess I assumed that Reader would use the reference too. I might be able to work on this at home where I don't own Pro, but I'm not nearly as familiar with Reader

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

Link to post
Share on other sites

TIL: Adobe Acrobat Pro is required for creating objects through AcroExch.App and AcroExch.PDDoc :(

There may be a way to automate Reader through DDE messages, but I'm unclear on what that is and if it's possible. Looking into it.

Edit: Read way too much on Reader...

Adobe Reader implements a different interface, resulting in a different set of functionality (Read: greatly reduced). I'm running out of ideas with Reader, but I'm pretty sure it implements IAcroAxDocShim (and a few more? C has multiple inheritance?) and can be created with AcroPDF.PDF or AcroPDF.PDF.1 - I think both, but it's something to do with the version of the type library you have.

I also found that not all of the methods are documented. There are three that I found: execCommand, postMessage, and messageHandler (get/set). I have no idea what they are/do. You'll see the methods if you find "Adobe PDF Reader" in the OLE/COM Object Viewer under "Object Classes\Grouped By Component Category\Automation Objects\" and right click to "View Type Information". From there, select 'Dispinterface IAcroAXDocShim' to see the methods available.

Aaand that's enough for now. I'll be dreaming in code tonight for sure.

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

Link to post
Share on other sites

Updated to version 0.0.0.2. I found that the JavaScript Object can be accessed and used, meaning that bookmarks are edit-able and so much more.

Added Functions:

  • _Acro_DocDisplay
  • _Acro_PageRotate
  • _Acro_AppShow
  • _Acro_DocJSObject
  • _Acro_DocBookmarkAdd

Fixed:

  • _Acro_PageCount - Actually returns page count now

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

Link to post
Share on other sites
  • 3 weeks later...

Bug: _Acro_PageGetText uses the wrong values to get the size of a page... dyslexia at work again...

Local $oRect = __Acro_Rect(0, $aPoint[0], 0, $aPoint[1])
;            Should be
Local $oRect = __Acro_Rect(0, $aPoint[1], 0, $aPoint[0])

Yeah... that's a good one. I'll try to update this soon. End of the month in accounting with a slow network. Nuff said? :D

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

Link to post
Share on other sites
  • 3 months later...

Updated to version 1.0.0.0

Added _Acro_DocAppend, which is my most used function now. I'm constantly combining PDFs at work using this. :)

If you have any suggestions or notice any issues, don't hesitate to let me know!

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

Link to post
Share on other sites
  • 2 weeks later...

seadoggie01

I can't seem to get _Acro_PageMove to work.  I have Acrobat 8 Pro.  Here's the code.  I'm not sure why it's not working.  I'm using the iac_api_reference.pdf file for checking but also just created a simple 4 page pdf to try it with the same result.  Any help/hints appreciated.

;Acro.au3 test program
#AutoIt3Wrapper_run_debug_mode=Y    ; use this to debug in console window <--- LOOK


#include <Acro.au3>

MsgBox(0, "Test", "Testing Acro UDF")

;Reverse order of pages e.g. 1,2,3,...,n-1,n to n,n-1,...3,2,1  - ALWAYS work from bottom to top
;open it
;$sFullPath = "C:\Program Files (x86)\AutoIt3\AH Code\PDF Processing\Acro UDF\Reverse test document pp 1-4.pdf"
$sFullPath = "C:\Program Files (x86)\AutoIt3\AH Code\PDF Processing\Acro UDF\iac_api_reference - WORKING COPY.pdf"
$oPdDoc = _Acro_DocOpen($sFullPath)
If $oPdDoc = False Then
    If @error = 1 Then MsgBox(0, "Error", "Could not find file: '" & $sFullPath &"'")
    If @error = 2 Then MsgBox(0, "Error", "Document not opened: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", "Document opened: '" & $sFullPath &"'")
EndIf


;get page count so we do all pages
$iPages = _Acro_PageCount($oPdDoc)
If $iPages = False Then
    If @error = 1 Then MsgBox(0, "Error", "$oPdDoc isn't a PDDoc object: '" & $sFullPath &"'")
    If @error = 2 Then MsgBox(0, "Error", "Can't get number of pages in: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", $iPages & " pages in document: '" & $sFullPath &"'")
EndIf

$j = 1  ;init value
For $i = $iPages to 2 Step -1   ;skip last move
    $iFromPage = $iPages    ;always move from last page
    $iToPage = $j
    $x = _Acro_PageMove($oPdDoc, $iFromPage, $iToPage)
    If $x = False Then
        If @error = 1 Then MsgBox(0, "Error", "$oPdDoc isn't a PDDoc object: '" & $sFullPath &"'")
        If @error = 2 Then MsgBox(0, "Error", "Unable to move page: " & $iFromPage & " to page: " & $iToPage & " in: '" & $sFullPath &"'")
    Else
        MsgBox(0, "Okay", "Old Page: " & $iFromPage & " moved to New Page: " & $iToPage & " in document: '" & $sFullPath &"'")
    EndIf
    $j = $j + 1     ;increment to next $iToPage
Next
MsgBox(0, "Status", "Reversed pages in: '" & $sFullPath &"'")


;be polite and close document
;close document
$x = _Acro_DocClose($oPdDoc)
If $x = False Then
    If @error = 1 Then MsgBox(0, "Error", "$oDoc isn't an AV/PD Doc object: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", "Document closed: '" & $sFullPath &"'")
EndIf


Exit

 

Reverse test document pp 1-4.pdf

Link to post
Share on other sites

The pages in a PDF document are 0-based, so try changing this:

$x = _Acro_PageMove($oPdDoc, $iFromPage, $iToPage)
; To this...
$x = _Acro_PageMove($oPdDoc, $iFromPage - 1, $iToPage - 1)

You'll also want to call _Acro_DocSave before closing the document, otherwise your changes won't be saved.

And finally, you do want to move that first page to the end if you're truly trying to reverse the whole document, otherwise you'll end up with pages like (1, 4, 3, 2) instead :)

(I'll make sure to add a note to the UDF on the next release about 0 or 1 based pages! Sorry for the confusion there :()

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

Link to post
Share on other sites

seadoggie01,

Okay more confusion on my part.  I indeed get 1,4,3,2, however I don't understand why.

Here's what I thought the move sequence would look like.

original order    after 1st move     after 2nd move        after 3rd move

1                                   4                             4                               4

2                                   1                             3                               3

3                                   2                             1                               2

4                                   3                             2                               1

 

Here's the code.  (Also not sure why _Acro_DocSave isn't saving file as "-saved.pdf")

;
;Acro.au3 test program
#AutoIt3Wrapper_run_debug_mode=Y    ; use this to debug in console window <--- LOOK

#include <Acro.au3>

MsgBox(0, "Test", "Testing Acro UDF")

;Reverse order of pages e.g. 1,2,3,...,n-1,n to n,n-1,...3,2,1  - ALWAYS work from bottom to top
;from seadoggie01 PDF pages are Zero based so for n pages we have 0,1,2,...,n-2,n-1 to n-1,n-2,...,2,1,0
;open it
$sFullPath = "C:\Program Files (x86)\AutoIt3\AH Code\PDF Processing\Acro UDF\Reverse test document pp 1-4.pdf"
$oPdDoc = _Acro_DocOpen($sFullPath)
If $oPdDoc = False Then
    If @error = 1 Then MsgBox(0, "Error", "Could not find file: '" & $sFullPath &"'")
    If @error = 2 Then MsgBox(0, "Error", "Document not opened: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", "Document opened: '" & $sFullPath &"'")
EndIf


;get page count so we do all pages      ;page count is Zero based!! SO it goes from 0 to $iPage-1
$iPages = _Acro_PageCount($oPdDoc)
If $iPages = False Then
    If @error = 1 Then MsgBox(0, "Error", "$oPdDoc isn't a PDDoc object: '" & $sFullPath &"'")
    If @error = 2 Then MsgBox(0, "Error", "Can't get number of pages in: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", $iPages & " pages in document: '" & $sFullPath &"'")
EndIf

$j = 1  ;init value
For $i = $iPages to 2 Step -1   ;skip last move
    $iFromPage = $iPages    ;always move from last page
    $iToPage = $j
    MsgBox(0, "Debug", "moving["& $iFromPage - 1 &"] to ["& $iToPage -1 & "]")
    $x = _Acro_PageMove($oPdDoc, $iFromPage - 1, $iToPage -1)   ;-1 because Zero based
    If $x = False Then
        If @error = 1 Then MsgBox(0, "Error", "$oPdDoc isn't a PDDoc object: '" & $sFullPath &"'")
        If @error = 2 Then MsgBox(0, "Error", "Unable to move page: " & $iFromPage & " to page: " & $iToPage & " in: '" & $sFullPath &"'")
    Else
        MsgBox(0, "Okay", "Old Page: " & $iFromPage & " moved to New Page: " & $iToPage & " in document: '" & $sFullPath &"'")
    EndIf
    $j = $j + 1     ;increment to next $iToPage
Next
MsgBox(0, "Status", "Reversed pages in: '" & $sFullPath &"'")


;save the document
$sFullPath = StringTrimRight($sFullPath, 4) & "-saved.pdf"  ;name it "-saved.pdf"
MsgBox(0, "Debug", "$sFullPath = '" & $sFullPath &"'")
$x = _Acro_DocSave($oPdDoc, $sFullPath)
MsgBox(0, "Debug", "$x = '" & $x &"'")
If $x = False Then
    If @error = 1 Then MsgBox(0, "Error", "$oPdDoc isn't a PDDoc object: '" & $sFullPath &"'")
    If @error = 2 Then MsgBox(0, "Error", "Document not saved: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", "Document saved: '" & $sFullPath &"'")
EndIf


;be polite and close document
;close document
$x = _Acro_DocClose($oPdDoc)
If $x = False Then
    If @error = 1 Then MsgBox(0, "Error", "$oDoc isn't an AV/PD Doc object: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", "Document closed: '" & $sFullPath &"'")
EndIf


Exit

 

Link to post
Share on other sites

Because the pages are 0-based, you'll need to subtract 1 from the number of pages in your For loop (For $i = $iPages -1 To 2 Step -1)

What do you mean by "_Acro_DocSave isn't saving file as "-saved.pdf"? Is it returning an error? 

There's an error in _Acro_DocSave: it won't return True if there's not an error. I'll add that to my ToDo-list when I get back from vacation :) 

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

Link to post
Share on other sites
  • 2 weeks later...

@ahha I got back from vacation and completely forgot about this, my sincere apologies. Fortunately, I think I may have solved your _Acro_DocSave issue... there's a minor note in the documentation that explains the PDSaveLinearized flag. In order to use the flag, it appears that changes to the document cannot be made. So, try saving your document like this instead:

_Acro_DocSave($oPdDoc, $sFullPath, $PDSaveFull)

This overrides my default value of $PDSaveFull + $PDSaveLinearized, which worked for me when my documents weren't saving. :) I'll add a note about the flag and the lack of an error when using the flag as well as change the default in my next release. Hopefully I can get that out next week.

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

Link to post
Share on other sites

seadoggie01,

How do I add a sub bookmark?

Like this

Page 1   <-- main top level bookmark

     Page 2   <-- 1st sub bookmark

          Page 3   <-- 2nd sub bookmark

                Page 4   <-- 3rdsub bookmark

Is it the $oParent somehow?

Here's what I've got.

Thanks

;
;v1k - trying to add bookmarks
;v1j - messing around
;v1i - updated _Acro_DocSave($oPdDoc, $sFullPath, $PDSaveFull) see https://www.autoitscript.com/forum/topic/202026-acroau3-udf/?tab=comments#comment-1449581
;Acro.au3 test program
#AutoIt3Wrapper_run_debug_mode=Y    ; use this to debug in console window <--- LOOK

#include <Acro.au3>

MsgBox(0, "Test", "Testing Acro UDF")

;open it
$sFullPath = "C:\Program Files (x86)\AutoIt3\AH Code\PDF Processing\Acro UDF\Bookmark test document pp 1-4.pdf"
$oPdDoc = _Acro_DocOpen($sFullPath)
If $oPdDoc = False Then
    If @error = 1 Then MsgBox(0, "Error", "Could not find file: '" & $sFullPath &"'")
    If @error = 2 Then MsgBox(0, "Error", "Document not opened: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", "Document opened: '" & $sFullPath &"'")
EndIf


;get page count so we do all pages      ;page count is Zero based!! SO it goes from 0 to $iPage-1
$iPages = _Acro_PageCount($oPdDoc)
If $iPages = False Then
    If @error = 1 Then MsgBox(0, "Error", "$oPdDoc isn't a PDDoc object: '" & $sFullPath &"'")
    If @error = 2 Then MsgBox(0, "Error", "Can't get number of pages in: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", $iPages & " pages in document: '" & $sFullPath &"'")
EndIf

;v1k - add bookmarks
;For $i = 0 to $iPages-1    ;zero based ;Note works BUT with this 0,...,n-1 the order in the BM panel is n-1,..0 - really want it reversed so start at bottom and work to top BM
For $i = $iPages-1  to 0 step -1    ;zero based
    $sName = $i + 1     ;just bookmark with the page number
    $iPage = $i
    $iIndex = 0         ;zero based - this shifts the BM panel presentation order  ;$iIndex=0 gives 1,2,3,4     ;$iIndex=1 gives 4,1,2,3
    $oParent = Default  ;? (top level) - not sure how to declare an object parent for a bookmark (page?)
    $x = _Acro_DocBookmarkAdd($oPdDoc, $sName, $iPage, $iIndex, $oParent)
    MsgBox(0, "Debug", "$x = '" & $x &"'" & " @error = '" & @error & "'")
    If $x = False Then
        If @error = 1 Then MsgBox(0, "Error", "$oPdDoc isn't a PDDoc object: '" & $sFullPath &"'")
        If @error = 2 Then MsgBox(0, "Error", "_Acro_DocJSObject returned an error: @extended set to it's @error." & @CRLF & "@extended = '"& @extended & "'")
    Else
        MsgBox(0, "Okay", "Page: " & $i & " should be bookmarked with '" & $sName &"'") ;skipped because $x='' and @error ='0'
    EndIf
Next


;save the document
$sFullPath = StringTrimRight($sFullPath, 4) & "-saved.pdf"  ;name it "-saved.pdf"
MsgBox(0, "Debug", "$sFullPath = '" & $sFullPath &"'")
$x = _Acro_DocSave($oPdDoc, $sFullPath, $PDSaveFull)    ;v1i using $PDSaveFull
MsgBox(0, "Debug", "$x = '" & $x &"'")
If $x = False Then
    If @error = 1 Then MsgBox(0, "Error", "$oPdDoc isn't a PDDoc object: '" & $sFullPath &"'")
    If @error = 2 Then MsgBox(0, "Error", "Document not saved: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", "Document saved: '" & $sFullPath &"'")
EndIf


;be polite and close document
;close document
$x = _Acro_DocClose($oPdDoc)
If $x = False Then
    If @error = 1 Then MsgBox(0, "Error", "$oDoc isn't an AV/PD Doc object: '" & $sFullPath &"'")
Else
    MsgBox(0, "Okay", "Document closed: '" & $sFullPath &"'")
EndIf


Exit

 

Bookmark test document pp 1-4.pdf

Link to post
Share on other sites

I haven't actually implemented that yet :D I was hoping that the result of _Acro_DocBookmarkAdd would return the bookmark object, but it appears to return nothing or something else undocumented that relates to JavaScript. If you check out the methods inside of that function, you'll see that I'm accessing the JavaScript object of the document to get access to bookmarks. I haven't had much time to play around with them yet, so currently there isn't a built-in way to manipulate them. 

You can get access to the JavaScript object through _Acro_DocJSObject and manipulate it through something like this (untested code):

Local $oPdDoc = _Acro_DocOpen("file")
Local $oJS    = _Acro_DocJSObject($oPdDoc)  ; $oJS is now equal to "this" in the JavaScript reference

; Get the root level bookmark, an imaginary bookmark that doesn't display, but holds all other top level bookmarks
Local $oRootBkmk = $oJS.bookmarkRoot

; Get a 1-d array of child bookmark objects
Local $aoChildBkmk = $oRootBkmk.children

For $i=0 To Ubound($aoChildBkmk) - 1
    
    ; Print the name
    ConsoleWrite($aoChildBkmk[$i].name)
    
    ; Add a child bookmark to it (Name, Javascript to execute when clicked, index of parent)
    $aoChildBkmk[$i].createChild($aoChildBkmk[$i].name & "'s - Child", "this.pageNum++", 0)
Next

I haven't added much code related to bookmarks yet, but I'm happy to add some when I get some time, let me know if you're interested :) I've been thinking about doing this lately anyways.

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Kanashius
      This UDF can be used to simply edit an Listview. There will be created an inputfield at the position of the subitem, with enter you save, use esc to interrupt,...
      You can specify single rows and cols or single field (giving row and col,...), also you can specify, if a singleclick or a doubleclick is needed to edit.
      If you like it, please leave me a comment, also if you have any suggestions to make it better or if you found bugs.
      I reworked the UDF with AutoIt v3.3.16.1 and added the functionality to use tab to go to the next cell.
      New Version: ListViewEditInput.au3 with example Example.au3
      The old version is left here: ListViewEditInput_v1_1_0.au3 with example Example_v1_1_0.au3
    • By noellarkin
      Other than different methodologies, are there any differences between the two? Does one work out to be faster or more reliable than the other when deployed at scale? I'm trying out both UDFs, was curious which method is preferred by the community.
    • By kurtykurtyboy
      GuiFlatButton is a UDF to easily create regular buttons with different colors for background, foreground, border, hover, focus, etc..
      This started as an effort to change the background color of a button and eventually grew into a full UDF.
      If you've looked around forums for changing button background colors, you have probably noticed that each proposed workaround has its own set of issues/side-effects. The answers usually circle back to 'use ownerdrawn buttons' and 'not worth it'. Well, now it is possible for anyone to easily create ownerdrawn buttons - totally worth it!
      Some issues with other workarounds such as drawing with GDI+ or using a colored label as a 'button':
      Not 'real' buttons so you lose built-in functionality that windows gives to buttons Messy / inefficient code in the main while loop to check for mouse position Slow to respond to click, paint, etc... Having to deal with GUIRegisterMsg messages Not straight-forward to implement GuiFlatButton is not a workaround; it is a technique to respond to Windows' built-in owner-drawn button events.
      With minimal effort, we can now create true simple colored buttons.
      The idea is to create an owner-drawn button using GUICtrlCreateButton then subclass the GUI and controls to handle the button-specific events to paint it however we want.
      This UDF magically does all of this for us! No need to worry about event handling or main while loop logic.
       
      How to use
      It couldn't be any easier! Simply create a new button using the familiar syntax. This creates an ownerdrawn button with default colors.
      $mybutton1 = GuiFlatButton_Create("Button 1", 78, 20, 120, 40) If you want to change the background and text colors:
      GuiFlatButton_SetBkColor(-1, 0x5555FF) GuiFlatButton_SetColor(-1, 0xFFFFFF) Advanced Usage
      Set background/text/border all at once
      GuiFlatButton_SetColors(-1, 0x0000FF, 0xFFFFFF, 0x9999FF) Set ALL colors for ALL button states! (normal, focus, hover, selected)
      Local $aColorsEx = [0x0000FF, 0xFFFFFF, -2, 0x4444FF, 0xFFFFFF, 0xAAAAFF, 0x6666FF, 0xFFFFFF, 0xCCCCFF, 0x0000EE, 0xFFFFFF, 0x7777EE] GuiFlatButton_SetColorsEx(-1, $aColorsEx) Set default colors to apply to any future buttons
      ;set colors GuiFlatButton_SetDefaultColors(0x0000FF, 0xFFFFFF, 0x9999FF) ;create buttons $mybutton1 = GuiFlatButton_Create("Button 1", 12, 20, 120, 40) $mybutton2 = GuiFlatButton_Create("Button 2", 143, 20, 120, 40) Set ALL color defaults
      ;set colors Local $aColorsEx = [0x0000FF, 0xFFFFFF, -2, 0x4444FF, 0xFFFFFF, 0xAAAAFF, 0x6666FF, 0xFFFFFF, 0xCCCCFF, 0x0000EE, 0xFFFFFF, 0x7777EE] GuiFlatButton_SetDefaultColorsEx($aColorsEx) ;create buttons $mybutton1 = GuiFlatButton_Create("Button 1", 12, 20, 120, 40) $mybutton2 = GuiFlatButton_Create("Button 2", 143, 20, 120, 40)  
      Available Functions
       
      Simple Example

      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include "GuiFlatButton.au3" Example() ;GUI with one button Func Example() Local $hGUI, $mybutton1 $hGUI = GUICreate("GuiFlatButton Ex0", 275, 120) GUISetBkColor(0x333333) Local $idLabel = GUICtrlCreateLabel("Click the button", 10, 100, 150, 30) GUICtrlSetColor(-1, 0xFFFFFF) ;create new button then set the background and foreground colors $mybutton1 = GuiFlatButton_Create("Button 1" & @CRLF & "Line 2", 78, 20, 120, 40, $BS_MULTILINE) GuiFlatButton_SetBkColor(-1, 0x5555FF) GuiFlatButton_SetColor(-1, 0xFFFFFF) GUISetState(@SW_SHOW, $hGUI) Local $i = 0 Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $mybutton1 $i += 1 GUICtrlSetData($idLabel, $i) ConsoleWrite($i & @CRLF) EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example
      Menu/Toolbar Example

      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include "GuiFlatButton.au3" Example() ;Example GUI with toolbar Func Example() Local $hGUI, $idLabel, $aButtons, $iTbSize $hGUI = GUICreate("GuiFlatButton Ex2", 300, 200) GUISetBkColor(0x444444) $idLabel = GUICtrlCreateLabel("Click a button", 10, 180, 150, 30) GUICtrlSetColor(-1, 0xFFFFFF) $aButtons = createToolbar() $iTbSize = UBound($aButtons) GUISetState(@SW_SHOW, $hGUI) Local $i = 0 Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $aButtons[0] To $aButtons[$iTbSize - 1] ConsoleWrite("1") GUICtrlSetData($idLabel, GuiFlatButton_Read($iMsg)) EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example Func createToolbar() Local $aButtons[6] Local $bkColor = 0x777777 Local $textColor = 0xFFFFFF Local $borderColor = 0x999999 Local $aBtnClrs[12] = [0x777777, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT, 0x888888, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT, 0x999999, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT, 0x666666, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT] For $i = 0 To UBound($aButtons) - 1 $aButtons[$i] = GuiFlatButton_Create("B" & $i, $i * 50, 0, 50, 17) GuiFlatButton_SetColorsEx($aButtons[$i], $aBtnClrs) Next Return $aButtons EndFunc ;==>createToolbar  
      Icon Example
      You can even easily add icons to your buttons -- just create a new button and send it an icon!

      #include <GDIPlus.au3> #include "GuiFlatButton.au3" Example() ;buttons with Icon images Func Example() ;get images for demonstration _GDIPlus_Startup() ;initialize GDI+ Local $hIcon = _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 258, 24, 24) ;extract the 'Save' icon Local $hBitmap = _GDIPlus_BitmapCreateFromHICON($hIcon) ;Create Bitmap from Icon (for demonstration) Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;Create HBitmap from Bitmap _GDIPlus_BitmapDispose($hBitmap) ;dispose the bitmap _GDIPlus_Shutdown() ;done with GDI+ Local $hGUI = GUICreate("GuiFlatButton Ex5", 255, 400) GUISetBkColor(0xEEEEEE) ;set default colors of future buttons Local $aColorsEx = _ [0xE2E5E8, 0X000000, 0x888888, _ ; normal : Background, Text, Border 0xE2E5E8, 0X000000, 0x333333, _ ; focus : Background, Text, Border 0xE8E8E8, 0X000000, 0x666666, _ ; hover : Background, Text, Border 0xDDDDDD, 0X000000, 0xAAAAAA] ; selected : Background, Text, Border GuiFlatButton_SetDefaultColorsEx($aColorsEx) ;normal button with icon $label1 = GUICtrlCreateLabel( "$BS_TOOLBUTTON -->", 5, 10) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Local $mybutton1 = GuiFlatButton_Create("Save", 130, 5, 50, 48, $BS_TOOLBUTTON) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybutton1), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align top Local $mybuttonT = GuiFlatButton_Create("Top", 5, 65, 120, 55, $BS_TOP) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonT), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align top-left Local $mybuttonTL = GuiFlatButton_Create("Top-Left", 5, 125, 120, 55, BITOR($BS_TOP, $BS_LEFT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonTL), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align top-right Local $mybuttonTR = GuiFlatButton_Create("Top-Right", 5, 185, 120, 55, BITOR($BS_TOP, $BS_RIGHT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonTR), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align left Local $mybuttonL = GuiFlatButton_Create("Left", 5, 245, 120, 55, $BS_LEFT) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonL), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align bottom Local $mybuttonB = GuiFlatButton_Create("Bottom", 130, 65, 120, 55, $BS_BOTTOM) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonB), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align bottom-left Local $mybuttonBL = GuiFlatButton_Create("Bottom-Left", 130, 125, 120, 55, BITOR($BS_BOTTOM, $BS_LEFT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonBL), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align bottom-right Local $mybuttonBR = GuiFlatButton_Create("Bottom-Right", 130, 185, 120, 55, BITOR($BS_BOTTOM, $BS_RIGHT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonBR), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align right Local $mybuttonR = GuiFlatButton_Create("Right", 130, 245, 120, 55, $BS_RIGHT) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonR), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) GuiFlatButton_SetState($mybuttonR, $GUI_DISABLE ) ;disabled Local $mybuttonDisable = GuiFlatButton_Create("Disabled", 130, 310, 120, 55, $BS_TOOLBUTTON) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonDisable), $BM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)) GuiFlatButton_SetState($mybuttonDisable, $GUI_DISABLE ) ;clean up! _WinAPI_DestroyIcon( $hIcon ) _WinAPI_DeleteObject( $hHBitmap ) GUISetState(@SW_SHOW, $hGUI) Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example  
      I'm sure there are some use-cases I've forgotten, so feedback is welcome!
       
      Download the latest UDF and several more examples:
      GuiFlatButton_20220919.zip (1,121)
      Update 2022-09-19
      Added update from 05/25 back in after it was accidentally removed
      Update 2022-09-01
      Added $BS_MULTILINE button style
      Added ellipses when text is longer than the button
      Fixed compatibility with Opt("MustDeclareVars", 1)
      Update 2022-05-25
      Fixed issue, buttons disappear when a GUI containing a child window with WS_EX_MDICHILD extended style is moved
      Update 2022-05-24
      Fixed issue releasing subclassing when GUI is deleted but program is not closed
      Fixed occasional white background flicker
      Added function GuiFlatButton_GetPos
      Update 2021-01-02
      Fixed bug, not drawing correctly after deleting GUI with GUIDelete()
      Fixed bug, changing default colors changed all buttons, even previously created buttons
      Made some internal functions more efficient
      Update 2019-04-14
      Fixed bug, not showing pressed down state when clicking rapidly
      Added Icon/Bitmap support!
      Added function GuiFlatButton_SetPos to change the position and/or size of a button
      Update 2019-02-09
      Added 2 new functions to set the button colors globally for all future buttons.
      GuiFlatButton_SetDefaultColors 
      GuiFlatButton_SetDefaultColorsEx

      Credits to:
      Melba23 (UDF template)
      LarsJ (general subclassing code)
      4ggr35510n (TrackMouseEvent example)
      binhnx (disable dragging with $WS_EX_CONTROLPARENT)
      GUIRegisterMsg in AutoIt Help (owner-draw button example)
      funkey (_WinAPI_DrawState example)
       
       
       
       
    • By t0nZ
      Always searching for the "final" solution to my zipping/unzipping needs, I started years ago using WinRar with AutoIT (don't ask me why...) and for the last 10 years I worked well with the _zip.UDF , a good solution using the embedded windows zipfldr.dll.
      But often I work with a lot of data (both multi gigabytes and/or 100K+ files) and I noticed the performance of the windows zip DLL are not so good, the problem is maybe worsened by the mono thread operation using AutoIT +  zipfldr.dll.
      SO my choice is 7zip (7ZA.exe)  also for licence (freeware also for business) reasons, and I wrote a small and simple UDF:
      ; #INDEX# ======================================================================================================================= ; Title .........: _7za ; AutoIt Version : 3.3.16.0 ; Language ......: English ; Description ...: Functions for using 7za.exe archive manipulation app ; Author(s) .....: NSC ; Version .......: 1.2 ; Date ..........: 2022/06/28 ; =============================================================================================================================== ; ------------------------------------------------------------------------------ ; This software is provided 'as-is', without any express or ; implied warranty. In no event will the authors be held liable for any ; damages arising from the use of this software. ; #INCLUDES# =================================================================================================================== ; #include-once #include <AutoItConstants.au3> ; =============================================================================================================================== ; #VARIABLES# =================================================================================================================== ; Global Global $7za_exe = @ScriptDir & "\" & "7za.exe" ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _EXEC7za ;_UNcompress_7za ;_COMpress_7za_7z ;_COMpress_7za_zip ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _EXEC7za ; Description ...: launch 7Za.exe with params and returns exit codes ; Syntax ........: EXEC7za($7zCommands, $archive, $folder[, $show]) ; Parameters ....: $7zCommands - 7zip command line params ; $archive - complete path to the archive ; $folder - the source/destination folder ; $show - optional set the state of 7za console visibility, default @SW_HIDE, ; other values as ShellExecuteWait() ; Return values .: 1 - Success ; 0 - and set @error = 1 ; and ; @extended = 1 (Warning (Non fatal error(s)) ; @extended = 2 (Fatal error) ; @extended = 7 (Command line error) ; @extended = 8 (Not enough memory for operation) ; @extended = 255 (User stopped the process) ; @extended values set by 7za.exe exit codes ; Author ........: NSC ; Modified ......: 2022/05/13 ; Remarks .......: requires 7za.exe in @scriptdir, 7za.exe (7-Zip Extra: standalone console version) ; Thanks to 7-zip.org ; Related .......: ; Link ..........: ; Examples .......: compress a folder recursive with subfolders ; EXEC7za("u -mx4 -bt", c:\folder1\archive.7z", c:\folder1\folderTOcompress\ ) ; uncompress the same folder recursive ; EXEC7za("x -aoa -bt -r", "c:\folder1\archive.7z", "-oc:\folder2\") ; =============================================================================================================================== Func _EXEC_7za($7zCommands, $archive, $folder, $show = @SW_HIDE) Local $return7za = ShellExecuteWait($7za_exe, $7zCommands & ' "' & $archive & '" "' & $folder & '"', '', $SHEX_OPEN, $show) Select Case $return7za = 0 Return 1 Case Else Return SetError(1, $return7za, 0) EndSelect EndFunc ;==>_EXEC_7za ; #FUNCTION# ==================================================================================================================== ; Name ..........: _UNcompress_7za ; Description ...: launch 7Za.exe with preset params to uncompress an archive (.7z or .zip recursively) and returns exit codes ; Syntax ........: _UNcompress_7za($archive, $folder[, $show]) ; Parameters ....: $archive - complete path to the archive ; $folder - the source/destination folder ; $show - optional set the state of 7za console visibility, default @SW_HIDE, ; other values as ShellExecuteWait() ; Return values .: 1 - Success ; 0 - and set @error = 1 ; and ; @extended = 1 (Warning (Non fatal error(s)) ; @extended = 2 (Fatal error) ; @extended = 7 (Command line error) ; @extended = 8 (Not enough memory for operation) ; @extended = 255 (User stopped the process) ; @extended values set by 7za.exe exit codes ; Author ........: NSC ; Modified ......: 2022/05/19 ; Remarks .......: requires 7za.exe in @scriptdir, 7za.exe (7-Zip Extra: standalone console version) ; Thanks to 7-zip.org ; Related .......: ; Link ..........: ; =============================================================================================================================== Func _UNcompress_7za($archive, $folder, $show = @SW_HIDE) Local $return7za = ShellExecuteWait($7za_exe, "x -aoa -bt -r" & ' "' & $archive & '" -o"' & $folder & '"', '', $SHEX_OPEN, $show) Select Case $return7za = 0 Return 1 Case Else Return SetError(1, $return7za, 0) EndSelect EndFunc ;==>_UNcompress_Folder_7za ; #FUNCTION# ==================================================================================================================== ; Name ..........: _COMpress_7za_7z ; Description ...: launch 7Za.exe with precompiled params to compress in .7z format ;a single file, a filtered (*.pdf) bunch of files or a folder (recursively) and returns exit codes ; Syntax ........: _COMpress_7za_7z($archive, $folder[, $show [, $compLvl]] ) ; Parameters ....: $archive - complete path to the archive ; $folder - the source file(s) / folder ; $show - optional set the state of 7za console visibility, default @SW_HIDE, ; other values as ShellExecuteWait() ; $CompLvl - optional compression level (1-9) default 4 ; Return values .: 1 - Success ; 0 - and set @error = 1 ; and ; @extended = 1 (Warning (Non fatal error(s)) ; @extended = 2 (Fatal error) ; @extended = 7 (Command line error) ; @extended = 8 (Not enough memory for operation) ; @extended = 255 (User stopped the process) ; @extended values set by 7za.exe exit codes ; Author ........: NSC ; Modified ......: 2022/06/22 ; Remarks .......: requires 7za.exe in @scriptdir, 7za.exe (7-Zip Extra: standalone console version) ; avoids re-compress of popular archives. ; Thanks to 7-zip.org ; Related .......: ; Link ..........: ; =============================================================================================================================== Func _COMpress_7za_7z($archive, $folder, $show = @SW_HIDE, $CompLvl = 4) If StringRight($folder, 4) = ".zip" Or StringRight($folder, 3) = ".7z" Or StringRight($folder, 4) = ".rar" Or StringRight($folder, 4) = ".lha" Or StringRight($folder, 3) = ".gz" Or StringRight($folder, 7) = ".tar.gz" Or StringRight($folder, 4) = ".iso" Then $CompLvl = 0 EndIf Local $return7za = ShellExecuteWait($7za_exe, 'u -mx' & $CompLvl & ' -mmt -bt' & ' "' & $archive & '" "' & $folder & '"', '', $SHEX_OPEN, $show) Select Case $return7za = 0 Return 1 Case Else Return SetError(1, $return7za, 0) EndSelect EndFunc ;==>_COMpress_7za_7z ; #FUNCTION# ==================================================================================================================== ; Name ..........: _COMpress_7za_zip ; Description ...: launch 7Za.exe with precompiled params to compress in zip format ; a single file, a filtered (*.pdf) bunch of files or a folder (recursively) and returns exit codes ; Syntax ........: _COMpress_7za_zip($archive, $folder[, $show [, $compLvl]] ) ; Parameters ....: $archive - complete path to the archive ; $folder - the source file(s) / folder ; $show - optional set the state of 7za console visibility, default @SW_HIDE, ; other values as ShellExecuteWait() ; $CompLvl - optional compression level (1-9) default 4 ; Return values .: 1 - Success ; 0 - and set @error = 1 ; and ; @extended = 1 (Warning (Non fatal error(s)) ; @extended = 2 (Fatal error) ; @extended = 7 (Command line error) ; @extended = 8 (Not enough memory for operation) ; @extended = 255 (User stopped the process) ; @extended values set by 7za.exe exit codes ; Author ........: NSC ; Modified ......: 2022/06/22 ; Remarks .......: requires 7za.exe in @scriptdir, 7za.exe (7-Zip Extra: standalone console version), ; avoids re-compress of popular archives. ; Thanks to 7-zip.org ; Related .......: ; Link ..........: ; =============================================================================================================================== Func _COMpress_7za_zip($archive, $folder, $show = @SW_HIDE, $CompLvl = 9) If StringRight($folder, 4) = ".zip" Or StringRight($folder, 3) = ".7z" Or StringRight($folder, 4) = ".rar" Or StringRight($folder, 4) = ".lha" Or StringRight($folder, 3) = ".gz" Or StringRight($folder, 7) = ".tar.gz" Or StringRight($folder, 4) = ".iso" Then $CompLvl = 0 EndIf Local $return7za = ShellExecuteWait($7za_exe, 'u -tzip -mx' & $CompLvl & ' -mmt -bt' & ' "' & $archive & '" "' & $folder & '"', '', $SHEX_OPEN, $show) Select Case $return7za = 0 Return 1 Case Else Return SetError(1, $return7za, 0) EndSelect EndFunc ;==>_COMpress_7za_zip You have to provide 7za.exe, in scriptdir in some way, maybe with a fileinstall or embedding in some way. 
      Daily I use most of the time:
      _UNcompress_7za
      _COMpress_7za_7z
      so I'am almost done with these funcs....
      Also I made a quick and dirty benchmark on some real world data (for me at least) , comparing the windows DLL, the zip ULTRA by 7zip and the various 7zip levels.

      My choice is level 4 (time/size) but your mileage may vary...
      Also, extracting many thousands of little files from a 7z archive with 7zip is waaaay fast in respect to other solutions.
    • By Kanashius
      This UDF can be used to draw at the Desktop Wallpaper (Windows 8+) with GDI+ without using files.
      The example runs with 60-120fps at my machine, so the speed is acceptable.
      When the script exits, the original wallpaper is restored.
      Have fun :).
      PS: The UDF uses the window between the background and the icons, so it could be used to add an own child window at the desktop. Just look at the begin of __Wallpaper_Startup ($hWorkerW).
       
      Example:
       
      WallpaperUDF.au3 WallpaperUDF Example.au3
×
×
  • Create New...