Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/27/2021 in all areas

  1. You're using GetProgress in your code. 😅 Saludos
    2 points
  2. 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)
    1 point
  3. Use this to unaccent your strings: ; Unicode Normalization Forms Global Enum $UNF_NormC = 1, $UNF_NormD, $UNF_NormKC = 5, $UNF_NormKD Func _UNF_Change($sIn, $iForm) If $iForm = $UNF_NormC Or $iForm = $UNF_NormD Or $iForm = $UNF_NormKC Or $iForm = $UNF_NormKD Then Local $aRet = DllCall("Normaliz.dll", "int", "NormalizeString", "int", $iForm, "wstr", $sIn, "int", -1, "ptr", 0, "int", 0) Local $tOut = DllStructCreate("wchar[" & 2 * ($aRet[0] + 20) & "]") $aRet = DllCall("Normaliz.dll", "int", "NormalizeString", "int", $iForm, "wstr", $sIn, "int", -1, "ptr", DllStructGetPtr($tOut, 1), "int", 2 * ($aRet[0] + 20)) Return DllStructGetData($tOut, 1) Else SetError(1, 0, $sIn) EndIf EndFunc ;==>_UNF_Change Func _Unaccent($s, $iMode = 0) Local Static $aPat = [ _ "(*UCP)[\x{300}-\x{36F}`'¨^¸¯]", _ ; $iMode = 0 : remove combining accents only "(*UCP)\p{Mn}|\p{Lm}|\p{Sk}" _ ; $iMode = 1 : " " " and modifying letters ] Return StringRegExpReplace(_UNF_Change($s, $UNF_NormD), $aPat[Mod($iMode, 2)], "") EndFunc ;==>_Unaccent Local $s = 'Nếu tôi là cậu thì sẽ biết mệt mỏi' Local $t = _Unaccent($s) MsgBox(0, "", $s & @LF & $t) This has nothing to do with UTF8, let alone unsigned UTF8 (which doesn't make sense).
    1 point
  4. It happens to all of us 🤣 I'm getting some issue while creating the BackgroundCopyManager Instance. I get AutoIt stuck while creating "{4BD3E4E1-7BD4-4A2B-9964-496400DE5193}", _ ; BITS 10.1 instance. BITS 10.3 and BITS 10.2 fails correctly. but BITS 10.1 make my code get stuck forever in the ObjCreateInterface. I'll check deeply later. It's just to to let you know. Saludos
    1 point
  5. There already is a way to create threads in AutoIt, yes, real actual threads. You literally call the CreateThread function via DllCall (since it's a Win32 function), someone even made a wrapper UDF around it: https://github.com/jesobreira/thread.au3 It works, but crashes are imminent because AutoIt was designed to work in a single thread, so once the thread does something which conflicts with the main thread, the program segfaults and crashes hard. Yeah... I am being careful of that too, I don't want to make ECI yet another OOP language, the beauty of AutoIt is in the simplicity, no complex object hierarchy and convoluted code. I guess there is no way to enforce this but making the standard library not use objects extensively should set an example for those who want to write code with the best practices.
    1 point
  6. Yeah, it did - but I warned you. The part I found interesting was the concept of building features into the language (that are desired by the community) and then not telling anyone about them for fear of “misuse”. It wasn’t exactly clear how the dot notation was discovered by the Hoi Polloi, but it certainly could have been someone not familiar with the language guessing. Makes you wonder what else may lie dormant, just waiting for the AutoIt ingenue to stumble upon…. ThreadCreate() perhaps?
    1 point
  7. Made one. #include <GDIPlus.au3> #include <Crypt.au3> Example() Func Example() If Not WinExists("[CLASS:Notepad]") Then Run("Notepad") WinWait("[CLASS:Notepad]") EndIf Local $hWnd = WinGetHandle("[CLASS:Notepad]") Local $hTimer = TimerInit() Local $dPCS = _PixelCheckSum($hWnd, 10, 10, 200, 200) ConsoleWrite(TimerDiff($hTimer) & "/" & $dPCS & @CRLF) EndFunc ;==>Example Func _PixelCheckSum($hWnd, $iLeft, $iTop, $iRight, $iBottom, $bStart = True) Local $hDC_Capture = _WinAPI_GetDC($hWnd) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture) Local $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $iRight, $iBottom) Local $hObject = _WinAPI_SelectObject($hMemDC, $hHBitmap) _WinAPI_PrintWindow($hWnd, $hMemDC) If $bStart Then _GDIPlus_Startup() Local $hBMP = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap) Local $iWidth = $iRight - $iLeft, $iHeight = $iBottom - $iTop Local $tStruct = _GDIPlus_BitmapLockBits($hBMP, $iLeft, $iTop, $iWidth, $iHeight, $GDIP_ILMREAD, $GDIP_PXF32ARGB) Local $tPixel = DllStructCreate("byte arr[" & $iWidth * $iHeight * 4 & "]", $tStruct.Scan0) Local $dRet = _Crypt_HashData($tPixel.arr, $CALG_MD5) _GDIPlus_BitmapUnlockBits($hBMP, $tStruct) _GDIPlus_BitmapDispose($hBMP) If $bStart Then _GDIPlus_Shutdown() _WinAPI_SelectObject($hMemDC, $hObject) _WinAPI_DeleteDC($hMemDC) _WinAPI_ReleaseDC($hWnd, $hDC_Capture) _WinAPI_DeleteObject($hHBitmap) Return $dRet EndFunc ;==>_PixelCheckSum
    1 point
  8. TheDcoder

    Au3Check bug ?

    Sorry, I am 2 years late to the party, but I stumbled across this thread while searching for something, I can perhaps take a look at those YACC and FLEX bugs as I am a certified professional now because I read the book about them. @Jos Are these bugs still relevant? If so, I can offer my assistance if that is okay, please advice.
    1 point
  9. Where does the file 144WindowsAgentSetup.msi reside on disk? Sounds like misexec can't locate it. Also, you generally want to put #RequireAdmin at the top of your script.
    1 point
  10. Screensaver, Sleep, Workstation Lock, and Power-Save Disabling Since I see this question asked again and again, and the simple answer isn't always given (or at least, only half of it is), I'm posting this for reference. To disable Power-saving, Workstation Locking, Screensavers, etc., all that's needed is a call to SetThreadExecutionState. No need for timers, nor for emulating mouse or keyboard input. Just make a call to that API once to disable any locking/sleeping/screensaverin'. When you're done, make another call to it with the proper parameters (this part is important), and everything will be restored. NOTE: The 'execution state' should really only matter while the program that made the call is running (its supposed to be per-application). Once it is terminated, the execution state should be restored. However, there have been some unusual reports regarding this, especially when it is called by more than one process. The main functions in my module are _PowerKeepAlive() and _PowerResetState(). One keeps everything 'awake', the other reenables the default state of Windows power settings (including screensavers and workstation locking). The primary reason I've used this myself is for games that forget to call that API function, and after playing with the joystick for a while, a screensaver or lock-screen will pop up. Using these functions will workaround that problem. Also!: If you want to save and restore the current power-savings 'execution state', just pass the return value from _PowerKeepAlive() as the first argument to 'SetThreadExecutionState'. Anyway, here's the main module I use (example use is below): #include-once ; =============================================================================================================================== ; <_PowerKeepAlive.au3> ; ; Functions to prevent/disable sleep/power-savings modes (AND screensaver) ; ; Functions: ; _PowerKeepAlive() ; _PowerResetState() ; ; See also: ; <_ScreenSaverFunctions.au3> ; query, change, enable & disable screensaver. ; ; Author: Ascend4nt ; =============================================================================================================================== ; ========================================================================================================================== ; Func _PowerKeepAlive() ; ; Function to Prevent the Screensaver and Sleep/Power-savings modes from kicking in. ; NOTE: Be sure to reset this state on exit! ; ; Returns: ; Success: @error=0 & previous state as # (typically 0x80000000 [-2147483648]) ; Failure: @error set (returns 0x80000000, but thats just the normal state) ; @error = 2 = DLLCall error. @extended = DLLCall error code (see AutoIt Help) ; ; Author: Ascend4nt ; ========================================================================================================================== Func _PowerKeepAlive() #cs ; Flags: ; ES_SYSTEM_REQUIRED (0x01) -> Resets system Idle timer ; ES_DISPLAY_REQUIRED (0x02) -> Resets display Idle timer ; ES_CONTINUOUS (0x80000000) -> Forces 'continuous mode' -> the above 2 will not need to continuously be reset #ce Local $aRet=DllCall('kernel32.dll','long','SetThreadExecutionState','long',0x80000003) If @error Then Return SetError(2,@error,0x80000000) Return $aRet[0] ; Previous state (typically 0x80000000 [-2147483648]) EndFunc ; ========================================================================================================================== ; Func _PowerResetState() ; ; Function to Reset the Screensaver and Sleep/Power-savings modes to defaults. ; NOTE: The timer is reset on each call to this! ; ; Returns: ; Success: @error=0 & previous state as # ; Failure: @error set (returns 0x80000000, but thats just the normal state) ; @error = 2 = DLLCall error. @extended = DLLCall error code (see AutoIt Help) ; ; Author: Ascend4nt ; ========================================================================================================================== Func _PowerResetState() ; Flag: ES_CONTINUOUS (0x80000000) -> (default) -> used alone, it resets timers & allows regular sleep/power-savings mode Local $aRet=DllCall('kernel32.dll','long','SetThreadExecutionState','long',0x80000000) If @error Then Return SetError(2,@error,0x80000000) Return $aRet[0] ; Previous state EndFunc Example usage: #NoTrayIcon #include "_PowerKeepAlive.au3" ; Singleton code: If WinExists("SA_0bc53fe0-59c2-11e2-bcfd-0800200c9a66_SA") Then Exit AutoItWinSetTitle("SA_0bc53fe0-59c2-11e2-bcfd-0800200c9a66_SA") Opt("TrayOnEventMode", 0) Opt("TrayMenuMode", 1+2) TraySetClick(8+1) Local $iTrayExit = TrayCreateItem("Exit + Reenable Sleep") ; Disable screensaver, power-save, etc _PowerKeepAlive() ; Be sure to register this to reenable power-saving, screensaver, etc OnAutoItExitRegister("_PowerResetState") ; Now we're ready to accept messages TraySetState() While TrayGetMsg() <> $iTrayExit ; No need for sleep WEnd _PowerKeepAlive.au3
    1 point
×
×
  • Create New...