Jump to content

Recommended Posts

  • Developers

Just tested with the latest version and don't see that issue. Could you open telegram.au3 and uncomment line 791, so it will display the received text?

Func _Polling()
    While 1
        Sleep(1000) ;Prevent CPU Overloading
        $newUpdates = _GetUpdates()
        ConsoleWrite($newUpdates & @CRLF)
        If Not StringInStr($newUpdates,'update_id') Then ContinueLoop
        $msgData = __MsgDecode($newUpdates)
        $OFFSET = $msgData[0] + 1
        ;ConsoleWrite(_ArrayToString($msgData) & @CRLF)
        Return $msgData
    WEnd
EndFunc ;==> _Polling

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
  • Replies 110
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Hi! I wrote an UDF that can simplify the way you can control Telegram Bot with AutoIt. If you don't know what is a Telegram Bot, maybe you should read their official website here. All about this UDF i

Added to UDF List on AutoIt WikiPage, here: https://www.autoitscript.com/wiki/User_Defined_Functions#Social_Media_and_other_Website_API  

Perhaps we should give people who post UDFs a short time to get feedback from the community and improve the scripts, before we rush to add them to the Wiki.

Posted Images

13 minutes ago, Jos said:

Could you open telegram.au3 and uncomment line 791, so it will display the received text?

Sure. Here's what I got (changed the numbers and names):

