Sign in to follow this  
Followers 0
jvanegmond

Testing custom AutoIt API

3 posts in this topic

#1 ·  Posted (edited)

I wanted to play around with API's, and decided to try to find a way to create a API, so that other developers can create their plugins for your program. I've set this up program to show how you might go around creating an API for your program. I was wondering if anyone else has a different perspective on how to do this, or might want to share some of his or her work in this subject.

#include <GUIConstants.au3>
#include <Misc.au3>

Global $API_PREFIX = "API" ;<=======

Global $Mode = 0, $Color = 0xff0000

GUICreate("AutoIt Paint", 350,300)
GUISetBkColor(0)

$Line = GUICtrlCreateButton("Line", 300,0,50,50)
$Dot = GUICtrlCreateButton("Dot", 300,50,50,50,$SS_CENTER)
$ColorBtn = GUICtrlCreateButton("Select" & @LF & "Color", 300,100,50,50,BitOr($SS_CENTER,$BS_MULTILINE))
$ColorLbl = GUICtrlCreateLabel("", 300,150,50,20,$SS_CENTER)
GUICtrlSetBkColor(-1, $Color)

$Graphic = GUICtrlCreateGraphic(0,0,300,300)
GUICtrlSetGraphic($Graphic,$GUI_GR_COLOR, $Color)
GUISetState(@SW_SHOW)

While 1
    API() ;<=======
    
    $msg = GUIGetMsg()
    
    If $msg = -3 Then
        Exit
    ElseIf $msg = $Dot Then
        $Mode = 0
    ElseIf $msg = $Line Then
        $Mode = 1
    ElseIf $msg = $ColorBtn Then
        $NewColor = _ChooseColor (2, $Color, 2)
        If Not @error Then
            $Color = $NewColor
            GUICtrlSetBkColor($ColorLbl, $Color)
            GUICtrlSetGraphic($Graphic,$GUI_GR_COLOR, $Color)
        EndIf
    EndIf
    
    $Mouse = GUIGetCursorInfo()
    
    If $Mouse[2] = 1 AND $Mouse[4] = $Graphic Then
        If $Mode = 1 Then
            GUICtrlSetGraphic($Graphic,$GUI_GR_MOVE,$Mouse[0],$Mouse[1])
            While $Mouse[2] = 1
                $Mouse = GUIGetCursorInfo()
            WEnd
            GUICtrlSetGraphic($Graphic,$GUI_GR_LINE,$Mouse[0],$Mouse[1])
        ElseIf $Mode = 0 Then
            GUICtrlSetGraphic($Graphic,$GUI_GR_DOT,$Mouse[0],$Mouse[1])
        EndIf
        GUICtrlSetGraphic($Graphic,$GUI_GR_REFRESH)
    EndIf
WEnd

Func API_Drawline($x1,$y1,$x2,$y2) ;<=======
    GUICtrlSetGraphic($Graphic,$GUI_GR_MOVE,$x1,$y1)
    GUICtrlSetGraphic($Graphic,$GUI_GR_LINE,$x2,$y2)
    GUICtrlSetGraphic($Graphic,$GUI_GR_REFRESH)
    Return "Succesful operation"
EndFunc

Func API_Drawdot($x,$y) ;<=======
    GUICtrlSetGraphic($Graphic,$GUI_GR_DOT,$x,$y)
    GUICtrlSetGraphic($Graphic,$GUI_GR_REFRESH)
    Return "Succesful operation"
EndFunc

Func API() ;<=======
    $sIn = ConsoleRead(-1,True)
    If $sIn Then
        $sIn = ConsoleRead()
        $sSplit = StringSplit($sIn,"(,)",0)
        If $sSplit[0] >= 1 Then
            Local $sArray[$sSplit[0]-1]
            $sArray[0] = "CallArgArray"
            For $x = 2 to $sSplit[0]-1
                If StringLeft($sSplit[$x],1) == '"' AND StringRight($sSplit[$x],1) == '"' Then
                    $sSplit[$x] = String(StringTrimLeft(StringTrimRight($sSplit[$x],1),1))
                EndIf
                $sArray[$x-1] = $sSplit[$x]
            Next
            $sReturnData = Call($API_PREFIX&"_"&$sSplit[1],$sArray)
            ConsoleWrite($sReturnData)
        EndIf
    EndIf
