Leaderboard
Popular Content
Showing content with the highest reputation on 08/18/2021 in all areas
-
AutoIt Package Manager
seadoggie01 and one other reacted to genius257 for a topic
version 0.3.0 released. https://github.com/genius257/au3pm/releases/tag/0.3.0 changes: Added update command (a0a95f8) Fixed issue where creating the au3pm symbolic link folders would fail, if the path contained a space (6225d71) Fixed issue with au3pm package name regex, where some packages could not be installed as a result (4085014) non code changes: started creating au3pm documentation pages (cli, and repo)2 points -
I wanted to use OpenCV v4+ in AutoIt. I found Opencv UDF on the forum, but there was no support for OpenCV v4+ This UDF provides support for OpenCV v4+ Update There is a new implementation using COM. It is almost as easy as python to use It is also possible to interact with GDI+ Download and extract opencv-4.10.0-windows.exe into a folder Download and extract autoit-opencv-4.10.0-com-v2.6.2.7z into a folder Sources Here Documentation A generated documentation for functions is available here Examples More samples can be found here To run them, please follow these instructions Showing an image #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include "autoit-opencv-com\udf\opencv_udf_utils.au3" _OpenCV_Open("opencv-4.7.0-windows\opencv\build\x64\vc16\bin\opencv_world470.dll", "autoit-opencv-com\autoit_opencv_com470.dll") OnAutoItExitRegister("_OnAutoItExit") Example() Func Example() Local $cv = _OpenCV_get() If Not IsObj($cv) Then Return Local $img = _OpenCV_imread_and_check(_OpenCV_FindFile("samples\data\lena.jpg")) $cv.imshow("Image", $img) $cv.waitKey() $cv.destroyAllWindows() EndFunc ;==>Example Func _OnAutoItExit() _OpenCV_Close() EndFunc ;==>_OnAutoItExit Drawing contours #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include "autoit-opencv-com\udf\opencv_udf_utils.au3" _OpenCV_Open("opencv-4.7.0-windows\opencv\build\x64\vc16\bin\opencv_world470.dll", "autoit-opencv-com\autoit_opencv_com470.dll") OnAutoItExitRegister("_OnAutoItExit") Example() Func Example() Local $cv = _OpenCV_get() If Not IsObj($cv) Then Return Local $img = _OpenCV_imread_and_check("samples\data\pic1.png") Local $img_grey = $cv.cvtColor($img, $CV_COLOR_BGR2GRAY) $cv.threshold($img_grey, 100, 255, $CV_THRESH_BINARY) Local $thresh = $cv.extended[1] Local $contours = $cv.findContours($thresh, $CV_RETR_TREE, $CV_CHAIN_APPROX_SIMPLE) ConsoleWrite("Found " & UBound($contours) & " contours" & @CRLF & @CRLF) $cv.drawContours($img, $contours, -1, _OpenCV_Scalar(0, 0, 255), 2) $cv.imshow("Image", $img) $cv.waitKey() $cv.destroyAllWindows() EndFunc ;==>Example Func _OnAutoItExit() _OpenCV_Close() EndFunc ;==>_OnAutoItExit Showing an image in autoit GUI #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include "autoit-opencv-com\udf\opencv_udf_utils.au3" #include <GUIConstantsEx.au3> _OpenCV_Open("opencv-4.7.0-windows\opencv\build\x64\vc16\bin\opencv_world470.dll", "autoit-opencv-com\autoit_opencv_com470.dll") OnAutoItExitRegister("_OnAutoItExit") Example() Func Example() Local $cv = _OpenCV_get() If Not IsObj($cv) Then Return #Region ### START Koda GUI section ### Form= Local $FormGUI = GUICreate("show image in autoit gui", 400, 400, 200, 200) Local $Pic = GUICtrlCreatePic("", 0, 0, 400, 400) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Local $img = _OpenCV_imread_and_check(_OpenCV_FindFile("samples\data\lena.jpg")) _OpenCV_imshow_ControlPic($img, $FormGUI, $Pic) Local $nMsg While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd $cv.destroyAllWindows() EndFunc ;==>Example Func _OnAutoItExit() _OpenCV_Close() EndFunc ;==>_OnAutoItExit Showing an image in an autosized autoit GUI #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include "autoit-opencv-com\udf\opencv_udf_utils.au3" #include <GUIConstantsEx.au3> _OpenCV_Open("opencv-4.7.0-windows\opencv\build\x64\vc16\bin\opencv_world470.dll", "autoit-opencv-com\autoit_opencv_com470.dll") OnAutoItExitRegister("_OnAutoItExit") Example() Func Example() Local $cv = _OpenCV_get() If Not IsObj($cv) Then Return #Region ### START Koda GUI section ### Form= Local $FormGUI = GUICreate("show image in autoit gui [WINDOW_AUTOSIZE]", 400, 400, 200, 200) Local $Pic = GUICtrlCreatePic("", 0, 0, 400, 400) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Local $img = _OpenCV_imread_and_check(_OpenCV_FindFile("samples\data\lena.jpg")) ; get the image size and resize the GUI and the PIC control WinMove($FormGUI, "", Default, Default, $img.width, $img.height) GUICtrlSetPos($Pic, Default, Default, $img.width, $img.height) _OpenCV_imshow_ControlPic($img, $FormGUI, $Pic) Local $nMsg While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd $cv.destroyAllWindows() EndFunc ;==>Example Func _OnAutoItExit() _OpenCV_Close() EndFunc ;==>_OnAutoItExit Screen capture #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include "autoit-opencv-com\udf\opencv_udf_utils.au3" _OpenCV_Open("opencv-4.7.0-windows\opencv\build\x64\vc16\bin\opencv_world470.dll", "autoit-opencv-com\autoit_opencv_com470.dll") OnAutoItExitRegister("_OnAutoItExit") Example() Func Example() Local $cv = _OpenCV_get() If Not IsObj($cv) Then Return Local $iLeft = 200 Local $iTop = 200 Local $iWidth = 400 Local $iHeight = 400 Local $aRect[4] = [$iLeft, $iTop, $iWidth, $iHeight] Local $img = _OpenCV_GetDesktopScreenMat($aRect) $cv.imshow("Screen capture", $img) $cv.waitKey() $cv.destroyAllWindows() EndFunc ;==>Example Func _OnAutoItExit() _OpenCV_Close() EndFunc ;==>_OnAutoItExit Find template #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include "autoit-opencv-com\udf\opencv_udf_utils.au3" _OpenCV_Open("opencv-4.7.0-windows\opencv\build\x64\vc16\bin\opencv_world470.dll", "autoit-opencv-com\autoit_opencv_com470.dll") OnAutoItExitRegister("_OnAutoItExit") Example() Func Example() Local $cv = _OpenCV_get() If Not IsObj($cv) Then Return Local $img = _OpenCV_imread_and_check(_OpenCV_FindFile("samples\data\mario.png")) Local $tmpl = _OpenCV_imread_and_check(_OpenCV_FindFile("samples\data\mario_coin.png")) ; The higher the value, the higher the match is exact Local $threshold = 0.8 Local $aMatches = _OpenCV_FindTemplate($img, $tmpl, $threshold) Local $aRedColor = _OpenCV_RGB(255, 0, 0) Local $aMatchRect[4] = [0, 0, $tmpl.width, $tmpl.height] For $i = 0 To UBound($aMatches) - 1 $aMatchRect[0] = $aMatches[$i][0] $aMatchRect[1] = $aMatches[$i][1] ; Draw a red rectangle around the matched position $cv.rectangle($img, $aMatchRect, $aRedColor) Next $cv.imshow("Find template example", $img) $cv.waitKey() $cv.destroyAllWindows() EndFunc ;==>Example Func _OnAutoItExit() _OpenCV_Close() EndFunc ;==>_OnAutoItExit Video capture file #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include "autoit-opencv-com\udf\opencv_udf_utils.au3" #include <Misc.au3> _OpenCV_Open("opencv-4.7.0-windows\opencv\build\x64\vc16\bin\opencv_world470.dll", "autoit-opencv-com\autoit_opencv_com470.dll") OnAutoItExitRegister("_OnAutoItExit") Example() Func Example() Local $cv = _OpenCV_get() If Not IsObj($cv) Then Return Local $cap = _OpenCV_ObjCreate("cv.VideoCapture").create(_OpenCV_FindFile("samples\data\vtest.avi")) If Not $cap.isOpened() Then ConsoleWriteError("!>Error: cannot open the video file." & @CRLF) Exit EndIf Local $frame = _OpenCV_ObjCreate("cv.Mat") While 1 If _IsPressed("1B") Or _IsPressed(Hex(Asc("Q"))) Then ExitLoop EndIf If Not $cap.read($frame) Then ConsoleWriteError("!>Error: cannot read the video or end of the video." & @CRLF) ExitLoop EndIf $cv.imshow("capture video file", $frame) Sleep(30) WEnd $cv.destroyAllWindows() EndFunc ;==>Example Func _OnAutoItExit() _OpenCV_Close() EndFunc ;==>_OnAutoItExit Video capture camera #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include "autoit-opencv-com\udf\opencv_udf_utils.au3" #include <Misc.au3> _OpenCV_Open("opencv-4.7.0-windows\opencv\build\x64\vc16\bin\opencv_world470.dll", "autoit-opencv-com\autoit_opencv_com470.dll") OnAutoItExitRegister("_OnAutoItExit") Example() Func Example() Local $cv = _OpenCV_get() If Not IsObj($cv) Then Return Local $iCamId = 0 Local $cap = _OpenCV_ObjCreate("cv.VideoCapture").create($iCamId) If Not $cap.isOpened() Then ConsoleWriteError("!>Error: cannot open the camera." & @CRLF) Exit EndIf Local $frame = _OpenCV_ObjCreate("cv.Mat") While 1 If _IsPressed("1B") Or _IsPressed(Hex(Asc("Q"))) Then ExitLoop EndIf If $cap.read($frame) Then ;; Flip the image horizontally to give the mirror impression $frame = $cv.flip($frame, 1) $cv.imshow("capture camera", $frame) Else ConsoleWriteError("!>Error: cannot read the camera." & @CRLF) EndIf Sleep(30) WEnd $cv.destroyAllWindows() EndFunc ;==>Example Func _OnAutoItExit() _OpenCV_Close() EndFunc ;==>_OnAutoItExit Resize an image with GDI+ #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include "autoit-opencv-com\udf\opencv_udf_utils.au3" _OpenCV_Open("opencv-4.7.0-windows\opencv\build\x64\vc16\bin\opencv_world470.dll", "autoit-opencv-com\autoit_opencv_com470.dll") _GDIPlus_Startup() OnAutoItExitRegister("_OnAutoItExit") Example() Func Example() Local $cv = _OpenCV_get() If Not IsObj($cv) Then Return Local $bMethod = 1 Local $img = _OpenCV_imread_and_check(_OpenCV_FindFile("samples\tutorial_code\yolo\scooter-5180947_1920.jpg")) Local $resized If $bMethod Then $resized = $img.GdiplusResize(600, 400) Else Local $hImage = $img.convertToBitmap() Local $hResizedImage = _GDIPlus_ImageResize($hImage, 600, 400) _GDIPlus_BitmapDispose($hImage) $resized = $cv.createMatFromBitmap($hResizedImage) _GDIPlus_BitmapDispose($hResizedImage) EndIf $cv.imshow("Resized with GDI+", $resized) $cv.waitKey() $cv.destroyAllWindows() EndFunc ;==>Example Func _OnAutoItExit() _GDIPlus_Shutdown() _OpenCV_Close() EndFunc ;==>_OnAutoItExit1 point
-
Hello. So for some time now, I've been thinking about the possibilities with a package manager for AutoIt, like npm for UDF's and such. I am curious if anyone else would be interested in such a thing, or if it would be useless/problematic in practice? My personal problem with the idea so far, is the hurdle of legality and hosting options. Your thought(s) on this matter would be greatly appreciated. Edit: Package repo web page: https://au3pm.github.io/ Docs: https://genius257.github.io/au3pm/ Project: https://github.com/genius257/au3pm/ Latest release: https://github.com/genius257/au3pm/releases/tag/0.3.1 Download link: https://github.com/genius257/au3pm/releases/download/0.3.1/au3pm.exe1 point
-
I need help - willing to pay.
jchd reacted to JLogan3o13 for a topic
Per our community guidelines for anyone who doesn't want to actually do the scripting themselves, this topic will be locked. If anyone is interested in doing the work for you they will contact via PM.1 point -
Or did you mean: _FileListToArrayRec?1 point
-
Is it possible to improve the search speed in this code?
Loc reacted to 636C65616E for a topic
Also there's some redundancies in you checks, but i don't have time to explore and fix it for you (some tests are the same from one number to another, you should do them once, instead of what your doing, anyway it's a matter of maybe 0.5ms to redo them so ... -_-, just to makes stuff more readable) #include <GDIPlus.au3> #include <GDIPlusConstants.au3> #include <WinAPIMisc.au3> #include <Array.au3> func assert($check, $line = @SCRIPTLINENUMBER) if not $check then MsgBox(0x10, 'ERROR', 'Assert failed at line ' & $line) Exit endif endfunc func FetchColors($aWinHandle, byref $OX, byref $OY) local $tmp = WinGetPos($aWinHandle) assert(@ERROR = 0) local $width = $tmp[2] local $height = $tmp[3] local $hDDC = _WinAPI_GetDC($aWinHandle) assert($hDDC <> 0) local $hCDC = _WinAPI_CreateCompatibleDC($hDDC) assert($hCDC <> 0) local $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $width, $height) assert($hBMP <> 0) $tmp = _WinAPI_SelectObject($hCDC, $hBMP) assert($tmp <> 0) $tmp = _WinAPI_PrintWindow($aWinHandle, $hCDC) assert($tmp = True) ; $tmp = _WinAPI_BitBlt($hCDC, 0, 0, $width, $height, $hDDC, 0, 0, 0x00CC0020) ; assert($tmp = True) local $BMP = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) assert(@ERROR = 0) local $ret = ObjCreate('scripting.dictionary') for $x in $OX for $y in $OY local $key = $x & ':' & $y if $ret.Exists($key) then ContinueLoop local $val = _GDIPlus_BitmapGetPixel($BMP,$x,$y) assert(@ERROR = 0) ; println('[' & StringFormat('%02d:%02d',$x,$y) & '] 0x' & hex($val,6)) $ret.Add($key,$val) next next _GDIPlus_BitmapDispose($BMP) _WinAPI_DeleteObject($hBMP) _WinAPI_ReleaseDC($aWinHandle, $hDDC) _WinAPI_DeleteDC($hCDC) return $ret endfunc func _GetColor(byref $cols, $x, $y) local $key = $x & ':' & $y if not $cols.Exists($key) then MsgBox(0x10, 'error', StringFormat('Coords (%d,%d) not fetched', $x, $y)) Exit endif return $cols.Item($key) endfunc Func _RoomNumber(byref $cols, byref $OX, byref $OY) ; local $cols = FetchColors($hwnd, $OX, $OY) local $X0Y0 = _GetColor($cols, $OX[0], $OY[0]) local $X1Y0 = _GetColor($cols, $OX[1], $OY[0]) local $X2Y0 = _GetColor($cols, $OX[2], $OY[0]) local $X2Y2 = _GetColor($cols, $OX[2], $OY[2]) local $X2Y4 = _GetColor($cols, $OX[2], $OY[4]) local $X0Y1 = _GetColor($cols, $OX[0], $OY[1]) local $X0Y2 = _GetColor($cols, $OX[0], $OY[2]) local $X0Y3 = _GetColor($cols, $OX[0], $OY[3]) local $X0Y4 = _GetColor($cols, $OX[0], $OY[4]) local $X2Y1 = _GetColor($cols, $OX[2], $OY[1]) local $X1Y2 = _GetColor($cols, $OX[1], $OY[2]) local $X2Y3 = _GetColor($cols, $OX[2], $OY[3]) local $X1Y4 = _GetColor($cols, $OX[1], $OY[4]) If $X0Y0 <> 0xFFFF00 And $X0Y0 = 0xFFFF00 And $X2Y0 <> 0xFFFF00 And _ $X0Y1 = 0xFFFF00 And $X2Y1 = 0xFFFF00 And _ $X0Y2 = 0xFFFF00 And $X1Y2 <> 0xFFFF00 And $X2Y2 = 0xFFFF00 And _ $X0Y3 = 0xFFFF00 And $X2Y3 = 0xFFFF00 And _ $X0Y4 = 0xFFB400 And $X1Y4 = 0xFFB400 And $X2Y4 = 0xFFB400 Then MsgBox(0, '', 'Number 0'); Number 0 ElseIf $X0Y0 <> 0xFFFF00 And $X0Y0 = 0xFFFF00 And $X2Y0 <> 0xFFFF00 And _ $X0Y1 <> 0xFFFF00 And $X2Y1 <> 0xFFFF00 And _ $X0Y2 <> 0xFFFF00 And $X1Y2 = 0xFFFF00 And $X2Y2 <> 0xFFFF00 And _ $X0Y3 <> 0xFFFF00 And $X2Y3 <> 0xFFFF00 And _ $X0Y4 <> 0xFFB400 And $X1Y4 = 0xFFB400 And $X2Y4 <> 0xFFB400 Then MsgBox(0, '', 'Number 1'); Number 1 ElseIf $X0Y0 = 0xFFFF00 And $X0Y0 = 0xFFFF00 And $X2Y0 <> 0xFFFF00 And _ $X0Y1 <> 0xFFFF00 And $X2Y1 = 0xFFFF00 And _ $X0Y2 = 0xFFFF00 And $X1Y2 = 0xFFFF00 And $X2Y2 = 0xFFFF00 And _ $X0Y3 = 0xFFFF00 And $X2Y3 <> 0xFFFF00 And _ $X0Y4 = 0xFFB400 And $X1Y4 = 0xFFB400 And $X2Y4 = 0xFFB400 Then MsgBox(0, '', 'Number 2'); Number 2 ElseIf $X0Y0 = 0xFFFF00 And $X0Y0 = 0xFFFF00 And $X2Y0 <> 0xFFFF00 And _ $X0Y1 <> 0xFFFF00 And $X2Y1 = 0xFFFF00 And _ $X0Y2 = 0xFFFF00 And $X1Y2 = 0xFFFF00 And $X2Y2 <> 0xFFFF00 And _ $X0Y3 <> 0xFFFF00 And $X2Y3 = 0xFFFF00 And _ $X0Y4 = 0xFFB400 And $X1Y4 = 0xFFB400 And $X2Y4 = 0xFFB400 Then MsgBox(0, '', 'Number 3'); Number 3 ElseIf $X0Y0 = 0xFFFF00 And $X0Y0 <> 0xFFFF00 And $X2Y0 = 0xFFFF00 And _ $X0Y1 = 0xFFFF00 And $X2Y1 = 0xFFFF00 And _ $X0Y2 = 0xFFFF00 And $X1Y2 = 0xFFFF00 And $X2Y2 = 0xFFFF00 And _ $X0Y3 <> 0xFFFF00 And $X2Y3 = 0xFFFF00 And _ $X0Y4 <> 0xFFB400 And $X1Y4 <> 0xFFB400 And $X2Y4 = 0xFFB400 Then MsgBox(0, '', 'Number 4'); Number 4 ElseIf $X0Y0 <> 0xFFFF00 And $X0Y0 = 0xFFFF00 And $X2Y0 = 0xFFFF00 And _ $X0Y1 = 0xFFFF00 And $X2Y1 <> 0xFFFF00 And _ $X0Y2 = 0xFFFF00 And $X1Y2 = 0xFFFF00 And $X2Y2 = 0xFFFF00 And _ $X0Y3 <> 0xFFFF00 And $X2Y3 = 0xFFFF00 And _ $X0Y4 = 0xFFB400 And $X1Y4 = 0xFFB400 And $X2Y4 = 0xFFB400 Then MsgBox(0, '', 'Number 5'); Number 5 ElseIf $X0Y0 <> 0xFFFF00 And $X0Y0 = 0xFFFF00 And $X2Y0 <> 0xFFFF00 And _ $X0Y1 = 0xFFFF00 And $X2Y1 <> 0xFFFF00 And _ $X0Y2 = 0xFFFF00 And $X1Y2 = 0xFFFF00 And $X2Y2 <> 0xFFFF00 And _ $X0Y3 = 0xFFFF00 And $X2Y3 = 0xFFFF00 And _ $X0Y4 = 0xFFB400 And $X1Y4 = 0xFFB400 And $X2Y4 = 0xFFB400 Then MsgBox(0, '', 'Number 6'); Number 6 ElseIf $X0Y0 = 0xFFFF00 And $X0Y0 = 0xFFFF00 And $X2Y0 <> 0xFFFF00 And _ $X0Y1 <> 0xFFFF00 And $X2Y1 = 0xFFFF00 And _ $X0Y2 <> 0xFFFF00 And $X1Y2 <> 0xFFFF00 And $X2Y2 = 0xFFFF00 And _ $X0Y3 <> 0xFFFF00 And $X2Y3 = 0xFFFF00 And _ $X0Y4 <> 0xFFB400 And $X1Y4 <> 0xFFB400 And $X2Y4 = 0xFFB400 Then MsgBox(0, '', 'Number 7'); Number 7 ElseIf $X0Y0 <> 0xFFFF00 And $X0Y0 = 0xFFFF00 And $X2Y0 <> 0xFFFF00 And _ $X0Y1 = 0xFFFF00 And $X2Y1 = 0xFFFF00 And _ $X0Y2 = 0xFFFF00 And $X1Y2 = 0xFFFF00 And $X2Y2 <> 0xFFFF00 And _ $X0Y3 = 0xFFFF00 And $X2Y3 = 0xFFFF00 And _ $X0Y4 = 0xFFB400 And $X1Y4 = 0xFFB400 And $X2Y4 = 0xFFB400 Then MsgBox(0, '', 'Number 8'); Number 8 ElseIf $X0Y0 <> 0xFFFF00 And $X0Y0 = 0xFFFF00 And $X2Y0 <> 0xFFFF00 And _ $X0Y1 = 0xFFFF00 And $X2Y1 = 0xFFFF00 And _ $X0Y2 = 0xFFFF00 And $X1Y2 = 0xFFFF00 And $X2Y2 = 0xFFFF00 And _ $X0Y3 <> 0xFFFF00 And $X2Y3 = 0xFFFF00 And _ $X0Y4 = 0xFFB400 And $X1Y4 = 0xFFB400 And $X2Y4 = 0xFFB400 Then MsgBox(0, '', 'Number 9'); Number 9 ElseIf $X0Y0 = 0xFFFFFF And $X0Y0 = 0xFFFFBD And $X2Y0 = 0xFFFFAF And _ $X0Y4 = 0x00DB00 And $X1Y4 = 0x00DB00 And $X2Y4 = 0x00B500 Then MsgBox(0, '', 'String S');Chu~ S ; Else ? EndIf; Number 0 EndFunc $handle = WinGetHandle('NumberApp') Global $OX1[3] = [32, 35, 39], $OX2[3] = [45, 48, 52], $OX3[3] = [58, 61, 65], $OY[5] = [69, 71, 73, 75, 77] global $TotX = [32, 35, 39, 45, 48, 52, 58, 61, 65] ; just OX1, OX2 and OX3 concatenated ; DO THIS COMPLETE BLOCK EACH TIME YOU WANT TO GET THE 'NUMBERS' ; START $cols = FetchColors($handle, $TotX, $OY) _RoomNumber($cols, $OX1, $OY) _RoomNumber($cols, $OX2, $OY) _RoomNumber($cols, $OX3, $OY) ; END EDIT: for what i think you're trying to do, you should get the whole screen one time and retrieve the 3 numbers with the same screen. ofc if there's multiple call to this kind of stuff, you could alloc the gdi objects onces and update thems each time instead of allocating and freeing all the time, etc. Optimization depends on your code, it's behavior and what you are trying to do, with this little overview of what you are doing, i can't do more, sorry ... Optimizing a code is achieved by otpimising the 'what' i'm doing and also the 'how' i'm doing it, so ...1 point -
Hello. Do it like this. (Start-Process App.exe -PassThru -Wait).ExitCode Saludos1 point
-
need help with regex
Burgaud reacted to seadoggie01 for a topic
I guess since y'all are using StringRegExpReplace, yes. However, if you use StringRegExp instead, then you don't have to worry about it. Local $aRet = StringRegExp($sText, "(CPU\s+.*)", 3) return $aRet[0] ; Or, if you're feeling daring, assume that you always want the first line... Local $aRet = StringRegExp($sText, "(.*)", 3) return $aRet[0] As an added bonus, I got it in 4 characters, @Musashi1 point -
Isn't there still a .* missing before (CPU.*?°C) ? Otherwise the lines before the "CPU line" are included. Example : Local $sText, $sTextNew $sText = "some text before CPU line" & @CRLF & _ "CPU 51°C" & @CRLF & _ "GPU 45°C" & @CRLF & _ "C0% 9.6" & @CRLF & _ "MHz 2968" & @CRLF & _ "FID 29.75" ConsoleWrite("----> Original : ------------------------------------- " & @CRLF) ConsoleWrite($sText & @CRLF) ConsoleWrite("----> Marc : ----------------------------------------- " & @CRLF) $sTextNew = StringRegExpReplace($sText,"(?s)(CPU.*?°C).*", "$1") ConsoleWrite($sTextNew & @CRLF) ConsoleWrite("----> Musashi : -------------------------------------- " & @CRLF) $sTextNew = StringRegExpReplace($sText,"(?s).*(CPU.*?°C).*", "$1") ConsoleWrite($sTextNew & @CRLF) -> Output : Now we only have to wait for @mikell , who will provide a pattern which is only 5 characters long .1 point
-
$text = StringRegExpReplace($text,"(?s)(CPU.*?°C).*", "$1") Try this way1 point
-
Calculation Mistakes in Large Arrays
FrancescoDiMuro reacted to RTFC for a topic
and (at the fear of repeating myself) E4A relies on internal dlls written (by yours truly) in C++, based upon Eigen and boost. Eigen is used extensively in science, engineering, robotics, and CG. And in x64-mode, data set size is limited only by your virtual memory. Yet to engage with it, you only need a few lines of AutoIt.1 point -
Calculation Mistakes in Large Arrays
rudi reacted to JockoDundee for a topic
I think it only fair to count the lines inserted by any new #include statement, recursively of course1 point -
This links back to this very thread, so were I an AI, I would now be in a fatal embrace. What a terrible place to spend eternity. ☹️1 point
-
AutoIt Snippets
DKiehl reacted to argumentum for a topic
Center GUI on Monitor based on mouse position #include <AutoItConstants.au3> #include <GUIConstants.au3> #include <WinAPIGdi.au3> Func GuiCenterOnMonitorFromMousePosition($hForm, $sText = "") Local $aData, $hMonitor, $tPos = _WinAPI_GetMousePos() If Not @error Then $hMonitor = _WinAPI_MonitorFromPoint($tPos) If Not @error Then $aData = _WinAPI_GetMonitorInfo($hMonitor) If @error Then Return SetError(1, -1, 1) Local $iWinState = WinGetState($hForm, $sText) If @error Then Return SetError(2, $aData[2], 2) If BitAND($iWinState, $WIN_STATE_MINIMIZED) Or _ BitAND($iWinState, $WIN_STATE_MAXIMIZED) Then WinSetState($hForm, $sText, @SW_RESTORE) Local $aWinPos = WinGetPos($hForm, $sText) If @error Then Return SetError(3, $aData[2], 3) WinMove($hForm, _ $sText, _ Int((($aData[0].Right - $aData[0].Left - $aWinPos[2]) / 2) + $aData[0].Left), _ Int((($aData[0].Bottom - $aData[0].Top - $aWinPos[3]) / 2) + $aData[0].Top)) If @error Then Return SetError(4, $aData[2], 4) Return SetError(0, $aData[2], 0) EndFunc ;==>GuiCenterOnMonitorFromMousePosition Example() Func Example() Local $hGUI = GUICreate("GuiCenterOnMonitorFromMousePosition example", 600, 200) GuiCenterOnMonitorFromMousePosition($hGUI) GUICtrlCreateLabel("Primary display monitor = " & @extended, 20, 20, 160, 21) GUISetState() While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd GUIDelete() EndFunc ;==>Example1 point -
Other readers use a USB interface and the most popular/cheap of them are driverless. They fake input by identifying as keyboard and emit ASCII codes by sending ALT+<value> sequences. See >this thread. Here are the code I've been using. Note that it may be a bit rusty but I know it already helped others. All I can do quickly is join you the sample code. Look for a line wth @@@@@@@@@ for interesting point. I haven't used this code for years... You'll probably have to list HID devices properties to determine which is which, which makes the code somehow specific to a particular setup. I hope this will help you out. Barcode Reader Filter.au3 RawInput.au3 EDIT: attachments fixed.1 point
-
Indeed I mixed up the topics. Nice examples rover! I searched for Yashied's code but didn't find it and decided to hack something with built-in graphic creator using GDI+. ;coded by UEZ build 2013-09-03 beta #AutoIt3Wrapper_Run_Obfuscator=y #Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0 #AutoIt3Wrapper_UseUpx=y #AutoIt3Wrapper_UPX_Parameters=--best --lzma #include <SliderConstants.au3> ;~ #include <WindowsConstants.au3>;~~~ #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GDIPlus.au3> Opt("GUIOnEventMode", 1) Opt("MouseCoordMode", 0) Global Const $IMAGE_BITMAP = 0 Global Const $STM_SETIMAGE = 0x0172 _GDIPlus_Startup() Global $hGUI = GUICreate("New Slider beta by UEZ 2012-2013", 580, 280) Global $iW = 300, $iH = 16 Global $aSlider1 = GUICtrlCreateHSlider(100, 50, $iW, $iH, 0xFF4080F0) Global $idLabel = GUICtrlCreateLabel("Volume", 10, 46, 70, 30) GUICtrlSetFont(-1, 16) Global $idInput1 = GUICtrlCreateInput($aSlider1[7], 420, 46, 42, 24, BitOR($ES_CENTER, $ES_READONLY)) GUICtrlSetFont(-1, 12) Global $iSliderPos = 50 Global $aSlider2 = GUICtrlCreateHSlider(120, 100, $iW + 30, 30, 0xFF205020, @ScriptDir & "\button_smiley.png", "", $iSliderPos) Global $idInput2 = GUICtrlCreateInput($aSlider2[7], 10, 100, 42, 24) GUICtrlSetFont(-1, 12) Global $iSlider = GUICtrlCreateSlider(6, 150, $iW + 156, 45, BitOR($GUI_SS_DEFAULT_SLIDER, $TBS_NOTHUMB, $TBS_NOTHUMB)) GUICtrlSetLimit(-1, 200, 0) GUICtrlSetState(-1, $GUI_DISABLE) Global $idButton = GUICtrlCreateButton("OK", 56, 99, 40, 26) Global $aSlider3 = GUICtrlCreateHSlider(20, 180, $iW + 130, 50, 0, @ScriptDir & "\star.png", @ScriptDir & "\Texture.jpg", $iSliderPos) Global $aSlider4 = GUICtrlCreateVSlider(520, 20, 24, 240, 0xFF505050) ;~ Global $aSlider4 = GUICtrlCreateVSlider(520, 20, 24, 240, 0, "", @ScriptDir & "\TextureRotated.jpg") GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUICtrlSetOnEvent($aSlider1[0], "CheckSliderMove") GUICtrlSetOnEvent($aSlider2[0], "CheckSliderMove") GUICtrlSetOnEvent($aSlider3[0], "CheckSliderMove") GUICtrlSetOnEvent($aSlider4[0], "CheckSliderMove") GUICtrlSetOnEvent($idButton, "UpdateSlider") Do Until Not Sleep(3000) Func UpdateSlider() SetSliderPosHMan($aSlider2, GUICtrlRead($idInput2)) EndFunc ;==>UpdateSlider Func _Exit() _GDIPlus_Shutdown() Exit EndFunc ;==>_Exit Func CheckSliderMove() Local $aRes = GUIGetCursorInfo($hGUI), $aPosW, $aPosH Switch $aRes[4] Case $aSlider1[0] While $aRes[2] * Sleep(20) $aRes = GUIGetCursorInfo($hGUI) SetSliderPosH($aSlider1, $aRes[0]) GUICtrlSetData($idInput1, $aSlider1[7]) $aPosW = WinGetPos($hGUI) ToolTip("Value: " & $aSlider1[7], $aPosW[0] + $aRes[0], $aPosW[1] + $aRes[1] + 50) WEnd ToolTip("") Case $aSlider2[0] While $aRes[2] * Sleep(20) $aRes = GUIGetCursorInfo($hGUI) SetSliderPosH($aSlider2, $aRes[0]) GUICtrlSetData($idInput2, $aSlider2[7]) WEnd Case $aSlider3[0] While $aRes[2] * Sleep(20) $aRes = GUIGetCursorInfo($hGUI) SetSliderPosH($aSlider3, $aRes[0]) $aPosW = WinGetPos($hGUI) ToolTip("Value: " & $aSlider3[7], $aPosW[0] + $aRes[0], $aPosW[1] + $aRes[1] + 50) WEnd ToolTip("") Case $aSlider4[0] While $aRes[2] * Sleep(20) $aRes = GUIGetCursorInfo($hGUI) SetSliderPosV($aSlider4, $aRes[1]) $aPosH = WinGetPos($hGUI) ToolTip("Value: " & $aSlider4[7], $aPosH[0] + $aRes[0], $aPosH[1] + $aRes[1] + 50) WEnd ToolTip("") EndSwitch EndFunc ;==>CheckSliderMove Func SetSliderPosHMan(ByRef $aSlider, $iPos) Local $aPos, $aPosW $iNewPos = 1 + Int($aSlider[1] + $iPos * $aSlider[5] + $aSlider[3]) GUICtrlSetPos($aSlider[0], Max($aSlider[1], Min($iNewPos - $aSlider[3], $aSlider[4])), $aSlider[2]) $aPos = ControlGetPos($hGUI, "", $aSlider[0]) $aPosW = WinGetPos($hGUI) $aSlider[7] = $iPos ;Int(($aPos[0] + $aSlider[3] - $aSlider[6]) / $aSlider[5]) EndFunc ;==>SetSliderPosHMan Func SetSliderPosH(ByRef $aSlider, $iPos) Local $aPos, $aPosW GUICtrlSetPos($aSlider[0], Max($aSlider[1], Min($iPos - $aSlider[3], $aSlider[4])), $aSlider[2]) $aPos = ControlGetPos($hGUI, "", $aSlider[0]) $aPosW = WinGetPos($hGUI) $aSlider[7] = Int(($aPos[0] + $aSlider[3] - $aSlider[6]) / $aSlider[5]) EndFunc ;==>SetSliderPosH Func SetSliderPosV(ByRef $aSlider, $iPos) Local $aPos, $aPosH GUICtrlSetPos($aSlider[0], $aSlider[2], Max($aSlider[1], Min($iPos - $aSlider[3], $aSlider[4]))) $aPos = ControlGetPos($hGUI, "", $aSlider[0]) $aPosH = WinGetPos($hGUI) $aSlider[7] = Int(($aPos[1] + $aSlider[3] - $aSlider[6]) / $aSlider[5]) EndFunc ;==>SetSliderPosV Func GUICtrlCreateHSlider($iX, $iY, $iW, $iH, $iColor, $sFileThumb = "", $sFileBg = "", $iValThumb = 0, $iColorThumb = 0xD0A00000, $iColorThumb_Center = 0xFFFFA0A0, $iValMin = 0, $iValMax = 100, $fSize = 0.025, $fScale = 1.5) Local $hHBitmap_Thumb, $hHBitmap_Bg Local $idPic_Bg = GUICtrlCreatePic("", $iX, $iY, $iW, $iH) GUICtrlSetState(-1, $GUI_DISABLE) If $sFileBg <> "" And FileExists($sFileBg) Then $hHBitmap_Bg = _GDIPlus_CreateHBitmapFromFile($sFileBg, $iW, $iH) Else $hHBitmap_Bg = _GDIPlus_CreateRoundRectImage($iW, $iH, $iColor, $fSize) EndIf _WinAPI_DeleteObject(GUICtrlSendMsg($idPic_Bg, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap_Bg)) _WinAPI_DeleteObject($hHBitmap_Bg) Local $iH_Thumb = $iH * $fScale Local $fRatio = $iW / Abs($iValMax - $iValMin) Local $idPic_Thumb = GUICtrlCreatePic("", $iX - $iH_Thumb / 2 + $iValThumb * $fRatio, $iY - ($iH_Thumb - $iH) / 2, $iH_Thumb, $iH_Thumb) If $sFileThumb <> "" And FileExists($sFileThumb) Then $hHBitmap_Thumb = _GDIPlus_CreateHBitmapFromFile($sFileThumb, $iH_Thumb, $iH_Thumb) Else $hHBitmap_Thumb = _GDIPlus_CreateEllipseThumb($iH_Thumb, $iColorThumb, $iColorThumb_Center) EndIf _WinAPI_DeleteObject(GUICtrlSendMsg($idPic_Thumb, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap_Thumb)) _WinAPI_DeleteObject($hHBitmap_Thumb) Local $aSlider[8] = [ $idPic_Thumb, _ ;0 control id $iX - $iH_Thumb / 2, _ ;1 min x position thumb $iY - ($iH_Thumb - $iH) / 2, _ ;2 center position thumb height $iH_Thumb / 2, _ ;3 center thumb height $iX + $iW - $iH_Thumb / 2, _ ;4 end x position $fRatio, _ ;5 ratio $iX, _ ;6 start x position $iValThumb] ;7 thumb size ratio Return $aSlider EndFunc ;==>GUICtrlCreateHSlider Func GUICtrlCreateVSlider($iX, $iY, $iW, $iH, $iColor, $sFileThumb = "", $sFileBg = "", $iValThumb = 0, $iColorThumb = 0xD0005000, $iColorThumb_Center = 0xFF80E080, $iValMin = 0, $iValMax = 100, $fSize = 0.025, $fScale = 1.5) Local $hHBitmap_Thumb, $hHBitmap_Bg Local $idPic_Bg = GUICtrlCreatePic("", $iX, $iY, $iW, $iH) GUICtrlSetState(-1, $GUI_DISABLE) If $sFileBg <> "" And FileExists($sFileBg) Then $hHBitmap_Bg = _GDIPlus_CreateHBitmapFromFile($sFileBg, $iW, $iH) Else $hHBitmap_Bg = _GDIPlus_CreateRoundRectImage($iH, $iW, $iColor, $fSize, True, True) EndIf _WinAPI_DeleteObject(GUICtrlSendMsg($idPic_Bg, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap_Bg)) _WinAPI_DeleteObject($hHBitmap_Bg) Local $iW_Thumb = $iW * $fScale Local $fRatio = $iH / Abs($iValMax - $iValMin) Local $idPic_Thumb = GUICtrlCreatePic("", $iX + ($iW - $iW_Thumb) / 2 + $iValThumb * $fRatio, $iY - ($iW_Thumb - $iH) / 2, $iW_Thumb, $iW_Thumb) If $sFileThumb <> "" And FileExists($sFileThumb) Then $hHBitmap_Thumb = _GDIPlus_CreateHBitmapFromFile($sFileThumb, $iW_Thumb, $iW_Thumb) Else $hHBitmap_Thumb = _GDIPlus_CreateEllipseThumb($iW_Thumb, $iColorThumb, $iColorThumb_Center) EndIf _WinAPI_DeleteObject(GUICtrlSendMsg($idPic_Thumb, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap_Thumb)) _WinAPI_DeleteObject($hHBitmap_Thumb) Local $aSlider[8] = [ $idPic_Thumb, _ ;0 control id $iY - $iW_Thumb / 2, _ ;1 min y position thumb $iX - ($iW_Thumb - $iW) / 2, _ ;2 center position thumb width $iW_Thumb / 2, _ ;3 center thumb height $iY + $iH - $iW_Thumb / 2, _ ;4 end Y position $fRatio, _ ;5 ratio $iY, _ ;6 start Y position $iValThumb] ;7 thumb size ratio Return $aSlider EndFunc ;==>GUICtrlCreateVSlider Func _GDIPlus_CreateRoundRectImage($iW, $iH, $iColor = 0xFF4080F0, $fSize = 0.025, $hHBitmap = True, $iRotate = 0) Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePath", "int", 0, "int*", 0) Local $hPath_Bg = $aResult[2] $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePath", "int", 0, "int*", 0) Local $hPath_Fg = $aResult[2] $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) Local $hBitmap = $aResult[6] Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2) Local $iColor_Bg = 0xFF000000 + 0x10000 * Max(BitShift(BitAND($iColor, 0x00FF0000) / 3, 16), 0x10) + 0x100 * Max(BitShift(BitAND($iColor, 0x0000FF00) / 3, 8), 0x10) + Max(BitAND($iColor, 0x000000FF / 3), 0x10) Local $hBrush = _GDIPlus_BrushCreateSolid($iColor_Bg) Local $dW = Int($iW * $fSize) DllCall($ghGDIPDll, "int", "GdipAddPathArc", "handle", $hPath_Bg, "float", 0, "float", 0, "float", $dW, "float", $iH, "float", 90, "float", 180) ;left arc DllCall($ghGDIPDll, "int", "GdipAddPathArc", "handle", $hPath_Bg, "float", $iW - $dW - 1, "float", 0, "float", $dW, "float", $iH, "float", -90, "float", 180) ;right arc DllCall($ghGDIPDll, "int", "GdipClosePathFigure", "handle", $hPath_Bg) DllCall($ghGDIPDll, "int", "GdipFillPath", "handle", $hCtxt, "handle", $hBrush, "handle", $hPath_Bg) $iH *= 0.89 Local $iColor2 = 0xFF000000 + 0x10000 * Min(BitShift(BitAND($iColor, 0x00FF0000), 16) * 3, 0xFF) + 0x100 * Min(BitShift(BitAND($iColor, 0x0000FF00), 8) * 3, 0xFF) + Min(BitAND($iColor, 0x000000FF) * 3, 0xFF) Local $tRectF = _GDIPlus_RectFCreate(0, 0, $iW, $iH) $aResult = DllCall($ghGDIPDll, "int", "GdipCreateLineBrushFromRect", "ptr", DllStructGetPtr($tRectF), "int", $iColor2, "int", $iColor, "int", 1, "int", 0, "int*", 0) Local $hBrush_Gradient = $aResult[6] DllCall($ghGDIPDll, "int", "GdipAddPathArc", "handle", $hPath_Fg, "float", 1, "float", 0, "float", $dW * 0.8, "float", $iH, "float", 90, "float", 180) DllCall($ghGDIPDll, "int", "GdipAddPathArc", "handle", $hPath_Fg, "float", $iW - $dW - $dW / 5, "float", 0, "float", $dW * 0.8, "float", $iH, "float", -90, "float", 180) DllCall($ghGDIPDll, "int", "GdipClosePathFigure", "handle", $hPath_Fg) $aResult = DllCall($ghGDIPDll, "int", "GdipFillPath", "handle", $hCtxt, "handle", $hBrush_Gradient, "handle", $hPath_Fg) DllCall($ghGDIPDll, "int", "GdipDeletePath", "handle", $hPath_Bg) DllCall($ghGDIPDll, "int", "GdipDeletePath", "handle", $hPath_Fg) _GDIPlus_GraphicsDispose($hCtxt) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BrushDispose($hBrush_Gradient) Switch $iRotate Case 1 DllCall($ghGDIPDll, "uint", "GdipImageRotateFlip", "handle", $hBitmap, "int", 1) Case 2 DllCall($ghGDIPDll, "uint", "GdipImageRotateFlip", "handle", $hBitmap, "int", 3) EndSwitch If $hHBitmap Then Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hHBmp EndIf Return $hBitmap EndFunc ;==>_GDIPlus_CreateRoundRectImage Func _GDIPlus_CreateEllipseThumb($iSize, $iColor = 0xD0A00000, $iColor_Center = 0xFFFFA0A0, $hHBitmap = True, $sFile = "") Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePath", "int", 0, "int*", 0) Local $hPath = $aResult[2] DllCall($ghGDIPDll, "int", "GdipAddPathEllipse", "handle", $hPath, "float", 0, "float", 0, "float", $iSize, "float", $iSize) $aResult = DllCall($ghGDIPDll, "int", "GdipCreatePathGradientFromPath", "handle", $hPath, "int*", 0) Local $hBrush_Gradient = $aResult[2] Local $fCenter = $iSize / 2 Local $tPointF = DllStructCreate("float;float") DllStructSetData($tPointF, 1, $fCenter * 0.6) DllStructSetData($tPointF, 2, $fCenter * 0.4) $aResult = DllCall($ghGDIPDll, "int", "GdipSetPathGradientCenterPoint", "handle", $hBrush_Gradient, "ptr", DllStructGetPtr($tPointF)) $tARGB = DllStructCreate("int") DllStructSetData($tARGB, 1, $iColor, 1) DllCall($ghGDIPDll, "int", "GdipSetPathGradientSurroundColorsWithCount", "handle", $hBrush_Gradient, "int", DllStructGetPtr($tARGB), "int*", 1) DllCall($ghGDIPDll, "int", "GdipSetLineGammaCorrection", "handle", $hBrush_Gradient, "int", True) DllCall($ghGDIPDll, "int", "GdipSetPathGradientCenterColor", "handle", $hBrush_Gradient, "int", $iColor_Center) $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromScan0", "int", $iSize, "int", $iSize, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) Local $hBitmap = $aResult[6] Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hCtxt, 2) DllCall($ghGDIPDll, "int", "GdipFillPath", "handle", $hCtxt, "handle", $hBrush_Gradient, "handle", $hPath) DllCall($ghGDIPDll, "int", "GdipClosePathFigure", "handle", $hPath) DllCall($ghGDIPDll, "int", "GdipDeletePath", "handle", $hPath) Local $hPen = _GDIPlus_PenCreate(0xD0080808) _GDIPlus_GraphicsDrawEllipse($hCtxt, 0, 0, $iSize - 1, $iSize - 1, $hPen) _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hCtxt) _GDIPlus_BrushDispose($hBrush_Gradient) If $hHBitmap Then Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hHBmp EndIf Return $hBitmap EndFunc ;==>_GDIPlus_CreateEllipseThumb Func _GDIPlus_CreateHBitmapFromFile($sFile, $iW, $iH) Local $hBmp = _GDIPlus_BitmapCreateFromFile($sFile) Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateBitmapFromScan0", "int", $iW, "int", $iH, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0) Local $hBitmap = $aResult[6] Local $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) DllCall($ghGDIPDll, "int", "GdipSetInterpolationMode", "handle", $hCtxt, "int", 7) _GDIPlus_GraphicsDrawImageRect($hCtxt, $hBmp, 0, 0, $iW, $iH) _GDIPlus_BitmapDispose($hBmp) _GDIPlus_GraphicsDispose($hCtxt) Local $hHBmp = _WinAPI_BitmapCreateDIBFromBitmap($hBitmap) _GDIPlus_BitmapDispose($hBitmap) Return $hHBmp EndFunc ;==>_GDIPlus_CreateHBitmapFromFile Func _WinAPI_BitmapCreateDIBFromBitmap($hBitmap) ;create 32-bit bitmap v5 (alpha channel supported) Local $tBIHDR, $aRet, $tData, $pBits, $hResult = 0 $aRet = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0) If (@error) Or ($aRet[0]) Then Return 0 $tData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $aRet[2], $aRet[3], $GDIP_ILMREAD, $GDIP_PXF32ARGB) $pBits = DllStructGetData($tData, 'Scan0') If Not $pBits Then Return 0 $tBIHDR = DllStructCreate('dword bV5Size;long bV5Width;long bV5Height;ushort bV5Planes;ushort bV5BitCount;dword bV5Compression;dword bV5SizeImage;long bV5XPelsPerMeter;long bV5YPelsPerMeter;dword bV5ClrUsed;dword bV5ClrImportant;dword bV5RedMask;dword bV5GreenMask;dword bV5BlueMask;dword bV5AlphaMask;dword bV5CSType;int bV5Endpoints[3];dword bV5GammaRed;dword bV5GammaGreen;dword bV5GammaBlue;dword bV5Intent;dword bV5ProfileData;dword bV5ProfileSize;dword bV5Reserved;') DllStructSetData($tBIHDR, 'bV5Size', DllStructGetSize($tBIHDR)) DllStructSetData($tBIHDR, 'bV5Width', $aRet[2]) DllStructSetData($tBIHDR, 'bV5Height', $aRet[3]) DllStructSetData($tBIHDR, 'bV5Planes', 1) DllStructSetData($tBIHDR, 'bV5BitCount', 32) DllStructSetData($tBIHDR, 'bV5Compression', 3) ; $BI_BITFIELDS = 3 DllStructSetData($tBIHDR, 'bV5SizeImage', $aRet[3] * DllStructGetData($tData, 'Stride')) DllStructSetData($tBIHDR, 'bV5AlphaMask', 0xFF000000) DllStructSetData($tBIHDR, 'bV5RedMask', 0x00FF0000) DllStructSetData($tBIHDR, 'bV5GreenMask', 0x0000FF00) DllStructSetData($tBIHDR, 'bV5BlueMask', 0x000000FF) DllStructSetData($tBIHDR, 'bV5CSType', 2) ; LCS_WINDOWS_COLOR_SPACE = 2 DllStructSetData($tBIHDR, 'bV5Intent', 4) ; $LCS_GM_IMA $hResult = DllCall('gdi32.dll', 'ptr', 'CreateDIBSection', 'hwnd', 0, 'ptr', DllStructGetPtr($tBIHDR), 'uint', 0, 'ptr*', 0, 'ptr', 0, 'dword', 0) If (Not @error) And ($hResult[0]) Then DllCall('gdi32.dll', 'dword', 'SetBitmapBits', 'ptr', $hResult[0], 'dword', $aRet[2] * $aRet[3] * 4, 'ptr', DllStructGetData($tData, 'Scan0')) $hResult = $hResult[0] Else $hResult = 0 EndIf _GDIPlus_BitmapUnlockBits($hBitmap, $tData) Return $hResult EndFunc ;==>_WinAPI_BitmapCreateDIBFromBitmap Func Min($a, $b) If $a < $b Then Return $a Return $b EndFunc ;==>Min Func Max($a, $b) If $a > $b Then Return $a Return $b EndFunc ;==>Max It is beta and probably buggy! All needed files in the attachment -> New Slider.7z (73 download previously) Br, UEZ1 point
-
And while playing around... here is a version which passes commandline parameters to first instance via WM_COPYDATA before exiting... Compile and start multiple times with different commandline parameters to see whats happening... #NoTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hwnd_AutoIt = _EnforceSingleInstance('e15ff08b-84ac-472a-89bf-5f92db683165') ; any 'unique' string; created with http://www.guidgen.com/Index.aspx Opt("TrayIconHide", 1) $hGUI = GUICreate("My GUI " & $hwnd_AutoIt,300,300,Default,Default) ; will create a dialog box that when displayed is centered $label = GUICtrlCreateLabel($CmdLineRaw,10,10,300,100) GUISetState(@SW_SHOW) ; will display an empty dialog box ControlSetText($hwnd_AutoIt,'',ControlGetHandle($hwnd_AutoIt,'','Edit1'),$hGUI) ; to pass hWnd of main GUI to AutoIt default GUI GUIRegisterMsg($WM_COPYDATA, "WM_COPYDATA") While 1 sleep(10) $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd GUIDelete() Func _EnforceSingleInstance($GUID_Program = "") If $GUID_Program = "" Then Return $hwnd = WinGetHandle($GUID_Program) If IsHWnd($hwnd) Then $hwnd_Target = ControlGetText($hwnd,'',ControlGetHandle($hwnd,'','Edit1')) WM_COPYDATA_SendData(HWnd($hwnd_Target), $CmdLineRaw) Exit EndIf AutoItWinSetTitle($GUID_Program) Return WinGetHandle($GUID_Program) EndFunc ;==>_EnforceSingleInstance Func WM_COPYDATA($hWnd, $MsgID, $wParam, $lParam) ; http://www.autoitscript.com/forum/index.php?showtopic=105861&view=findpost&p=747887 ; Melba23, based on code from Yashied Local $tCOPYDATA = DllStructCreate("ulong_ptr;dword;ptr", $lParam) Local $tMsg = DllStructCreate("char[" & DllStructGetData($tCOPYDATA, 2) & "]", DllStructGetData($tCOPYDATA, 3)) $msg = DllStructGetData($tMsg, 1) if $msg = " " then GUICtrlSetData($label, "") else GUICtrlSetData($label, DllStructGetData($tMsg, 1)) endif Return 0 EndFunc ;==>WM_COPYDATA Func WM_COPYDATA_SendData($hWnd, $sData) If Not IsHWnd($hWnd) Then Return 0 if $sData = "" then $sData = " " Local $tCOPYDATA, $tMsg $tMsg = DllStructCreate("char[" & StringLen($sData) + 1 & "]") DllStructSetData($tMsg, 1, $sData) $tCOPYDATA = DllStructCreate("ulong_ptr;dword;ptr") DllStructSetData($tCOPYDATA, 2, StringLen($sData) + 1) DllStructSetData($tCOPYDATA, 3, DllStructGetPtr($tMsg)) $Ret = DllCall("user32.dll", "lparam", "SendMessage", "hwnd", $hWnd, "int", $WM_COPYDATA, "wparam", 0, "lparam", DllStructGetPtr($tCOPYDATA)) If (@error) Or ($Ret[0] = -1) Then Return 0 Return 1 EndFunc ;==>WM_COPYDATA_SendData1 point
-
Even more fun! Made this after checking out LockWorkStation because of your DLL tutorial: Get notification when session is locked and unlocked: Global Const $NOTIFY_FOR_THIS_SESSION = 0x0 Global Const $NOTIFY_FOR_ALL_SESSIONS = 0x1 Global Const $WM_WTSSESSION_CHANGE = 0x2B1 Global Const $WTS_CONSOLE_CONNECT = 0x1 Global Const $WTS_CONSOLE_DISCONNECT = 0x2 Global Const $WTS_REMOTE_CONNECT = 0x3 Global Const $WTS_REMOTE_DISCONNECT = 0x4 Global Const $WTS_SESSION_LOGON = 0x5 Global Const $WTS_SESSION_LOGOFF = 0x6 Global Const $WTS_SESSION_LOCK = 0x7 Global Const $WTS_SESSION_UNLOCK = 0x8 Global Const $WTS_SESSION_REMOTE_CONTROL = 0x9 Global $hGUI = GUICreate("Message Sink", 400, 600); GUI to receive notification Global $sMsg = "$hGUI = " & $hGUI & @CRLF Global $ctrlEdit = GUICtrlCreateEdit($sMsg, 10, 10, 380, 580) GUISetState() GUIRegisterMsg($WM_WTSSESSION_CHANGE, "_WM_WTSSESSION_CHANGE") DllCall("Wtsapi32.dll", "int", "WTSRegisterSessionNotification", "hwnd", $hGUI, "dword", $NOTIFY_FOR_THIS_SESSION) DllCall("Kernel32.dll", "none", "Sleep", "dword", 1000) DllCall("User32.dll", "int", "LockWorkStation") While 1 If GUIGetMsg() = -3 Then ExitLoop WEnd DllCall("Wtsapi32.dll", "int", "WTSUnRegisterSessionNotification", "hwnd", $hGUI) Func _WM_WTSSESSION_CHANGE($hWnd, $iMsgID, $wParam, $lParam) $sMsg &= @CRLF & @HOUR & ":" & @Min & ":" & @SEC & " = " Switch $wParam Case $WTS_CONSOLE_CONNECT $sMsg &= "A session was connected to the console terminal." Case $WTS_CONSOLE_DISCONNECT $sMsg &= "A session was disconnected from the console terminal." Case $WTS_REMOTE_CONNECT $sMsg &= "A session was connected to the remote terminal." Case $WTS_REMOTE_DISCONNECT $sMsg &= "A session was disconnected from the remote terminal." Case $WTS_SESSION_LOGON $sMsg &= "A user has logged on to the session." Case $WTS_SESSION_LOGOFF $sMsg &= "A user has logged off the session." Case $WTS_SESSION_LOCK $sMsg &= "A session has been locked." Case $WTS_SESSION_UNLOCK $sMsg &= "A session has been unlocked." Case $WTS_SESSION_REMOTE_CONTROL $sMsg &= "A session has changed its remote controlled status." EndSwitch $sMsg &= @CRLF & "$hWnd = " & $hWnd & @CRLF & _ "$iMsgID = 0x" & Hex($iMsgID, 8) & @CRLF & _ "$wParam = " & $wParam & @CRLF & _ "$lParam = " & $lParam & @CRLF ControlSetText($hGUI, "", $ctrlEdit, $sMsg) EndFunc Thank you, master monoceres, for my DLL-fu grows stronger! There must be great Chi in sitting around eating cereal in your underwear!1 point
-
It seems to me that I used $SS_CENTERIMAGE to get vertical centering on a label control.1 point