{"ok":true,"result":[{"update_id":3047043522550647,
"my_chat_member":{"chat":{"id":-81145169345617,"title":"GroupName","type":"group","all_members_are_administrators":true},"from":{"id":316898134589,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"date":1671734534514725,"old_chat_member":{"user":{"id":5951434506661,"is_bot":true,"first_name":"BotName","username":"BotUsername"},"status":"left"},"new_chat_member":{"user":{"id":595134535406661,"is_bot":true,"first_name":"BotName","username":"BotUsername"},"status":"member"}}},{"update_id":30345470099648,
"message":{"message_id":23,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":-81116960017,"title":"Prescott Norris Office","type":"group","all_members_are_administrators":true},"date":1671713454725,"group_chat_created":true}},{"update_id":30470070649,
"message":{"message_id":24,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1634571714973,"text":"hey"}},{"update_id":30478000650,
"message":{"message_id":25,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1673451716039,"text":"hey"}},{"update_id":30479000651,
"message":{"message_id":26,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1671456716336,"text":"test"}},{"update_id":30504700652,
"message":{"message_id":27,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1671789717549,"text":"test"}},{"update_id":30479000653,
"message":{"message_id":28,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1123671717640,"text":"test"}},{"update_id":30456700654,
"message":{"message_id":29,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1671717678652,"text":"check"}},{"update_id":33404700655,
"message":{"message_id":30,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1671789017960,"text":"Hey"}},{"update_id":30470088656,
"message":{"message_id":31,"from":{"id":31643834598189,"is_bot":false,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","language_code":"en"},"chat":{"id":316898181249,"first_name":"MyFirstName","last_name":"MyLastName","username":"telegramusername","type":"private"},"date":1671890718156,"text":"Check"}}]}

 

Link to post
Share on other sites
  • Developers

Thanks... I had a play with your received data and the issue is with the first message which isn't properly handled by this UDF, so gets stuck there. This also explains why the posted work-around is fixing it as long as there isn't another message of that type.

Guess this needs to be fixed by the original owner of the UDF so you best report it at the GITHUB.

.. and the quick fix should be those 4 steps you earlier quoted, as that should skip this messages.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
5 minutes ago, Jos said:

so you best report it at the GITHUB

Sure thing, I'll do that. In the meantime I'll try out the libcurl version posted here:

Could you tell me where I should put the libcurl DLL files? Should they be in path or can I set their location using a global variable in the UDF?

Link to post
Share on other sites
  • Developers

Try replacing func __MsgDecode() with this version first as that will likely solve it for you:

Func __MsgDecode($Update)
    Local $json = Json_Decode($Update)

    ;@PRIVATE CHAT MESSAGE

    If (Json_Get($json, '[result][0][message][chat][type]') = 'private') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _
                Json_Get($json, '[result][0][message][message_id]'), _
                Json_Get($json, '[result][0][message][from][id]'), _
                Json_Get($json, '[result][0][message][from][username]'), _
                Json_Get($json, '[result][0][message][from][first_name]') _
                ]

        If (Json_Get($json, '[result][0][message][text]')) Then $msgData[5] = Json_Get($json, '[result][0][message][text]')

        ; TODO: Media recognition

        Return $msgData

        ;@GROUP CHAT MESSAGE (Inlude left/new member events)
    ElseIf (Json_Get($json, '[result][0][message][chat][type]') = 'group') Or (Json_Get($json, '[result][0][message][chat][type]') = 'supergroup') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][message][message_id]'), _ ;[1] = Message ID
                Json_Get($json, '[result][0][message][from][id]'), _ ;[2] = User ID
                Json_Get($json, '[result][0][message][from][username]'), _ ;[3] = Username
                Json_Get($json, '[result][0][message][from][first_name]'), _ ;[4] = Firstname
                Json_Get($json, '[result][0][message][chat][id]'), _ ;[5] = Group ID
                Json_Get($json, '[result][0][message][chat][title]') _ ;[6] = Group Name
                ]

        If (Json_Get($json, '[result][0][message][left_chat_member]')) Then
            $msgData[7] = 'left' ;[7] = Event
            $msgData[8] = Json_Get($json, '[result][0][message][from][id]') ;[8] = Left member ID
            $msgData[9] = Json_Get($json, '[result][0][message][from][username]') ;[9] = Left member Username
            $msgData[10] = Json_Get($json, '[result][0][message][from][first_name]') ;[10] = Left member Firstname
        ElseIf (Json_Get($json, '[result][0][message][new_chat_member]')) Then
            $msgData[7] = 'new' ;[7] = Event
            $msgData[8] = Json_Get($json, '[result][0][message][from][id]') ;[8] = New member ID
            $msgData[9] = Json_Get($json, '[result][0][message][from][username]') ;[9] = New member Username
            $msgData[10] = Json_Get($json, '[result][0][message][from][first_name]') ;[10] = New member Firstname
        Else
            $msgData[7] = Json_Get($json, '[result][0][message][text]') ;[7] = Text
        EndIf

        Return $msgData

        ;@EDITED PRIVATE CHAT MESSAGE
    ElseIf (Json_Get($json, '[result][0][edited_message][chat][type]') = 'private') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][edited_message][message_id]'), _ ;[1] = Message ID
                Json_Get($json, '[result][0][edited_message][from][id]'), _ ;[2] = Chat ID
                Json_Get($json, '[result][0][edited_message][from][username]'), _ ;[3] = Username
                Json_Get($json, '[result][0][edited_message][from][first_name]') _ ;[4] = Firstname
                ]

        If (Json_Get($json, '[result][0][edited_message][text]')) Then $msgData[5] = Json_Get($json, '[result][0][edited_message][text]') ;[5] = Text (eventually)

        ;Insert media recognition here

        Return $msgData

        ;@EDITED GROUP CHAT MESSAGE
    ElseIf (Json_Get($json, '[result][0][edited_message][chat][type]') = 'group') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][edited_message][message_id]'), _ ;[1] = Message ID
                Json_Get($json, '[result][0][edited_message][from][id]'), _ ;[2] = Chat ID
                Json_Get($json, '[result][0][edited_message][from][username]'), _ ;[3] = Username
                Json_Get($json, '[result][0][edited_message][from][first_name]') _ ;[4] = Firstname
                ]

        If (Json_Get($json, '[result][0][edited_message][text]')) Then $msgData[5] = Json_Get($json, '[result][0][edited_message][text]') ;[5] = Text (eventually)

        ;Insert media recognition here

        Return $msgData

        ;@CALLBACK QUERY
    ElseIf (Json_Get($json, '[result][0][callback_query][id]') <> '') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][callback_query][id]'), _ ;[1] = Callback ID
                Json_Get($json, '[result][0][callback_query][from][id]'), _ ;[2] = Chat ID
                Json_Get($json, '[result][0][callback_query][from][username]'), _ ;[3] = Username
                Json_Get($json, '[result][0][callback_query][from][first_name]'), _ ;[4] = Firstname
                Json_Get($json, '[result][0][callback_query][data]') _ ;[5] = Callback Data
                ]

        Return $msgData

        ;@INLINE QUERY
    ElseIf (Json_Get($json, '[result][0][inline_query][id]') <> '') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][inline_query][id]'), _ ;[1] = Inline Query ID
                Json_Get($json, '[result][0][inline_query][from][id]'), _ ;[2] = Chat ID
                Json_Get($json, '[result][0][inline_query][from][username]'), _ ;[3] = Username
                Json_Get($json, '[result][0][inline_query][from][first_name]'), _ ;[4] = Firstname
                Json_Get($json, '[result][0][inline_query][query]') _ ;[5] = Inline Query Data
                ]

        Return $msgData

        ;@CHANNEL MESSAGE (Where bot is admin)
        ; Sample JSON:
        #comments-start
            {"ok":true,"result":[{
                "update_id":<int>,
                "channel_post":{
                    "message_id":<int>,
                    "chat":{
                    "id":<int>,
                    "title":"<string>",
                    "type":"channel"},
                    "date":<int>,
                    "text":"<string>"
            }}]}
        #comments-end
    ElseIf (Json_Get($json, '[result][0][channel_post][message_id]') <> '') Then
        Local $msgData[5] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][channel_post][message_id]'), _ ;[1] = Message ID
                Json_Get($json, '[result][0][channel_post][chat][id]'), _ ;[2] = Chat ID
                Json_Get($json, '[result][0][channel_post][chat][title]') _ ;[3] = Firstname
                ]

        If (Json_Get($json, '[result][0][channel_post][text]')) Then
            $msgData[4] = Json_Get($json, '[result][0][channel_post][text]') ;[4] = Text (eventually)
        EndIf

        Return $msgData

        ;@EDITED CHANNEL CHAT MESSAGE
    ElseIf (Json_Get($json, '[result][0][edited_channel_post][chat][type]') = 'channel') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][edited_channel_post][message_id]'), _ ;[1] = Message ID
                Json_Get($json, '[result][0][edited_channel_post][from][id]'), _ ;[2] = Chat ID
                Json_Get($json, '[result][0][edited_channel_post][from][username]'), _ ;[3] = Username
                Json_Get($json, '[result][0][edited_channel_post][from][first_name]') _ ;[4] = Firstname
                ]

        If (Json_Get($json, '[result][0][edited_channel_post][text]')) Then $msgData[5] = Json_Get($json, '[result][0][edited_channel_post][text]') ;[5] = Text (eventually)

        ;Insert media recognition here

        Return $msgData
        ;@EDITED CHANNEL CHAT MESSAGE
    ElseIf (Json_Get($json, '[result][0][my_chat_member][chat][type]') = 'group') Then
        Local $msgData[10] = [ _
                Json_Get($json, '[result][0][update_id]'), _ ;[0] = Offset
                Json_Get($json, '[result][0][my_chat_member][message_id]'), _ ;[1] = Message ID
                Json_Get($json, '[result][0][my_chat_member][from][id]'), _ ;[2] = Chat ID
                Json_Get($json, '[result][0][my_chat_member][from][username]'), _ ;[3] = Username
                Json_Get($json, '[result][0][my_chat_member][from][first_name]') _ ;[4] = Firstname
                ]
        $msgData[5] = ""
        If (Json_Get($json, '[result][0][my_chat_member][text]')) Then $msgData[5] = Json_Get($json, '[result][0][my_chat_member][text]') ;[5] = Text (eventually)

        ;Insert media recognition here

        Return $msgData

    EndIf