EndFuncoÝ÷ Û÷(uæèÅ«­¢+Ø¥¹±Õ±Ðí
½¹ÍѹÑ̹ÔÌÐì((ÀÌØíA%ôIÕ¸¡Õѽ%ÑáµÀìÌäìÅÕ½ÐìÌäìµÀìMÉ¥ÁѥȵÀìÌäìÀäÈíQÍÑAɽɵ]¥Ñ¡A$¹ÔÌÅÕ½ÐìÌäì°ÅÕ½ÐìÅÕ½Ðì°´Ä°ÀÌØíMQ=UQ}
!%1¬ÀÌØíMQ%9}
!%1¤()5Í  ½à ÁàÐÀÀÀÀ°ÅÕ½ÐìÅÕ½Ðì°ÅÕ½Ðí
±¥¬Ñ¡=,ÕÑѽ¸Ñ¼Ñ¥ÙÑ¡Á±Õ¥¸°ÅÕ½ÐìµÀì
I1µÀìÅÕ½ÐíÑ¡Á±Õ¥¸Ý¥±°Ñ¡¸Éܱ¥¹¥¸Ñ¡Ý¥¹½Ü¸ÅÕ½Ðì¤()MÑ¥¹]É¥Ñ ÀÌØíA%°ÅÕ½ÐíÉݱ¥¹ À°À°ÌÀÀ°ÌÀÀ¤ÅÕ½Ðì¤)5Í  ½à ÁàÐÀÀÀÀ°ÅÕ½ÐìÅÕ½Ðì°MѽÕÑI ÀÌØíA%¤¤
Edited by Manadar

Share this post


Link to post
Share on other sites



I like the way you do this. I had to change this part to make it work:

$Mouse = GUIGetCursorInfo()
    If IsArray($Mouse) Then ;here
        If $Mouse[2] = 1 And $Mouse[4] = $Graphic Then
            If $Mode = 1 Then
                GUICtrlSetGraphic($Graphic, $GUI_GR_MOVE, $Mouse[0], $Mouse[1])
                While $Mouse[2] = 1
                    $Mouse = GUIGetCursorInfo()
                WEnd
                GUICtrlSetGraphic($Graphic, $GUI_GR_LINE, $Mouse[0], $Mouse[1])
            ElseIf $Mode = 0 Then
                GUICtrlSetGraphic($Graphic, $GUI_GR_DOT, $Mouse[0], $Mouse[1])
            EndIf
            GUICtrlSetGraphic($Graphic, $GUI_GR_REFRESH)
        EndIf
    EndIf ;here

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

Share this post


Link to post
Share on other sites

I like the way you do this. I had to change this part to make it work:

$Mouse = GUIGetCursorInfo()
    If IsArray($Mouse) Then ;here
        If $Mouse[2] = 1 And $Mouse[4] = $Graphic Then
            If $Mode = 1 Then
                GUICtrlSetGraphic($Graphic, $GUI_GR_MOVE, $Mouse[0], $Mouse[1])
                While $Mouse[2] = 1
                    $Mouse = GUIGetCursorInfo()
                WEnd
                GUICtrlSetGraphic($Graphic, $GUI_GR_LINE, $Mouse[0], $Mouse[1])
            ElseIf $Mode = 0 Then
                GUICtrlSetGraphic($Graphic, $GUI_GR_DOT, $Mouse[0], $Mouse[1])
            EndIf
            GUICtrlSetGraphic($Graphic, $GUI_GR_REFRESH)
        EndIf
    EndIf ;here
 oÝ÷ Ûú®¢×°£ajÙh¢Kjh¥ªüo+a{²¶zQÚ0*.².ÚeiDzW¦)íì!W¥¢ZºÚ"µÍÚ[H ÌÍÓ[ÝÙVÌHHB   ÌÍÓ[ÝÙHHÕRQÙ]ÝÛÜ[Ê
BÛY
JBÑ[

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0