willichan Posted October 3, 2012 Share Posted October 3, 2012 Ok. Here is another quick and dirty. My old, reliable eyedropper app is not compatible with 64bit windows 7. After trying several, looking for a new one, I was unhappy with them all. AutoIt to the rescue! This took me mere minutes to bang out, and gives me just the basic information I wanted, without being obtrusive. It will remember where you last positioned it, and whether you had it hidden or displayed. Enjoy. expandcollapse popup#region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=MEyeDropper.ico #AutoIt3Wrapper_Outfile=MEyeDropper.exe #AutoIt3Wrapper_Outfile_x64=MEyeDropper64.exe #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_Compile_Both=y #AutoIt3Wrapper_Res_Description=Simple Eye Dropper utility (pronounced My Dropper) #AutoIt3Wrapper_Res_Fileversion=1.0.0.1 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #AutoIt3Wrapper_Res_Language=1033 #AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker ://////=__= ://////=__= #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y #AutoIt3Wrapper_Run_Tidy=y #AutoIt3Wrapper_Run_Obfuscator=y #Obfuscator_Parameters=/striponly #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- Project Name: MEyeDropper Description: Simple Eye Dropper utility (pronounced My Dropper) Creation Date: 10/1/2012 AutoIt Version: Author: willichan #ce ---------------------------------------------------------------------------- Global Const $MyName=StringLeft(@ScriptName, StringInStr(@ScriptName,".", 0, -1)-1) ;get just the name portion of the script/exe name Global Const $MyMutex=$MyName & "-0EFEB5039155DF6E" ;name the mutex for this app If _MutexExists($MyMutex) Then Exit ;exit if another instance of this app is running #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declare Opt("TrayAutoPause", 0) ;0=no pause, 1=Pause Opt("TrayMenuMode", 1) ;0=append, 1=no default menu, 2=no automatic check, 4=menuitemID not return Opt("TrayIconHide", 0) ;0=show, 1=hide tray icon Opt("PixelCoordMode", 1) ;absolute screen coordinates Opt("MouseCoordMode", 1) ;absolute screen coordinates Global $ShowEyedropper Global $WinPosX Global $WinPosY Global $TrayMenuDisplay, $TrayMenuExit Global $PixelColor, $msg, $x, $y, $h Global $frm_dsp, $frm_dsp_x, $frm_dsp_y, $frm_dsp_r, $frm_dsp_g, $frm_dsp_b, $frm_dsp_h, $frm_dsp_sample _ConfigInitialize() $TrayMenuDisplay = TrayCreateItem("Display/Hide") $TrayMenuExit = TrayCreateItem("Exit") TraySetState() $frm_dsp = GUICreate("MEyeDropper", 132, 145, 2278, 194, BitOR($WS_MINIMIZEBOX, $WS_GROUP, $DS_MODALFRAME)) $frm_dsp_x = GUICtrlCreateLabel("X:", 2, 0, 108, 17) $frm_dsp_y = GUICtrlCreateLabel("Y:", 2, 16, 108, 17) $frm_dsp_r = GUICtrlCreateLabel("R:", 2, 40, 60, 17) $frm_dsp_g = GUICtrlCreateLabel("G:", 2, 56, 60, 17) $frm_dsp_b = GUICtrlCreateLabel("B:", 2, 72, 60, 17) $frm_dsp_h = GUICtrlCreateLabel("#", 2, 96, 108, 17) $frm_dsp_sample = GUICtrlCreateLabel(" ", 64, 40, 44, 49) _SetGuiState() While 1 Local $msg = TrayGetMsg() Select Case $msg = $TrayMenuDisplay ;toggle the display $ShowEyedropper = Not $ShowEyedropper _SetGuiState() Case $msg = $TrayMenuExit Exit EndSelect If $ShowEyedropper Then ;Update Dropper $x = MouseGetPos(0) $y = MouseGetPos(1) $PixelColor = PixelGetColor($x, $y) $h = Hex($PixelColor, 6) GUICtrlSetData($frm_dsp_x, $x) GUICtrlSetData($frm_dsp_y, $y) GUICtrlSetData($frm_dsp_h, "#" & $h) GUICtrlSetData($frm_dsp_r, Dec(StringLeft($h, 2))) GUICtrlSetData($frm_dsp_g, Dec(StringMid($h, 3, 2))) GUICtrlSetData($frm_dsp_b, Dec(StringRight($h, 2))) GUICtrlSetBkColor($frm_dsp_sample, $PixelColor) EndIf Sleep(100) WEnd Func _SetGuiState() If $ShowEyedropper Then GUISetState(@SW_SHOW, $frm_dsp) Else GUISetState(@SW_HIDE, $frm_dsp) EndIf EndFunc ;==>_SetGuiState Func _ConfigInitialize() OnAutoItExitRegister("_ConfigDestroy") ;initializers here for script startup $WinPosX = RegRead("HKCU\Software\MEyeDropper", "LastX") If @error or ($WinPosX<0) Then $WinPosX = 0 $WinPosY = RegRead("HKCU\Software\MEyeDropper", "LastY") If @error or ($WinPosY<0) Then $WinPosY = 0 $ShowEyedropper = RegRead("HKCU\Software\MEyeDropper", "Visible") If @error Then $ShowEyedropper = False; EndFunc ;==>_ConfigInitialize Func _ConfigDestroy() ;destructors here for script shutdown/cleanup RegWrite("HKCU\Software\MEyeDropper", "LastX", "REG_SZ", $WinPosX) RegWrite("HKCU\Software\MEyeDropper", "LastY", "REG_SZ", $WinPosY) RegWrite("HKCU\Software\MEyeDropper", "Visible", "REG_SZ", $ShowEyedropper) EndFunc ;==>_ConfigDestroy Func _MutexExists($sOccurenceName) ;Credit goes to martin for this function Local $ERROR_ALREADY_EXISTS = 183, $handle, $lastError $sOccurenceName = StringReplace($sOccurenceName, "\", "") $handle = DllCall("kernel32.dll", "int", "CreateMutex", "int", 0, "long", 1, "str", $sOccurenceName) $lastError = DllCall("kernel32.dll", "int", "GetLastError") Return $lastError[0] = $ERROR_ALREADY_EXISTS EndFunc ;==>_MutexExists My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
guinness Posted October 3, 2012 Share Posted October 3, 2012 Why not use _Singleton instead of _MutexExists? UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
willichan Posted October 3, 2012 Author Share Posted October 3, 2012 (edited) Mostly out of laziness. I have some templates I made a while back that I have never got around to updating. _MutexExists() gets included in scripts that don't really need it as well. One of these days I need to redo my script templates. ---EDIT--- I was just looking at the code for _Singleton(). With the exception of the additional code for multi-user, it looks the same as _MutexExists(). Are there any other advantages to using _Singleton() over _MutexExists()? Edited October 3, 2012 by willichan My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now