Jump to content

Just curious, what's your opinion?


Recommended Posts

I have this script that I wrote:

CODE
#include <GuiConstants.au3>

#NoTrayIcon

Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown.

opt("WinTitleMatchMode", 3)

Global $aboutitem = TrayCreateItem("About")

TrayCreateItem("")

Global $exititem = TrayCreateItem("Exit")

TraySetState()

;HotKeySet("^!a", "toggle") ;Must click window and then back off to activate so this feature has been disabled for now.

HotKeySet("^!p", "go")

HotKeySet("^!t", "terminate")

TraySetToolTip( "PixiHex" )

TrayTip("PixiHex", "Use Ctrl+Alt+P to capture the color beneath the cursor." & @CRLF & "Use Ctrl+Alt+T to terminate.", 60)

go()

Func go()

If WinExists("PixiHex", "") Then

$xy=MouseGetPos()

$color=PixelGetColor( $xy[0] , $xy[1])

GUICtrlCreateLabel("The color of the pixel" & @CRLF & "beneath the cursor is" & @CRLF & "displayed on the right:", 13, 20)

GUICtrlCreateLabel("The Hex value of this color is: " & @CRLF & Hex($color, 6), 13, 80)

GUICtrlCreateLabel("The Decimal value of this color is: " & @CRLF & $color, 13, 120)

GuiCtrlCreateLabel("", 135, 15, 50, 50)

GuiCtrlSetBkColor(-1, 0x & $color)

Else

$xy=MouseGetPos()

$color=PixelGetColor( $xy[0] , $xy[1])

GuiCreate("PixiHex", 200, 200)

GuiSetIcon(@SystemDir & "\mspaint.exe", 0)

GUICtrlCreateLabel("The color of the pixel" & @CRLF & "beneath the cursor is" & @CRLF & "displayed on the right:", 13, 20)

GUICtrlCreateLabel("The Hex value of this color is: " & @CRLF & Hex($color, 6), 13, 80)

GUICtrlCreateLabel("The Decimal value of this color is: " & @CRLF & $color, 13, 120)

GuiCtrlCreateLabel("", 135, 15, 50, 50)

GuiCtrlSetBkColor(-1, 0x & $color)

GUICtrlCreateCheckbox("Set as Always On Top", 13, 160)

GUICtrlSetState(-1, $GUI_CHECKED)

; GUI MESSAGE LOOP

GuiSetState()

While GuiGetMsg() <> $GUI_EVENT_CLOSE

$tray = TrayGetMsg()

$checkbox=GUICtrlRead(7)

Select

Case $tray = $aboutitem

Msgbox(262144, "about:", "PixiHex was created by Me using the" & @CRLF & "AutoItv3 scripting language. Copyright 2008.")

Case $tray = $exititem

Exit

Case $checkbox = $GUI_CHECKED

WinSetOnTop("PixiHex", "", 1)

Case $checkbox = $GUI_UNCHECKED

WinSetOnTop("PixiHex", "", 0)

EndSelect

WEnd

EndIf

EndFunc

Func terminate()

Exit

EndFunc

;Func toggle()

; $check=GUICtrlRead(7)

; If $check = $GUI_CHECKED Then

; WinSetOnTop("PixiHex", "", 0)

; GUICtrlSetState(7, $GUI_UNCHECKED)

; Else

; WinSetOnTop("PixiHex", "", 1)

; GUICtrlSetState(7, $GUI_CHECKED)

; EndIf

;EndFunc

And was wondering if I did it how others would do it. The "it" part being the repetitious part under the IF statement. I had to do this to get it to update the labels when Ctrl+Alt+P was pressed. Wondering if there was a better way to do it. Just curious. Also, sorry if it is hard to read. I just started learning AutoIt a little while ago, (off and on for about a year now). AutoIt is my first scripting language and I still rely on the help files quite a bit.

Link to comment
Share on other sites

Just a quick note, the following:

GuiCtrlSetBkColor(-1, 0x & $color)

muttley

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

Feeling generous so this is how I would do it:

#include <GuiConstants.au3>
#NoTrayIcon

;set ON EVENT MODE
Opt("GUIOnEventMode", 1)

;set HOTKEY
HotKeySet("^!p", "go")

;create GUI
$GUI = GuiCreate("PixiHex", 200, 200)
GUISetOnEvent($GUI_EVENT_CLOSE,"terminate")
GuiSetIcon(@SystemDir & "\mspaint.exe", 0)