EndFunc   ;==>__MsgDecode

 

20 minutes ago, noellarkin said:

Could you tell me where I should put the libcurl DLL files? Should they be in path or can I set their location using a global variable in the UDF?

Looks to me you need to add that Curl UDF which is linked in that post. 
The Telegram.au3 in that version looks somewhat more ridged 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
1 hour ago, Jos said:

Try replacing func __MsgDecode() with this version first as that will likely solve it for you:

Thank you, this worked! For any forum members who may stumble upon this thread, this is a solution to the the error:

Line 794 in Telegram.au3
$OFFSET = $msgData[0] + 1
$OFFSET = $msgData^ERROR
Error: Subscript used on non-accessible variable

 

 

1 hour ago, Jos said:

Looks to me you need to add that Curl UDF which is linked in that post. 

I did, I unpacked all the files in Curl UDF to the Include folder. I also went ahead and copied the two provided dll files in the same directory as the example script (Test.au3) as well as in a folder accessible to PATH. I'm still getting "Error opening libcurl.dll" Is there any way I can set the full path in the UDF?
Furthermore, I'm getting:
image.png.44d564efd252d75cb1fdc5bf35032564.png

as well as:
image.png.f36df999dc6c912be455b94b13dff3e6.png

 

when attempting to run "Test.au3" (example file provided in the LibCurl Telegram Bot UDF).

