Leaderboard
Popular Content
Showing content with the highest reputation on 02/18/2024 in all areas
-
MsgBox_Extn() UDF
ioa747 and 3 others reacted to argumentum for a topic
It started in the help area, to delay the OK button for X seconds but is a good example for a mix of _WinAPI_SetTimer(), _WinAPI_SetWindowsHookEx(), IsFunc(), FuncName() and a callback. ; same as MsgBox() + button to delay[ /options ] [+ X,Y,W,H ] _MsgBox_Extn(5, BitOR($MB_TOPMOST, $MB_ICONINFORMATION, $MB_OK), "My title", "My Message", 20) ;~ _MsgBox_Extn("0, 20, 100", BitOR($MB_TOPMOST, $MB_ICONINFORMATION, $MB_OKCANCEL), "My title", "My Message", 20) ;~ _MsgBox_Extn("5/1, 20, 100", BitOR($MB_TOPMOST, $MB_ICONINFORMATION, $MB_YESNO), "My title", "My Message", 20) ;~ _MsgBox_Extn("5 sec. / -4th button, 20, 100, 600, 300", BitOR($MB_TOPMOST, $MB_ICONINFORMATION, $MB_CANCELTRYCONTINUE, $MB_HELP), "My title", "My Message", 20) The use is simple ( to me that I wrote it ). Try the examples above and it'll be self evident. Is a MsgBox with an extra ( 1st ) parameter. All expected returns are the same. But in @error there is also the return value and in @extended the line number were something is wrong. I may start coding this way for myself too. Is like a UDF with training wheels. A fun example of the callback is: #include <MsgBox_Extn.au3> ; https://www.autoitscript.com/forum/index.php?showtopic=211523 ConsoleWrite(@CRLF & "+++ _MsgBox_Extn() returned: $" & _MsgBox_Extn_ReturnMeaning(Example_CallBack(4)) & ' (' & @extended & ')' & @CRLF & @CRLF) ConsoleWrite('==========------------==========------------==========------------==========------------==========------------==========') ConsoleWrite(@CRLF & "+++ _MsgBox_Extn() returned: $" & _MsgBox_Extn_ReturnMeaning(Example_CallBack(1)) & ' (' & @extended & ')' & @CRLF & @CRLF) Func Example_CallBack($iTryButton) If _MsgBox_Extn_Version() < 5 Then Return SetError(1, 0, -2) Local $MsgText = 'Now this example will punish you' & @CR & 'by wasting 60 seconds of your life.' _MsgBox_Extn_SetCallBackFunc(_MyCallBack_TimerProc) If @error Then Return SetError(2, 0, -2) ConsoleWrite('+++ Using "' & FuncName(_MsgBox_Extn_SetCallBackFunc()) & '" as callback function.' & @CRLF) Local $iMisuseAtLineNumber, $iRet = _MsgBox_Extn("60/-" & $iTryButton, BitOR($MB_OKCANCEL, $MB_HELP), 'Example', $MsgText, 15) ; "-4" is wrong. Part of the demo. $iReturn = @error $iMisuseAtLineNumber = @extended ; so misuse/error, can be gathered for debug. If $iMisuseAtLineNumber Then ConsoleWrite('! At line ' & $iMisuseAtLineNumber & ' in the UDF, there was a complain. ( Naggy UDF ! )' & @CRLF) ConsoleWrite('@error (' & $iReturn & ') holds the same value as Return (' & $iRet & '). Why ?, meh, it may come in handy.' & _ ' There is no error return in MsgBox. Let''s give it some use.' & @CRLF) _MsgBox_Extn_SetCallBackFunc(Default) ; if you're not gonna use it anymore. Return $iRet EndFunc ;==>Example_CallBack Func _MyCallBack_TimerProc() Switch _MsgBox_Extn_SecCount() Case 60 ConsoleWrite('UDF version: ' & _MsgBox_Extn_Version() & @CRLF) Case 58 ; With the MsgBox HWnd, you can have your fun. ControlEnable(_MsgBox_Extn_GetHWnd(), "", "Button2") Case 57 _MsgBox_Extn_SetMessageText('Nah, just kidding =)') _MsgBox_Extn_SecCount(3) _MsgBox_Extn_SetCounterButtonText(_MsgBox_Extn_SetCounterButtonText() & " ?") Case 1 ; Setting "SetCounterButtonText" is used on a next loop. In 1 second. _MsgBox_Extn_SetCounterButtonText(_MsgBox_Extn_GetOrigBttnText()) Case 0 _MsgBox_Extn_SetButtonText(Default, Default, _MsgBox_Extn_GetOrigBttnText( _MsgBox_Extn_TotalCount()) & " ???") _MsgBox_Extn_ApplyButtonText() EndSwitch EndFunc ;==>_MyCallBack_TimerProc and the UDF code: #include-once ; #include <MsgBox_Extn.au3> ; https://www.autoitscript.com/forum/index.php?showtopic=211523 #include <WinAPISys.au3> #include <WinAPISysWin.au3> ; do check these include with your current version of AutoIt, it func() not found ( note for the future ) #include <WinAPI.au3> #include <MsgBoxConstants.au3> ; for the demo Global Const $g__MsgBox_Extn_tagCBT_CREATEWND = "ptr lpcs;HWND tagCBT_CREATEWND" ; https://www.autoitscript.com/forum/topic/191204-hookdlgbox-udf/ Global Const $g__MsgBox_Extn_tagCREATESTRUCT = "ptr lpCreateParams;handle hInstance;HWND hMenu;HWND hwndParent;int cy;int cx;int y;int x;LONG style;ptr lpszName;ptr lpszClass;DWORD dwExStyle" Global Const $g__MsgBox_Extn_aReturnMeaning[13] = [11, "IDOK", "IDCANCEL", "IDABORT", "IDRETRY", "IDIGNORE", "IDYES", "IDNO", "ID#8", "ID#9", "IDTRYAGAIN", "IDCONTINUE", "IDTIMEOUT"] Global $g__MsgBox_Extn_Globals_UDFversion = 5, _ $g__MsgBox_Extn_Globals_hHook = 0, _ $g__MsgBox_Extn_Globals_DisableAll = 0, _ $g__MsgBox_Extn_Globals_BttnAtlText[5] = [4, Default, Default, Default, Default], _ $g__MsgBox_Extn_Globals_BttnOriText[5] = [4, Default, Default, Default, Default], _ $g__MsgBox_Extn_Globals_DelayOnBttnNo = 1, _ $g__MsgBox_Extn_Globals_aWinPos = 0, _ $g__MsgBox_Extn_Globals_iSecCount = 0, _ $g__MsgBox_Extn_Globals_hWnd = 0, _ $g__MsgBox_Extn_Globals_hCallBackFunc = Default, _ $g__MsgBox_Extn_Globals_iDoitOnlyOnce = 1, _ $g__MsgBox_Extn_Globals_BttnOriCount = 0, _ $g__MsgBox_Extn_Globals_iWarning = 0, _ $g__MsgBox_Extn_Globals_sOriginalText ; same as MsgBox() + button to delay[ /options ] [+ X,Y,W,H ] ;~ _MsgBox_Extn(5, BitOR($MB_TOPMOST, $MB_ICONINFORMATION, $MB_OK), "My title", "My Message", 20) ;~ _MsgBox_Extn("0, 20, 100", BitOR($MB_TOPMOST, $MB_ICONINFORMATION, $MB_OKCANCEL), "My title", "My Message", 20) ;~ _MsgBox_Extn("5/1, 20, 100", BitOR($MB_TOPMOST, $MB_ICONINFORMATION, $MB_YESNO), "My title", "My Message", 20) ;~ _MsgBox_Extn("5 sec. / -4th button, 20, 100, 600, 300", BitOR($MB_TOPMOST, $MB_ICONINFORMATION, $MB_CANCELTRYCONTINUE, $MB_HELP), "My title", "My Message", 20) ; SecDelay The time delay until the control is re-enabled ; or a comma delimited string up to "delay [, X pos [, Y pos [, Width [, Height]]]]" ; "delay" can be formated as "delay [ /ButtonNumber]". Default is Button1. ; if ButtonNumber is a negative number, it'll disable all the buttons. ; flag The flag indicates the type of message box and the possible button combinations. See remarks in MsgBox(). ; title The title of the message box. ; text The text of the message box. ; timeout [optional] Timeout in seconds. After the timeout has elapsed the message box will close automatically. The default is 0, which is no timeout. ; hwnd [optional] The window handle to use as the parent for this dialog. ; Return Value ; Success: the ID of the button pressed. ; Failure: $IDTIMEOUT (-1) if the message box timed out. ; ; @extended = function misuse Func _MsgBox_Extn($iSecDelay, $iFlag, $sTitle, $sText, $iSecTimeout = 0, $hParent_hwnd = 0) ; https://www.autoitscript.com/forum/index.php?showtopic=211499&view=findpost&p=1530323 $g__MsgBox_Extn_Globals_aWinPos = StringSplit($iSecDelay, ",") ReDim $g__MsgBox_Extn_Globals_aWinPos[6] Local $aBttnNoDelay = StringSplit(StringReplace($g__MsgBox_Extn_Globals_aWinPos[1], "\", "/"), "/") ReDim $aBttnNoDelay[3] $g__MsgBox_Extn_Globals_DelayOnBttnNo = Int($aBttnNoDelay[2]) If Not $g__MsgBox_Extn_Globals_DelayOnBttnNo Then $g__MsgBox_Extn_Globals_DelayOnBttnNo = 1 If $g__MsgBox_Extn_Globals_DelayOnBttnNo < 0 Then $g__MsgBox_Extn_Globals_DisableAll = 1 $g__MsgBox_Extn_Globals_DelayOnBttnNo = Abs($g__MsgBox_Extn_Globals_DelayOnBttnNo) EndIf If $g__MsgBox_Extn_Globals_DelayOnBttnNo > 4 Then _MsgBox_Extn_ConsoleWrite('Note: Button' & $g__MsgBox_Extn_Globals_DelayOnBttnNo & ' will not exist. Setting to Button1 to, be nice ?. Check the code.' & @CRLF) $g__MsgBox_Extn_Globals_DelayOnBttnNo = 1 ; function misuse ; no more than a 4th button. EndIf If $g__MsgBox_Extn_Globals_aWinPos[0] > 5 Then _MsgBox_Extn_ConsoleWrite('Note: ' & $g__MsgBox_Extn_Globals_aWinPos[0] & ' parameters are too many. Check the code.' & @CRLF) $g__MsgBox_Extn_Globals_aWinPos[0] = 5 ; better safe than sorry. ; function misuse ; $iSecDelay = "delay [, X pos [, Y pos [, Width [, Height]]]]" only. EndIf For $n = 1 To $g__MsgBox_Extn_Globals_aWinPos[0] $g__MsgBox_Extn_Globals_aWinPos[1] = Int($g__MsgBox_Extn_Globals_aWinPos[1]) Next For $n = $g__MsgBox_Extn_Globals_aWinPos[0] + 1 To 5 $g__MsgBox_Extn_Globals_aWinPos[$n] = Null ; these are unused place holders. Next Local $hTimerProc = DllCallbackRegister(__MsgBox_Extn_TimerProc, 'none', 'hwnd;uint;uint_ptr;dword') Local $iTimerID = _WinAPI_SetTimer(0, 0, 1000, DllCallbackGetPtr($hTimerProc)) ; $iTimerID should be 0 if the $hWnd is 0. Local $hProc = DllCallbackRegister(__MsgBox_Extn_CbtHookProc, "int", "int;int;int") $g__MsgBox_Extn_Globals_hHook = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($hProc), 0, _WinAPI_GetCurrentThreadId()) Local $iRet = MsgBox($iFlag, $sTitle, $sText, $iSecTimeout, $hParent_hwnd) _WinAPI_KillTimer(0, $iTimerID) DllCallbackFree($hTimerProc) _WinAPI_UnhookWindowsHookEx($g__MsgBox_Extn_Globals_hHook) DllCallbackFree($hProc) Local $iExt = $g__MsgBox_Extn_Globals_iWarning $g__MsgBox_Extn_Globals_iWarning = 0 $g__MsgBox_Extn_Globals_hHook = 0 $g__MsgBox_Extn_Globals_iSecCount = 0 $g__MsgBox_Extn_Globals_aWinPos = 0 $g__MsgBox_Extn_Globals_hWnd = 0 $g__MsgBox_Extn_Globals_iDoitOnlyOnce = 1 $g__MsgBox_Extn_Globals_DelayOnBttnNo = 1 $g__MsgBox_Extn_Globals_DisableAll = 0 Dim $g__MsgBox_Extn_Globals_BttnOriText[5] = [4, Default, Default, Default, Default] _MsgBox_Extn_SetButtonText() ; re-init all prior alternate button text to defaults. $g__MsgBox_Extn_Globals_BttnOriCount = 0 Return SetError($iRet, $iExt, $iRet) EndFunc ;==>_MsgBox_Extn ; Return the meaning/name of the enumerator/constant Func _MsgBox_Extn_ReturnMeaning($iIndex) $iIndex = Int($iIndex) If $iIndex = -1 Then Return SetExtended($iIndex, $g__MsgBox_Extn_aReturnMeaning[12]) Switch $iIndex Case 8, 9 Return SetError(1, $iIndex, "unkown index " & $iIndex) Case 1 To 12 Return SetExtended($iIndex, $g__MsgBox_Extn_aReturnMeaning[$iIndex]) EndSwitch Return SetError(2, $iIndex, "unkown index " & $iIndex) EndFunc ;==>_MsgBox_Extn_ReturnMeaning ; Returns the UDF version. Just in case more stuff is added. Func _MsgBox_Extn_Version() Return $g__MsgBox_Extn_Globals_UDFversion EndFunc ;==>_MsgBox_Extn_Version ; Get the original text of any of the 4 possible buttons. ; For if _MsgBox_Extn_SetCallBackFunc() is used. Func _MsgBox_Extn_GetOrigBttnText($iIndex = $g__MsgBox_Extn_Globals_DelayOnBttnNo) If $iIndex > 4 Or $iIndex < 1 Then $g__MsgBox_Extn_Globals_iWarning = @ScriptLineNumber _MsgBox_Extn_ConsoleWrite('Note: an $iIndex of ' & $iIndex & ' should have been between 1 and 4. Therefore is an error.' & @CRLF) $iIndex = $g__MsgBox_Extn_Globals_DelayOnBttnNo EndIf Return SetExtended(IsKeyword($g__MsgBox_Extn_Globals_BttnOriText[$iIndex]), $g__MsgBox_Extn_Globals_BttnOriText[$iIndex]) EndFunc ;==>_MsgBox_Extn_GetOrigBttnText ; Reset the original text of the 4 possible buttons. Or just the one you pass along as Index. ; For if _MsgBox_Extn_SetCallBackFunc() is used. Func _MsgBox_Extn_ResetButtonText($iIndex = Default) If IsKeyword($iIndex) = 1 Then For $n = 1 To $g__MsgBox_Extn_Globals_BttnOriText[0] $g__MsgBox_Extn_Globals_BttnAtlText[$n] = $g__MsgBox_Extn_Globals_BttnOriText[$n] Next Else If $iIndex > 4 Or $iIndex < 1 Then $g__MsgBox_Extn_Globals_iWarning = @ScriptLineNumber _MsgBox_Extn_ConsoleWrite('Note: an $iIndex of ' & $iIndex & ' should have been between 1 and 4. Therefore is an error.' & @CRLF) $iIndex = $g__MsgBox_Extn_Globals_DelayOnBttnNo EndIf $g__MsgBox_Extn_Globals_BttnAtlText[$n] = $g__MsgBox_Extn_Globals_BttnOriText[$n] EndIf EndFunc ;==>_MsgBox_Extn_ResetButtonText ; Set any of the 4 possible buttons, from left to right, with an alternate text. Func _MsgBox_Extn_SetButtonText($iButton1 = Default, $iButton2 = Default, $iButton3 = Default, $iButton4 = Default) $g__MsgBox_Extn_Globals_BttnAtlText[1] = $iButton1 $g__MsgBox_Extn_Globals_BttnAtlText[2] = $iButton2 $g__MsgBox_Extn_Globals_BttnAtlText[3] = $iButton3 $g__MsgBox_Extn_Globals_BttnAtlText[4] = $iButton4 EndFunc ;==>_MsgBox_Extn_SetButtonText ; After _MsgBox_Extn_SetButtonText(), you'll need to _MsgBox_Extn_ApplyButtonText() ; For use in _MsgBox_Extn_SetCallBackFunc() Func _MsgBox_Extn_ApplyButtonText() For $n = 1 To $g__MsgBox_Extn_Globals_BttnAtlText[0] If Not IsKeyword($g__MsgBox_Extn_Globals_BttnAtlText[$n]) Then ControlSetText($g__MsgBox_Extn_Globals_hWnd, "", "Button" & $n, String($g__MsgBox_Extn_Globals_BttnAtlText[$n]), 1) EndIf Next EndFunc ;==>_MsgBox_Extn_ApplyButtonText ; Set a new message text on the fly ; For use in _MsgBox_Extn_SetCallBackFunc() Func _MsgBox_Extn_SetMessageText($sStr) Local $iRet, $iStatic = 2 If ControlGetText($g__MsgBox_Extn_Globals_hWnd, "", "Static2") = "" Or @error Then $iStatic = 1 $iRet = ControlSetText($g__MsgBox_Extn_Globals_hWnd, "", "Static" & $iStatic, String($sStr)) Return SetError(Int(Not $iRet), $iStatic, $iRet) EndFunc ;==>_MsgBox_Extn_SetMessageText ; Set a new default text on the fly ; For use in _MsgBox_Extn_SetCallBackFunc() Func _MsgBox_Extn_SetCounterButtonText($sNewText = Default) If Not IsKeyword($sNewText) Then $g__MsgBox_Extn_Globals_sOriginalText = String($sNewText) Return $g__MsgBox_Extn_Globals_sOriginalText EndFunc ;==>_MsgBox_Extn_SetCounterButtonText ; Set a new count down on the fly via _MsgBox_Extn_SetCallBackFunc() Func _MsgBox_Extn_SecCount($iNewValue = Default) If Not IsKeyword($iNewValue) Then $g__MsgBox_Extn_Globals_aWinPos[1] = Int($iNewValue) $g__MsgBox_Extn_Globals_iSecCount = -1 EndIf Return $g__MsgBox_Extn_Globals_aWinPos[1] - $g__MsgBox_Extn_Globals_iSecCount EndFunc ;==>_MsgBox_Extn_SecCount Func _MsgBox_Extn_TotalCount() Return $g__MsgBox_Extn_Globals_BttnOriCount EndFunc ;==>_MsgBox_Extn_TotalCount ; The handle of the MsgBox(), to use in _MsgBox_Extn_SetCallBackFunc() Func _MsgBox_Extn_GetHWnd() Return $g__MsgBox_Extn_Globals_hWnd EndFunc ;==>_MsgBox_Extn_GetHWnd Func _MsgBox_Extn_ConsoleWrite($sStr, $iLineNumber = @ScriptLineNumber) Local Static $iReturn = Not (StringRight(@ScriptName, 4) = '.au3') $g__MsgBox_Extn_Globals_iWarning = $iLineNumber If $iReturn Then Return "" ConsoleWrite('"MsgBox_Extn.au3" (' & $iLineNumber & ',0) : ' & $sStr) EndFunc ;==>_MsgBox_Extn_ConsoleWrite ; To do stuff within the time the delay is active. ; example at https://www.autoitscript.com/forum/index.php?showtopic=211499&view=findpost&p=1530455 Func _MsgBox_Extn_SetCallBackFunc($hCallBackFunc = Null) ; a no parameter func(). Use helper func ( _MsgBox_Extn_* ) Local $iErr = 0 If IsKeyword($hCallBackFunc) = 1 Then ; $KEYWORD_DEFAULT (1) the Default keyword. ; $KEYWORD_NULL (2) the Null keyword. $g__MsgBox_Extn_Globals_hCallBackFunc = "" ; ..to remove the value ElseIf IsFunc($hCallBackFunc) Then $g__MsgBox_Extn_Globals_hCallBackFunc = $hCallBackFunc ElseIf IsKeyword($hCallBackFunc) = 2 Then ; This is to return the $hCallBackFunc in use. Else ; if we get to this point, is not a keyword nor a function. Therefore is an error. _MsgBox_Extn_ConsoleWrite('Note: If we get to this point, is not a keyword nor a function. Therefore is an error.' & @CRLF) $g__MsgBox_Extn_Globals_hCallBackFunc = "" ; since is an error, let's remove whatever was there. $iErr = 1 EndIf Return SetError($iErr, 0, $g__MsgBox_Extn_Globals_hCallBackFunc) EndFunc ;==>_MsgBox_Extn_SetCallBackFunc #Region INTERNAL Func __MsgBox_Extn_TimerProc($hWnd, $iMsg, $iTimerID, $iTime) ;~ ConsoleWrite('+ Func __MsgBox_Extn_TimerProc(' & $hWnd & ', ' & $iMsg & ', ' & $iTimerID & ', ' & $iTime & ')' & @CRLF) #forceref $hWnd, $iMsg, $iTimerID, $iTime $g__MsgBox_Extn_Globals_iSecCount += 1 If $g__MsgBox_Extn_Globals_iSecCount < $g__MsgBox_Extn_Globals_aWinPos[1] Then ControlSetText($g__MsgBox_Extn_Globals_hWnd, "", "Button" & $g__MsgBox_Extn_Globals_DelayOnBttnNo, _MsgBox_Extn_SetCounterButtonText() & ' (' & $g__MsgBox_Extn_Globals_aWinPos[1] - $g__MsgBox_Extn_Globals_iSecCount & ')') ElseIf $g__MsgBox_Extn_Globals_iSecCount = $g__MsgBox_Extn_Globals_aWinPos[1] Then ControlSetText($g__MsgBox_Extn_Globals_hWnd, "", "Button" & $g__MsgBox_Extn_Globals_DelayOnBttnNo, _MsgBox_Extn_SetCounterButtonText()) If $g__MsgBox_Extn_Globals_DisableAll Then For $n = 1 To 4 ControlEnable($g__MsgBox_Extn_Globals_hWnd, "", "Button" & $n) Next Else ControlEnable($g__MsgBox_Extn_Globals_hWnd, "", "Button" & $g__MsgBox_Extn_Globals_DelayOnBttnNo) EndIf EndIf If IsFunc($g__MsgBox_Extn_Globals_hCallBackFunc) Then $g__MsgBox_Extn_Globals_hCallBackFunc() ; $hWnd, $iMsg, $iTimerID, $iTime) ; there's no use for these. EndFunc ;==>__MsgBox_Extn_TimerProc Func __MsgBox_Extn_CbtHookProc($nCode, $wParam, $lParam) ;~ ConsoleWrite('+ Func __MsgBox_Extn_CbtHookProc(' & $nCode & ', ' & $wParam & ', ' & $lParam & ')' & @CRLF) If $nCode = 3 And $g__MsgBox_Extn_Globals_iDoitOnlyOnce = 1 And _WinAPI_GetClassName(HWnd($wParam)) = "#32770" Then $g__MsgBox_Extn_Globals_iDoitOnlyOnce = 2 $g__MsgBox_Extn_Globals_hWnd = HWnd($wParam) If $g__MsgBox_Extn_Globals_aWinPos[2] <> Null Then Local $tcs = DllStructCreate($g__MsgBox_Extn_tagCREATESTRUCT, DllStructGetData(DllStructCreate($g__MsgBox_Extn_tagCBT_CREATEWND, $lParam), "lpcs")) If $g__MsgBox_Extn_Globals_aWinPos[2] <> Null Then DllStructSetData($tcs, "x", $g__MsgBox_Extn_Globals_aWinPos[2]) If $g__MsgBox_Extn_Globals_aWinPos[3] <> Null Then DllStructSetData($tcs, "y", $g__MsgBox_Extn_Globals_aWinPos[3]) If $g__MsgBox_Extn_Globals_aWinPos[4] <> Null Then DllStructSetData($tcs, "cx", $g__MsgBox_Extn_Globals_aWinPos[4]) ; these Cx,Cy don't do anything functional If $g__MsgBox_Extn_Globals_aWinPos[5] <> Null Then DllStructSetData($tcs, "cy", $g__MsgBox_Extn_Globals_aWinPos[5]) ; but, you can use them if you wish. EndIf EndIf If $nCode = 5 And $g__MsgBox_Extn_Globals_iDoitOnlyOnce = 2 And $g__MsgBox_Extn_Globals_aWinPos[1] > 0 And HWnd($wParam) = $g__MsgBox_Extn_Globals_hWnd Then ; 5=HCBT_ACTIVATE $g__MsgBox_Extn_Globals_iDoitOnlyOnce = 0 _MsgBox_Extn_ApplyButtonText() If $g__MsgBox_Extn_Globals_DisableAll Then For $n = 1 To 4 ControlDisable($g__MsgBox_Extn_Globals_hWnd, "", "Button" & $n) Next Else ControlDisable($g__MsgBox_Extn_Globals_hWnd, "", "Button" & $g__MsgBox_Extn_Globals_DelayOnBttnNo) EndIf For $n = 1 To 4 $g__MsgBox_Extn_Globals_BttnOriText[$n] = ControlGetText($g__MsgBox_Extn_Globals_hWnd, "", "Button" & $n) If $g__MsgBox_Extn_Globals_BttnOriText[$n] = "" And @error Then If Not $g__MsgBox_Extn_Globals_BttnOriCount Then $g__MsgBox_Extn_Globals_BttnOriCount = $n - 1 $g__MsgBox_Extn_Globals_BttnOriText[$n] = Default EndIf Next If $g__MsgBox_Extn_Globals_DelayOnBttnNo > $g__MsgBox_Extn_Globals_BttnOriCount Then _MsgBox_Extn_ConsoleWrite('Note: Button' & $g__MsgBox_Extn_Globals_DelayOnBttnNo & ' does not exist on this ' & $g__MsgBox_Extn_Globals_BttnOriCount & ' button MsgBox. Setting to Button1. Check the code.' & @CRLF) $g__MsgBox_Extn_Globals_DelayOnBttnNo = 1 EndIf _MsgBox_Extn_SetCounterButtonText(_MsgBox_Extn_GetOrigBttnText($g__MsgBox_Extn_Globals_DelayOnBttnNo)) ControlSetText($g__MsgBox_Extn_Globals_hWnd, "", "Button" & $g__MsgBox_Extn_Globals_DelayOnBttnNo, _MsgBox_Extn_SetCounterButtonText() & ' (' & $g__MsgBox_Extn_Globals_aWinPos[1] & ')') If IsFunc($g__MsgBox_Extn_Globals_hCallBackFunc) Then $g__MsgBox_Extn_Globals_hCallBackFunc() ElseIf $nCode = 5 And $g__MsgBox_Extn_Globals_iDoitOnlyOnce = 2 And HWnd($wParam) = $g__MsgBox_Extn_Globals_hWnd Then _MsgBox_Extn_ApplyButtonText() EndIf Return _WinAPI_CallNextHookEx($g__MsgBox_Extn_Globals_hHook, $nCode, $wParam, $lParam) EndFunc ;==>__MsgBox_Extn_CbtHookProc #EndRegion INTERNAL And a $MB_HELP usage example ( somewhere down there ). If you don't feel like copy and paste all this then here: MsgBox_Extn[v5].zip In version 5 there more stuff. Lost count, but it has nagging code to let the user know, if the code has a complain about the parameters. So, this is a good example as far as examples but M23's Extended Message Box is a better option if you need a flexible MsgBox UDF.4 points -
GuiBuilderPlus [updated March 24, 2024]
yahaosoft reacted to kurtykurtyboy for a topic
GuiBuilderPlus GuiBuilderPlus is a small, easy to use GUI designer for AutoIt. Originally created long ago as AutoBuilder by the user CyberSlug, enhanced as GuiBuilder by TheSaint, and further enhanced and expanded as GuiBuilderNxt by jaberwacky, GuiBuilderPlus is a continuation of their great work, with a focus on increased stability and usability followed by new features. ------ Yes, I have decided to bring back our old friend the GuiBuilder. This utility has a long history, which you can read about in TheSaint's Gui Creators topic, starting all the back back with CyberSlug's AutoBuilder. Even though I've hacked the original code to pieces in order to document and better understand what is going on, the essence of GuiBuilder still lives on! I am using the awesome updates from GuiBuilderNxt by jaberwacky as a starting point since he already did a lot of the hard work of parsing and updating the original code, plus I really like the layout that came about from that update. Unfortunately development seems to have stopped in 2016. Not sure how much interest there is in this, but suggestions and bug reports are welcome. See Full Changelog: Download the latest version: v1.3.0 (2024-03-24) GuiBuilderPlus v1.3.0 - 2024-03-24.zip FIXED: Wrong line endings when copying from code preview window FIXED: Issue changing properties when Obect Explorer window is not open FIXED: Issue when selecting controls under certain other conditions FIXED: SaveAs keyboard shortcut FIXED: Undo/Redo for Global property ADDED: Auto-size property for Labels, Buttons, and Inputs GitHub Repository: https://github.com/KurtisLiggett/GuiBuilderPlus1 point -
SmartNote
itchiTrigger reacted to ioa747 for a topic
SmartNote tesseract Edition: SmartNote is a screen snip tool to snip screen area with OCR ability from tesseract 100+ languages I tried it in Windows 10 with the version tesseract-ocr-w32-setup-v5.3.0.20221214.exe Snipe new note Double Click the tray icon to start NewCapture or While Left Windows Key IsPressed, tap 2 times the Left Shift key (is useful when Capture menu or context menu). While start NewCapture point click anywhere to escape. (Does not catch smaller than 9*9 px) While start NewCapture escape with ESC SmartNote.au3 ; https://www.autoitscript.com/forum/topic/208600-smartnote/ ;---------------------------------------------------------------------------------------- ; Title...........: SmartNote.au3 ; Description.....: SmartNote is a screen snip tool to take Screenshot with OCR ability from Tesseract (100+ languages) ; AutoIt Version..: 3.3.16.1 Author: ioa747 ;---------------------------------------------------------------------------------------- #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=mmcndmgr-106.ico #AutoIt3Wrapper_Res_Description=SmartNote is a screen snip tool to take Screenshot with OCR ability from Tesseract (100+ languages) #AutoIt3Wrapper_Res_Fileversion=0.0.5.20240413 #AutoIt3Wrapper_Res_ProductName=SmartNote.au3 #AutoIt3Wrapper_Res_CompanyName=ioa747 #AutoIt3Wrapper_Res_LegalCopyright=ioa747 #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #NoTrayIcon If WinExists(StringTrimRight(@ScriptName, 4) & "_STUB") Then Exit 5 AutoItWinSetTitle(StringTrimRight(@ScriptName, 4) & "_STUB") If @AutoItX64 Then Exit MsgBox(262144 + 64, StringTrimRight(@ScriptName, 4), "Please run as 32bit", 60) #include <MsgBoxConstants.au3> #include <ScreenCapture.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <TrayConstants.au3> #include <Misc.au3> #include <Array.au3> #include <GDIPlus.au3> #include <Clipboard.au3> #include <String.au3> ; Initialization DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", "int", -4) ; -4=PerMonitorAwareV2 Opt("MouseCoordMode", 1) ; 1=absolute, 0=relative, 2=client Opt("TrayMenuMode", 3) ; 0=append, 1=no default menu, 2=no automatic check, 4=menuitemID not return Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode. Opt("GUIOnEventMode", 1) ; 0=disabled, 1=OnEvent mode enabled ; tray entry to exit script Global $TRAY_ExitScript = TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "TRAY_EVENT") ; separator TrayCreateItem("") ; tray entry to capture Global $TRAY_NewCapture = TrayCreateItem("Capture") TrayItemSetOnEvent(-1, "TRAY_EVENT") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "TRAY_EVENT") TraySetIcon("mmcndmgr.dll", -106) TraySetClick(16) ; $TRAY_CLICK_SECONDARYUP = 16 TraySetState($TRAY_ICONSTATE_SHOW) TraySetToolTip("SmartNote" & @CRLF & "Double Click to take new note") Global $mPos, $aRecPos[4], $hGUICapture, $block_gui Global $hDLL = DllOpen("user32.dll") ; array to hold the Contextmenu data Global $NoteGui[1][14] $NoteGui[0][0] = 0 ; cnt, Note_Handle $NoteGui[0][1] = "jpgPath" $NoteGui[0][2] = "Gui_Size" $NoteGui[0][3] = "ID_PicCtrl" $NoteGui[0][4] = "ID_ContextMenu" $NoteGui[0][5] = "ID_cMenuCopy" $NoteGui[0][6] = "ID_cMenuShareX" $NoteGui[0][7] = "ID_cMenuSave" $NoteGui[0][8] = "ID_cMenuOpen" $NoteGui[0][9] = "ID_cMenuOCR-eng" $NoteGui[0][10] = "ID_cMenuOCR-eng+ell" $NoteGui[0][11] = "ID_cMenuClose" $NoteGui[0][12] = "ID_Dummy_DeleteKey" $NoteGui[0][13] = "ID_Dummy_EnterKey" ; Check for leftover files Global $iFileExists = FileExists(@ScriptDir & "\tmp") If $iFileExists Then FileDelete(@ScriptDir & "\tmp\*.*") Else DirCreate(@ScriptDir & "\tmp") EndIf ;~ HotKeySet("{PGUP}", "_Array_Gui_display") ; *** Debug _ArrayDisplay($NoteGui, "$NoteGui") <<- HotKey ; ℹ️ While Left Windows Key IsPressed, tap 2 times the Left SHIFT key to start NewCapture, ; is useful when Capture menu or contex menu. ; While start NewCapture point click anywhere to escape. (does not catch smaller than 9*9 px) ; While start NewCapture escape with ESC Global $iShift ; loop until program exit ;************************************************ While Sleep(100) $iShift = 0 While _IsPressed("5B", $hDLL) ; 5B Left Windows key Sleep(100) If _IsPressed("A0", $hDLL) Then ; A0 Left SHIFT key While _IsPressed("A1", $hDLL) Sleep(100) WEnd $iShift += 1 EndIf If $iShift = 2 Then NewCapture() ExitLoop EndIf WEnd WEnd ;************************************************ ;---------------------------------------------------------------------------------------- Func NewCapture() ; NewCapture Local $aRecPos[4], $aMPos[2], $tPos ;, $aTipPos[4], $iX, $iY Local $iDeskWidth, $iDeskHeight, $iDeskLeft, $iDeskTop Local $sDevice, $hMonitor, $sCurDevice, $aData, $Status = 0 ; make Capture gui $hGUICapture = GUICreate("Capture_gui", 1, 1, 1, 1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetBkColor("0xFFFF00", $hGUICapture) ; $COLOR_YELLOW WinSetTrans($hGUICapture, "", 50) ; make mouse block gui $block_gui = GUICreate("block_gui", 1, 1, 1, 1, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) WinSetTrans($block_gui, "", 1) GUISetState(@SW_SHOW, $block_gui) GUISetCursor($MCID_CROSS, 1, $block_gui) Sleep(200) Local $iMaxLoop = 1200, $iCntLoop = 0 While Sleep(10) $iCntLoop += 1 If $iCntLoop = $iMaxLoop Then ExitLoop ; get mouse coordinates $tPos = _WinAPI_GetMousePos() $aMPos[0] = DllStructGetData($tPos, 1) $aMPos[1] = DllStructGetData($tPos, 2) ; get $hMonitor from previously defined Mouse coordinates $hMonitor = _WinAPI_MonitorFromPoint($tPos) ; get monitor $aData appropriate for previously defined coordinates $aData = _WinAPI_GetMonitorInfo($hMonitor) If Not @error Then $sDevice = $aData[3] $iDeskLeft = DllStructGetData($aData[0], 1) $iDeskTop = DllStructGetData($aData[0], 2) $iDeskWidth = DllStructGetData($aData[0], 3) $iDeskHeight = DllStructGetData($aData[0], 4) EndIf ;move the $block_gui to active monitor If $sCurDevice <> $sDevice Then $sCurDevice = $sDevice ;ConsoleWrite("- $sCurDevice=" & $sCurDevice & @CRLF) WinMove($block_gui, "", $iDeskLeft, $iDeskTop, $iDeskWidth, $iDeskHeight) EndIf ; whait Left_mouse_button _IsPressed If _IsPressed("01", $hDLL) Then $Status = 1 $aMPos = MouseGetPos() $aRecPos[0] = $aMPos[0] $aRecPos[1] = $aMPos[1] ; Wait until key is released. While _IsPressed("01", $hDLL) Sleep(50) $aMPos = MouseGetPos() $aRecPos[2] = $aMPos[0] $aRecPos[3] = $aMPos[1] ; show Capture gui GUISetState(@SW_SHOW, $hGUICapture) WinMove($hGUICapture, "", $aRecPos[0], $aRecPos[1], $aRecPos[2] - $aRecPos[0], $aRecPos[3] - $aRecPos[1]) WEnd ElseIf _IsPressed("1B", $hDLL) Then ;1B=ESC key - emergency exit GUIDelete($hGUICapture) GUIDelete($block_gui) Return SetError(1, 1, 0) EndIf If $Status = 1 Then ExitLoop WEnd GUIDelete($hGUICapture) GUIDelete($block_gui) ;ConsoleWrite($aRecPos[0] & ";" & $aRecPos[1] & ";" & $aRecPos[2] - $aRecPos[0] & ";" & $aRecPos[3] - $aRecPos[1] & @CRLF) ; if bigger from 9*9 px then create note If ($aRecPos[2] - $aRecPos[0]) > 9 And ($aRecPos[3] - $aRecPos[1]) > 9 Then CreateNew_NoteGui($aRecPos) ; create new note ;Return $FilePath EndFunc ;==>NewCapture ;---------------------------------------------------------------------------------------- Func CreateNew_NoteGui($aRecPos) ; create new note gui Local $n, $aSize[2] ReDim $NoteGui[UBound($NoteGui) + 1][14] $NoteGui[0][0] += 1 $n = $NoteGui[0][0] $aSize[0] = $aRecPos[2] - $aRecPos[0] ; width $aSize[1] = $aRecPos[3] - $aRecPos[1] ; height ; create note GUI $NoteGui[$n][0] = GUICreate($NoteGui[$n][1], $aSize[0], $aSize[1], $aRecPos[0], $aRecPos[1], $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetOnEvent($GUI_EVENT_RESIZED, "GUI_EVENT", $NoteGui[$n][0]) ; jpg Path for _ScreenCapture_Capture $NoteGui[$n][1] = @ScriptDir & "\tmp\image_" & $NoteGui[$n][0] & ".jpg" _ScreenCapture_Capture($NoteGui[$n][1], $aRecPos[0], $aRecPos[1], $aRecPos[2], $aRecPos[3]) ; save the Gui_Size $NoteGui[$n][2] = $aSize ; set jpg Path as GUI title WinSetTitle($NoteGui[$n][0], "", $NoteGui[$n][1]) ; Creates a Picture control $NoteGui[$n][3] = GUICtrlCreatePic($NoteGui[$n][1], 0, 0, 0, 0, -1, $GUI_WS_EX_PARENTDRAG) ; Creates a Label control just for $SS_GRAYFRAME GUICtrlCreateLabel("", 0, 0, $aSize[0], $aSize[1], $SS_GRAYFRAME) ; Creates a context menu $NoteGui[$n][4] = GUICtrlCreateContextMenu($NoteGui[$n][3]) ; MenuItem for the context menu "Copy to Clipboard" $NoteGui[$n][5] = GUICtrlCreateMenuItem("Copy to Clipboard" & @TAB & "ENTER", $NoteGui[$n][4]) GUICtrlSetOnEvent(-1, "cm_CopyToClipboard") ; MenuItem for the context menu "ID_cMenuShareX" $NoteGui[$n][6] = GUICtrlCreateMenuItem("Send to ShareX", $NoteGui[$n][4]) GUICtrlSetOnEvent(-1, "cm_ShareX") ; MenuItem for the context menu "Save as..." $NoteGui[$n][7] = GUICtrlCreateMenuItem("Save as...", $NoteGui[$n][4]) GUICtrlSetOnEvent(-1, "cm_SaveAs") ; MenuItem for the context menu "Open" $NoteGui[$n][8] = GUICtrlCreateMenuItem("Open", $NoteGui[$n][4]) GUICtrlSetOnEvent(-1, "cm_Open") ; separator GUICtrlCreateMenuItem("", $NoteGui[$n][4]) ; MenuItem for the context menu "OCR - eng" $NoteGui[$n][9] = GUICtrlCreateMenuItem("OCR - eng", $NoteGui[$n][4]) GUICtrlSetOnEvent(-1, "cm_OCR_Eng") ; MenuItem for the context menu "OCR - eng+ell" $NoteGui[$n][10] = GUICtrlCreateMenuItem("OCR - eng+ell", $NoteGui[$n][4]) GUICtrlSetOnEvent(-1, "cm_OCR_EngEll") ; separator GUICtrlCreateMenuItem("", $NoteGui[$n][4]) ; MenuItem for the context menu "Close" $NoteGui[$n][11] = GUICtrlCreateMenuItem("Close" & @TAB & "DELETE" , $NoteGui[$n][4]) GUICtrlSetOnEvent(-1, "cm_Close") ; Display the GUI. GUISetState(@SW_SHOW, $NoteGui[$n][0]) $NoteGui[$n][12] = GUICtrlCreateDummy() $NoteGui[$n][13] = GUICtrlCreateDummy() Local $aAccelKeys[2][2] = [ ["{DELETE}", $NoteGui[$n][12] ], ["{ENTER}", $NoteGui[$n][13] ] ] GUISetAccelerators($aAccelKeys) GUICtrlSetOnEvent($NoteGui[$n][12], "cm_Close") GUICtrlSetOnEvent($NoteGui[$n][13], "cm_CopyToClipboard") Return $NoteGui[$n][0] EndFunc ;==>CreateNew_NoteGui ;---------------------------------------------------------------------------------------- Func SaveFileDlg($Active_title) ; Save file Dialog ; Create a constant variable in Local scope of the message to display in FileSaveDialog. Local Const $sMessage = "Choose a filename." ; Display a save dialog to select a file. Local $sFileSaveDialog = FileSaveDialog($sMessage, @ScriptDir & "\SET\", "image (*.jpg)", $FD_PATHMUSTEXIST) If @error Then ; Display the error message. MsgBox($MB_SYSTEMMODAL, "", "No file was saved.") Else ; Retrieve the filename from the filepath e.g. Example.jpg Local $sFileName = StringTrimLeft($sFileSaveDialog, StringInStr($sFileSaveDialog, "\", $STR_NOCASESENSEBASIC, -1)) ; Check if the extension .jpg is appended to the end of the filename. Local $iExtension = StringInStr($sFileName, ".", $STR_NOCASESENSEBASIC) ; If a period (dot) is found then check whether or not the extension is equal to .jpg If $iExtension Then ; If the extension isn't equal to .jpg then append to the end of the filepath. If Not (StringTrimLeft($sFileName, $iExtension - 1) = ".jpg") Then $sFileSaveDialog &= ".jpg" Else ; If no period (dot) was found then append to the end of the file. $sFileSaveDialog &= ".jpg" EndIf ; Display the saved file. ;ConsoleWrite("You saved the following file:" & @CRLF & $sFileSaveDialog & @CRLF) FileCopy($Active_title, $sFileSaveDialog, $FC_OVERWRITE + $FC_CREATEPATH) EndIf EndFunc ;==>SaveFileDlg ;---------------------------------------------------------------------------------------- Func NoteGui_Delete($hWnd) ; NoteGui_Delete For $i = 1 To $NoteGui[0][0] If $NoteGui[$i][0] = $hWnd Then _ArrayDelete($NoteGui, $i) $NoteGui[0][0] -= 1 ExitLoop EndIf Next EndFunc ;==>NoteGui_Delete ;---------------------------------------------------------------------------------------- Func PicToClip($Path) ; put image to clipboard (Thanks to @Nine) _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($Path) Local $hBitmap1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _GDIPlus_ImageDispose($hImage) Local $hBitmap2 = _WinAPI_CopyImage($hBitmap1, $IMAGE_BITMAP, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG) _WinAPI_DeleteObject($hBitmap1) _GDIPlus_Shutdown() _ClipBoard_Open(0) _ClipBoard_Empty() _ClipBoard_SetDataEx($hBitmap2, $CF_BITMAP) _ClipBoard_Close() _WinAPI_DeleteObject($hBitmap2) EndFunc ;==>PicToClip ;---------------------------------------------------------------------------------------- Func TesseracOCR($ImagePath, $lang) ; perform ocr (Thanks to @JohnOne) ;~ ; $lang = more LangCode -> https://tesseract-ocr.github.io/tessdoc/Data-Files-in-different-versions.html ;~ ; more info at -> https://tesseract-ocr.github.io/tessdoc/Command-Line-Usage.html#simplest-invocation-to-ocr-an-image ;~ ; Of course you will have to install it first. -> https://github.com/UB-Mannheim/tesseract/wiki ;~ ; I tried it in Windows 10 with the version -> https://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-w32-setup-v5.3.0.20221214.exe Local $ResultTextPath, $OutPutPath, $Result ;C:\Program Files (x86)\Tesseract-OCR\tesseract.exe Local Const $TesseractExePath = @ProgramFilesDir & "\Tesseract-OCR\tesseract.exe" ; ℹ️ Give your path * <- $ResultTextPath = @ScriptDir & "\tmp\Result" $OutPutPath = $ResultTextPath & ".txt" ShellExecuteWait($TesseractExePath, '"' & $ImagePath & '" "' & $ResultTextPath & '" -l ' & $lang & ' --psm 6', "", "", @SW_HIDE) ;ConsoleWrite($TesseractExePath & ' "' & $ImagePath & '" "' & $ResultTextPath & '" -l ' & $lang & ' --psm 6' & @CRLF) If @error Then Exit MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONERROR, "Error", @error) EndIf $Result = FileRead($OutPutPath) ;Remove last @LF Local $LastG = StringRight($Result, 1) If $LastG = @LF Then $Result = StringTrimRight($Result, 1) Local $Msg = @CRLF & @CRLF & _StringRepeat(@TAB, 4) & "Copy to ClipBoard ?" Local $iMsgBoxAnswer = MsgBox(4, "OCR Result", $Result & $Msg) If $iMsgBoxAnswer = 6 Then ;Yes ClipPut($Result) ToolTip("The text was copied to the clipboard") Sleep(1000) ToolTip("") EndIf FileDelete($OutPutPath) EndFunc ;==>TesseracOCR ;---------------------------------------------------------------------------------------- Func TRAY_EVENT() ; TRAY_Event Switch @TRAY_ID ; Check the last tray item identifier. Case $TRAY_EVENT_PRIMARYDOUBLE, $TRAY_NewCapture NewCapture() Case $TRAY_ExitScript DllClose($hDLL) Exit EndSwitch EndFunc ;==>TRAY_EVENT ;---------------------------------------------------------------------------------------- Func GUI_EVENT() ; GUI_EVENT Select Case @GUI_CtrlId = $GUI_EVENT_RESIZED Local $aSize For $i = 1 To $NoteGui[0][0] If $NoteGui[$i][0] = @GUI_WinHandle Then $aSize = $NoteGui[$i][2] WinMove(@GUI_WinHandle, "", Default, Default, $aSize[0], $aSize[1]) ControlMove(@GUI_WinHandle, "", "Static1", 0, 0, $aSize[0], $aSize[1]) ControlMove(@GUI_WinHandle, "", "Static2", 0, 0, $aSize[0], $aSize[1]) ExitLoop EndIf Next EndSelect EndFunc ;==>GUI_EVENT ;---------------------------------------------------------------------------------------- Func cm_CopyToClipboard() ; ContextMenu "Copy to Clipboard" Local $Active_title = WinGetTitle(@GUI_WinHandle) ToolTip("Copied to clipboard") PicToClip($Active_title) Sleep(500) ToolTip("") EndFunc ;==>cm_CopyToClipboard ;---------------------------------------------------------------------------------------- Func cm_ShareX() ; ContextMenu "Send to ShareX"" Local $Active_title = WinGetTitle(@GUI_WinHandle) PicToClip($Active_title) Sleep(100) Local $strLen = StringLen(@ScriptDir & "\tmp\image_") If StringLeft($Active_title, $strLen) = @ScriptDir & "\tmp\image_" Then GUIDelete(@GUI_WinHandle) FileDelete($Active_title) NoteGui_Delete(@GUI_WinHandle) EndIf ShellExecute("C:\Program Files\ShareX\ShareX.exe", "-imageeditor ") ; ℹ️ Give your path * <- Local $hShareXImageEd = WinWait("[TITLE:ShareX - Image editor; REGEXPCLASS:WindowsForms10\.Window\..\.app\.0\..+_r\d+_ad1]", "", 2) While WinExists($hShareXImageEd) ControlClick($hShareXImageEd, "", "[NAME:btnLoadImageFromClipboard]") Sleep(300) WEnd $hShareXImageEd = WinWait("[TITLE:ShareX - Image editor; REGEXPCLASS:WindowsForms10\.Window\..\.app\.0\..+_r\d+_ad1]", "", 2) WinActivate($hShareXImageEd) WinSetState($hShareXImageEd, "", @SW_MAXIMIZE) EndFunc ;==>cm_ShareX ;---------------------------------------------------------------------------------------- Func cm_SaveAs() ; ContextMenu "Save as..." Local $Active_title = WinGetTitle(@GUI_WinHandle) SaveFileDlg($Active_title) EndFunc ;==>cm_SaveAs ;---------------------------------------------------------------------------------------- Func cm_Open() ; ContextMenu "Open" Local $Active_title = WinGetTitle(@GUI_WinHandle) ShellExecute($Active_title) EndFunc ;==>cm_Open ;---------------------------------------------------------------------------------------- Func cm_OCR_Eng() ; ContextMenu "OCR - eng" Local $Active_title = WinGetTitle(@GUI_WinHandle) TesseracOCR($Active_title, "eng") EndFunc ;==>cm_OCR_Eng ;---------------------------------------------------------------------------------------- Func cm_OCR_EngEll() ; ContextMenu "OCR - eng+ell" Local $Active_title = WinGetTitle(@GUI_WinHandle) TesseracOCR($Active_title, "eng+ell") EndFunc ;==>cm_OCR_EngEll ;---------------------------------------------------------------------------------------- Func cm_Close() ; ContextMenu "Close" Local $Active_title = WinGetTitle(@GUI_WinHandle) Local $strLen = StringLen(@ScriptDir & "\tmp\image_") If StringLeft($Active_title, $strLen) = @ScriptDir & "\tmp\image_" Then GUIDelete(@GUI_WinHandle) FileDelete($Active_title) NoteGui_Delete(@GUI_WinHandle) ;ConsoleWrite("- WinClose " & @GUI_WinHandle & " & FileDelete " & $Active_title & @CRLF) EndIf EndFunc ;==>cm_Close ;---------------------------------------------------------------------------------------- Func _Array_Gui_display() ; *** Debug _ArrayDisplay($NoteGui) _ArrayDisplay($NoteGui, "$NoteGui") EndFunc ;==>NoteGui_display ;---------------------------------------------------------------------------------------- Please, every comment is appreciated! leave your comments and experiences here! Thank you very much1 point -
AutoIt3.exe ended.rc:-1073741819 with my Own Dll
NoNameCode reacted to Werty for a topic
cdecl maybe?1 point -
I meant something like this here (proof of concept): #include <GDIPlus.au3> Global Const $CELL_SIZE = 30 Global Const $GRID_PADDING = 5 Global Const $MIN_CIRCLE_RADIUS = 5 Global Const $MAX_CIRCLE_RADIUS = 10 Global $START = TimerInit() Func DrawCircles($hGraphics,$GRID_SIZE) Local $hBrush = _GDIPlus_BrushCreateSolid(0xFFFF5050) For $i = 0 To $GRID_SIZE - 1 For $j = 0 To $GRID_SIZE - 1 Local $iRadius = Random($MIN_CIRCLE_RADIUS, $MAX_CIRCLE_RADIUS, 1) Local $iCenterX = $GRID_PADDING * 1.5 + $j * ($CELL_SIZE + $GRID_PADDING) + $CELL_SIZE / 2 Local $iCenterY = $GRID_PADDING * 1.5 + $i * ($CELL_SIZE + $GRID_PADDING) + $CELL_SIZE / 2 _GDIPlus_GraphicsFillEllipse($hGraphics, $iCenterX - $iRadius, $iCenterY - $iRadius, $iRadius * 2, $iRadius * 2, $hBrush) Next Next _GDIPlus_BrushDispose($hBrush) EndFunc ;==>DrawCircles Func DrawGrid($hGraphics,$GRID_SIZE) Local $hPen = _GDIPlus_PenCreate(0xFF000000, 1) For $i = 0 To $GRID_SIZE Local $iX = $i * ($CELL_SIZE + $GRID_PADDING) _GDIPlus_GraphicsDrawLine($hGraphics, $GRID_PADDING, $GRID_PADDING + $iX, $GRID_PADDING + $GRID_SIZE * ($CELL_SIZE + $GRID_PADDING), $GRID_PADDING + $iX, $hPen) _GDIPlus_GraphicsDrawLine($hGraphics, $GRID_PADDING + $iX, $GRID_PADDING, $GRID_PADDING + $iX, $GRID_PADDING + $GRID_SIZE * ($CELL_SIZE + $GRID_PADDING), $hPen) Next _GDIPlus_PenDispose($hPen) EndFunc ;==>DrawGrid Func DrawGridToBitmap($GRID_SIZE) $aWS = ProcessGetStats() Local $pb = Round($aWS[1]/1024/1024) _GDIPlus_Startup() Local $iW = $GRID_SIZE * ($CELL_SIZE + $GRID_PADDING) + 2*$GRID_PADDING + 1, $iH = $GRID_SIZE * ($CELL_SIZE + $GRID_PADDING) + 2*$GRID_PADDING + 1 ;~ ConsoleWrite($iW & " x " & $iH & @CRLF) Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hBmpCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) _GDIPlus_GraphicsClear($hBmpCtxt, 0xFFFFFFFF) If $GRID_SIZE > 10 Then Local $iW2 = 10 * ($CELL_SIZE + $GRID_PADDING) + 2*$GRID_PADDING - 1, $iH2 = 10 * ($CELL_SIZE + $GRID_PADDING) + 2*$GRID_PADDING - 1 Local $hBitmap2 = _GDIPlus_BitmapCreateFromScan0($iW2, $iH2), $hBmpCtxt2 = _GDIPlus_ImageGetGraphicsContext($hBitmap2) _GDIPlus_GraphicsClear($hBmpCtxt2, 0xFFFFFFFF) _GDIPlus_GraphicsSetSmoothingMode($hBmpCtxt2, $GDIP_SMOOTHINGMODE_HIGHQUALITY) DrawGrid($hBmpCtxt2,10) DrawCircles($hBmpCtxt2,10) Local $hTexture = _GDIPlus_TextureCreate2($hBitmap2, 5, 5, $iW2 - 9, $iH2 - 9) DllCall($__g_hGDIPDll, "int", "GdipTranslateTextureTransform", "handle", $hTexture, "float", 5, "float", 5, "int", 0) _GDIPlus_GraphicsFillRect($hBmpCtxt, 5, 5, $iW - 11, $iH - 11, $hTexture) _GDIPlus_GraphicsDispose($hBmpCtxt2) _GDIPlus_BitmapDispose($hBitmap2) _GDIPlus_BrushDispose($hTexture) Else DrawGrid($hBmpCtxt,$GRID_SIZE) DrawCircles($hBmpCtxt,$GRID_SIZE) EndIf Local $sFilePath = @ScriptDir & "\grid" & $GRID_SIZE & ".png" _GDIPlus_ImageSaveToFile($hBitmap, $sFilePath) _GDIPlus_GraphicsDispose($hBmpCtxt) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() $aWS = ProcessGetStats() Local $pa = Round($aWS[1]/1024/1024) ConsoleWrite("Runtime: " & Round(TimerDiff($START)/1000) & " seconds.Memory peaks " & $pb & " -> " & $pa & " MB" & @LF) $START = TimerInit() Return $sFilePath EndFunc ;==>DrawGridToBitmap ConsoleWrite("Grid 10 - image created " & DrawGridToBitmap(10) & @LF) ConsoleWrite("Grid 100 - Image created " & DrawGridToBitmap(100) & @LF) ConsoleWrite("Grid 250 - Image created " & DrawGridToBitmap(250) & @LF) ConsoleWrite("Grid 450 - Image created " & DrawGridToBitmap(450) & @LF) ConsoleWrite("Grid 500 - Image created " & DrawGridToBitmap(500) & @LF) ConsoleWrite("Grid 1000 - Image created " & DrawGridToBitmap(1000) & @LF)1 point
-
Dropdown to fill Text to imput field after choosing the dropdown.
Crashrider reacted to Nine for a topic
Use this instead in WM_COMMAND as per MSDN: If _WinAPI_LoWord($wParam) = $cComboBox And _WinAPI_HiWord($wParam) = $CBN_SELCHANGE Then and also use this instead to get rid of count : GUICtrlSetData($cComboBox, "|" & _ArrayToString($aSections, "|", 1))1 point -
_GUICtrlStatusBar_Resize_Equidistant()
taurus905 reacted to argumentum for a topic
..in the words of @Andreik: "nah, you do it". So I posted #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <WindowsConstants.au3> Global $g_hStatus, $g_aParts Example() Func Example() ; Create GUI Local $hGUI = GUICreate("StatusBar Resize Equidistant (v" & @AutoItVersion & ")", 400, 300, -1, -1, $WS_OVERLAPPEDWINDOW) ; Set parts $g_hStatus = _GUICtrlStatusBar_Create($hGUI) Dim $g_aParts[3] ; = [75, 150, -1] ; it no longer matters _GUICtrlStatusBar_SetParts($g_hStatus, $g_aParts) _GUICtrlStatusBar_SetText($g_hStatus, "Part 0") _GUICtrlStatusBar_SetText($g_hStatus, "Part 1", 1) _GUICtrlStatusBar_SetText($g_hStatus, "Part 2", 2) _GUICtrlStatusBar_Resize_Equidistant($g_hStatus, $g_aParts, $hGUI) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_SIZE, "WM_SIZE") ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example ; Resize the status bar when GUI size changes Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam _GUICtrlStatusBar_Resize_Equidistant($g_hStatus, $g_aParts, $hWnd) If @error Then _GUICtrlStatusBar_Resize($g_hStatus) Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE Func _GUICtrlStatusBar_Resize_Equidistant($hStatus, ByRef $aParts, $hGUI) Local $aPos = WinGetPos($hGUI) If @error Then Return SetError(1, 0, 0) Local $iSize = Int(($aPos[2] - 24) / UBound($aParts)) Local $aTemp[UBound($aParts)] ; the "- 24" makes it look more even For $n = 0 To UBound($aParts) - 2 $aTemp[$n] = $iSize * ($n + 1) Next $aTemp[$n] = -1 $aParts = $aTemp ; in case of WinGetPos() error. _GUICtrlStatusBar_SetParts($g_hStatus, $aTemp) EndFunc ;==>_GUICtrlStatusBar_Resize_Equidistant Same as resize but proportional/equidistant.1 point