;create labels
GUICtrlCreateLabel("The color of the pixel" & @CRLF & "beneath the cursor is" & @CRLF & "displayed on the right:", 13, 20)
$color = 0x000000 ;initial color to show
$hex = GUICtrlCreateLabel("The Hex value of this color is: " & @CRLF & Hex($color, 6), 13, 80)
$dec = GUICtrlCreateLabel("The Decimal value of this color is: " & @CRLF & $color, 13, 120)
$col1 = GuiCtrlCreateLabel("", 135, 15, 50, 50)

;on top check box
$ontop = GUICtrlCreateCheckbox("Set as Always On Top", 13, 160)
GUICtrlSetState(-1, $GUI_CHECKED)

;show gui
GuiSetState(@SW_SHOW)

;loop
While 1
    Sleep(100)
    
    ;poll checkbox to see if wanted on top or not
    if GUICtrlRead($ontop) = 1 Then
        WinSetOnTop($gui,"",1)
    Else
        WinSetOnTop($gui,"",0)
    EndIf
WEnd
    
;go function activated when hotkey is pressed
Func go()
    ;get color of pixel at mouse cursor
    $xy=MouseGetPos()
    $color=PixelGetColor( $xy[0] , $xy[1])
    
    ;update the existing labels with new data
    GUICtrlSetData($hex,"The Hex value of this color is: " & @CRLF & Hex($color, 6))
    GUICtrlSetData($dec,"The Decimal value of this color is: " & @CRLF & $color)
    GuiCtrlSetBkColor($col1, "0x" & hex($color,6))
EndFunc

;exit gui
Func terminate()
Exit
EndFunc

I initally had a problem with your script, in that the color of the box/label was incorrect.

this is because you were setting the color of the label as the direct result of PixelGetColor like this:

GuiCtrlSetBkColor(-1, 0x & $color)

....but PixelGetColor returns a decimal number for the color, which needs hexing:

GuiCtrlSetBkColor(-1, "0x" & hex($color,6))

Note also, my example uses ON EVENT MODE, whereas your original script uses Message Loop mode..... I find event mode MUCH easier for GUIs, but that is a personal preference, you may prefer loop mode.

Hope this helps!!

Edited by andybiochem
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

;*********************************************************************************

; Created Date : 06/06/2008

; Created By :

; Tester Version : 1.0

; Project :

; Description :

;*********************************************************************************

; Running Test On :

;*********************************************************************************

;=========#DEFINES and '#INCLUDES File

#include <GuiConstants.au3> ; Gui File Export

#RequireAdmin ; Check the User login is req Admin privilabe

#NoTrayIcon

;*********************************************************************************

; global variable declarations

; local Variables

Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown.

opt("WinTitleMatchMode", 3) ; Title Match ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

HotKeySet("{ESC}", "_Exit")

HotKeySet("^!p", "go")

HotKeySet("^!t", "_Exit")

GuiCreate("PixiHex", 200, 200)

GuiSetIcon(@SystemDir & "\mspaint.exe", 0)

$xy=MouseGetPos()

$color=PixelGetColor( $xy[0] , $xy[1])

GUICtrlCreateLabel("The color of the pixel" & @CRLF & "beneath the cursor is" & @CRLF & "displayed on the right:", 13, 20)

GUICtrlCreateLabel("The Hex value of this color is: ", 13, 65)

$SC1 = GUICtrlCreateLabel (Hex($color, 6), 13, 80)

GUICtrlCreateLabel("The Decimal value of this color is: " , 14, 105)

$SC2 = GUICtrlCreateLabel( $color, 13, 120)

$SC3 = GuiCtrlCreateLabel("", 135, 15, 50, 50)

GuiCtrlSetBkColor(-1, 0x & $color)

GUICtrlCreateCheckbox("Set as Always On Top", 13, 160)

GUICtrlSetState(-1, $GUI_CHECKED)

WinSetOnTop("PixiHex", "", 1)

; GUI MESSAGE LOOP

GuiSetState()

While GuiGetMsg() <> $GUI_EVENT_CLOSE

$checkbox=GUICtrlRead(7)

Select

; Case $tray = $aboutitem

; Msgbox(262144, "about:", "PixiHex was created by Me using the" & @CRLF & "AutoItv3 scripting language. Copyright 2008.")

; Case $tray = $exititem

; Exit

Case $checkbox = $GUI_CHECKED

WinSetOnTop("PixiHex", "", 1)

Case $checkbox = $GUI_UNCHECKED

WinSetOnTop("PixiHex", "", 0)

EndSelect

WEnd

Func go()

$xy=MouseGetPos()

$color=PixelGetColor( $xy[0] , $xy[1])

GuiCtrlSetBkColor($SC3,0x & $color)

GUICtrlSetData($SC2,$color)

GUICtrlSetData($SC1,Hex($color, 6))

EndFunc ;==>_Exit

Func _Exit()

Exit

EndFunc ;==>_Exit

Updated file same script