Link to post
Share on other sites
  • 3 weeks later...
On 12/24/2022 at 5:43 AM, noellarkin said:

Update: Copying libcurl.dll and libcurl-x64.dll to C:\Windows\SysWOW64 worked

Either that (%PATH%) or to the executable's folder.

Link to post
Share on other sites
On 12/22/2022 at 2:28 PM, noellarkin said:

Tried the original UDF (downloaded from the github link in the first post), with the example script provided:

 

#include "../src/Telegram.au3"

HotKeySet("{PAUSE}","_Exit") ;Press 'PAUSE' on your keyboard to force-exit the script

$Token = "I put my token here" ;Token here
_InitBot($Token)

While 1
    $msgData = _Polling()
    ConsoleWrite("Incoming message from " & $msgData[3] & ": " & $msgData[5] & @CRLF)
    _SendMsg($msgData[2],$msgData[5])
WEnd

Func _Exit()
    Exit 0
EndFunc


Getting the error:
Line 794 in Telegram.au3

$OFFSET = $msgData[0] + 1

$OFFSET = $msgData^ERROR

Error: Subscript used on non-accessible variable

There were enough issues with the original UDF, not only this but also other false interpretations taken from the Telegram API that made this UDF not really reliable.
Not all the fault of the designer, the API chronological behavior wasn't all too clear either.

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

An apology, use google translate to change to English

I have tried the code and it works perfectly, message, photo, audio, document, voice, sticker.

I just don't see how to send a message to a telegram group or channel. Has anyone already done it?

 

Aca en español

Una disculpa, use google traductor para cambiar a ingles

He probaro el codigo y funciona a la perfeccion, mensaje, foto, audio, documento, voz, sticker. 

Solo que no veo como enviar un mensaje a un grupo o canal de telegram. Alguien ya lo logro?

Link to post
Share on other sites
Just now, jkarlos said:

An apology, use google translate to change to English

I have tried the code and it works perfectly, message, photo, audio, document, voice, sticker.

I just don't see how to send a message to a telegram group or channel. Has anyone already done it?

 

Aca en español

Una disculpa, use google traductor para cambiar a ingles

He probaro el codigo y funciona a la perfeccion, mensaje, foto, audio, documento, voz, sticker. 

Solo que no veo como enviar un mensaje a un grupo o canal de telegram. Alguien ya lo logro?

#include "../src/Telegram.au3"
#include <Array.au3>

;~ ConsoleWrite("Test file for Telegram UDF (https://github.com/xLinkOut/telegram-udf-autoit)." & @CRLF & _
;~              "This file need a valid ChatID of a Telegram user who has already sent at least a message to the bot, and a valid token given by @BotFather." & @CRLF & _
;~              "Insert this data in the source code." & @CRLF & @CRLF)

Local $ChatID = '### id' ;Your ChatID here (take this from @MyTelegramID_bot)
Local $Token  = 'Token' ;Token here

;~ If(($ChatID = '') or ($Token = '')) Then
;~     ConsoleWrite("Warning! ChatID or Token not specified!")
;~     Exit -1
;~  EndIf
_InitBot($Token)
Local $myData = _GetMe()

$MsgID = _SendMsg($ChatID,"Hola, esto es una prueba")

 

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