NewTest.au3

Edited by MyName

-= [font="Verdana"]A Men Who believes in himself and not circumstances is the real Winner =-[/font]

Link to comment
Share on other sites

;*********************************************************************************

; Created Date : 06/06/2008

; Created By :

; Tester Version : 1.0

; Project :

; Description :

;******

BLAH BLAH BLAH

Exit

EndFunc ;==>_Exit

Updated file same script

muttley see post number 2 of this thread.

your script gives:

C:\Documents and Settings\Administrator\Desktop\121.au3(38,24) : ERROR: syntax error

GuiCtrlSetBkColor(-1, 0x

~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Desktop\121.au3(63,26) : ERROR: syntax error

GuiCtrlSetBkColor($SC3,0x

~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Desktop\121.au3 - 2 error(s), 0 warning(s)

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

No Problem for ME

"C:\Program Files\AutoIt3\SciTE\..\aut2exe\aut2exe.exe" /in "D:\121.au3"

Exit code: 0 Time: 2.022

What version are you running?

I'm on v3.2.12.1

gives:

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /in "C:\Documents and Settings\Administrator\Desktop\121.au3"

+>17:11:00 Starting AutoIt3Wrapper v.1.10.1.8 Environment(Language:0409 Keyboard:00000809 OS:WIN_XP/Service Pack 3 CPU:X86)

>Running AU3Check (1.54.13.0) from:C:\Program Files\AutoIt3

C:\Documents and Settings\Administrator\Desktop\121.au3(38,24) : ERROR: syntax error

GuiCtrlSetBkColor(-1, 0x

~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Desktop\121.au3(63,26) : ERROR: syntax error

GuiCtrlSetBkColor($SC3,0x

~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Desktop\121.au3 - 2 error(s), 0 warning(s)

!>17:11:00 AU3Check ended.rc:2

>Exit code: 0 Time: 4.270

[EDIT] Never mind, I just realized you're using aut2exe directly, rather than checking the script for errors first. muttley

Edited by andybiochem
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

I'd do it this way

#include <GuiConstants.au3>
$title = "PixiHex"

GuiCreate($title, 200, 200)
GuiSetIcon(@SystemDir & "\mspaint.exe", 0)

$mPos = MouseGetPos()
$mColor = PixelGetColor($mPos[0], $mPos[1])
$bkColor = "0x" & Hex($mColor, 6)

HotKeySet("{ESC}", "_Exit")
HotKeySet("^!p", "_Go") ; Ctrl + Alt + P
HotKeySet("^!t", "_Exit")

GUICtrlCreateLabel("The color of the pixel" & @CRLF & "beneath the cursor is" & @CRLF & "displayed on the right:", 13, 20)
GUICtrlCreateLabel("The Hex value of this color is: ", 13, 65)
$SC1 = GUICtrlCreateLabel (Hex($mColor, 6), 13, 80)
GUICtrlCreateLabel("The Decimal value of this color is: " , 14, 105)
$SC2 = GUICtrlCreateLabel($mColor, 13, 120)
$SC3 = GuiCtrlCreateLabel("", 135, 15, 50, 50)
GuiCtrlSetBkColor(-1, $bkColor)
GUICtrlCreateCheckbox("Set as Always On Top", 13, 160)
GUICtrlSetState(-1, $GUI_CHECKED)
WinSetOnTop("PixiHex", "", 1)

; GUI MESSAGE LOOP
GuiSetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    $checkbox=GUICtrlRead(7)
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

Func _Go()
    $mPos = MouseGetPos()
    $mColor = PixelGetColor($mPos[0], $mPos[1])
    $bkColor = "0x" & Hex($mColor, 6)
    GuiCtrlSetBkColor($SC3, $bkColor)
    GUICtrlSetData($SC2,$mColor)
    GUICtrlSetData($SC1,Hex($mColor, 6))
EndFunc ;==>_Exit

Func _Exit()
    Exit
EndFunc ;==>_Exit

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

Link to comment
Share on other sites

OK. Thanks to all of you for your great suggestions. I have learned a few things so far from you all. The syntax error I did not realize because my version, (v3.2.12.1) ran just fine without any errors. I've never used ON EVENT MODE before so I'll play with that for a while. I also like how you suggest to use exit as a function name, not that naming really matters for me. Also, i forgot all about mentioning that I could not get the checkbox to work reliably with a hot key and that is why it was all commented out. Again, thanks to everyone. Just curious to see how the pros would do it.

Link to comment
Share on other sites

I have went over your suggestions. Not to single anyone out or anything, don't get me wrong, they are all great; but I really like andybiochem's suggestion. His reads easier and is less code than mine own. Thank you for your replies.

Edited by netman74501
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...