Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/12/2020 in all areas

  1. Nine

    ListBox events

    That seems to work quite well : #include <GuiListBox.au3> #include <WinAPI.au3> #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> Global $idCombo, $idComboUnit, $idList, $idListUnit Global $sComboInitUnit = "pJ", $fComboVal = 7.5 Global $sListInitUnit = "nF", $fListVal = 0.15 Units_Conversion_Example() Func Units_Conversion_Example() ; Create GUI Global $hGUI = GUICreate("Units Conversion", 400, 296) $idCombo = GUICtrlCreateInput($fComboVal, 22, 20, 91, 26) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idComboUnit = GUICtrlCreateCombo("", 112, 20, 50, 30) GUICtrlSetData(-1, "uJ|nJ|pJ", $sComboInitUnit) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idList = GUICtrlCreateInput($fListVal, 22, 80, 91, 26) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") $idListUnit = GUICtrlCreateList("", 112, 80, 57, 26, BitOR($LBS_NOTIFY, $LBS_NOSEL, $WS_VSCROLL)) GUICtrlSetData(-1, "uF|nF|pF", $sListInitUnit) GUICtrlSetFont(-1, 13, 400, 0, "MS Reference Sans Serif") Global $hCtrl = GUICtrlGetHandle($idListUnit) Global $iDummy = GUICtrlCreateDummy() GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") Local $hProc = DllCallbackRegister(WM_LIST_BOX, "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr") Local $hProcPtr = DllCallbackGetPtr($hProc) DllCall("comctl32.dll", "bool", "SetWindowSubclass", "hwnd", $hCtrl, "ptr", $hProcPtr, "uint_ptr", 0xBEEF, "dword_ptr", 0) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $iDummy ;ControlFocus ($hGUI, "", $hCtrl) ControlClick($hGUI, "", $idListUnit) EndSwitch WEnd GUIDelete() DllCall("comctl32.dll", "bool", "RemoveWindowSubclass", "hwnd", $hCtrl, "ptr", $hProcPtr, "uint_ptr", $WM_VSCROLL) DllCallbackFree($hProc) EndFunc ;==>Units_Conversion_Example Func WM_LIST_BOX($hWnd, $iMsg, $wParam, $lParam, $uIdSubClass, $IRefData) #forceref $hWnd, $iMsg, $wParam, $lParam, $uIdSubClass, $IRefData Local $iDirection Switch $iMsg Case $WM_VSCROLL $iDirection = _WinAPI_LoWord ($wParam) If $iDirection = 0 Or $iDirection = 1 Then GUICtrlSendToDummy ($iDummy) Case $WM_MOUSEWHEEL $iDirection = _WinAPI_HiWord ($wParam) GUICtrlSendToDummy ($iDummy) EndSwitch Return DllCall("comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)[0] EndFunc Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo, $hWndListBox If Not IsHWnd($idComboUnit) Then $hWndCombo = GUICtrlGetHandle($idComboUnit) If Not IsHWnd($idListUnit) Then $hWndListBox = GUICtrlGetHandle($idListUnit) $hWndFrom = $lParam $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case $hWndCombo Switch $iCode Case $CBN_SELCHANGE ConsoleWrite(GUICtrlRead($idComboUnit) & @CRLF) EndSwitch Case $hWndListBox Switch $iCode Case $LBN_SELCHANGE ConsoleWrite(GUICtrlRead($idListUnit) & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND
    2 points
  2. I'm working on a project right now for another department at work and I'm not in IT so I don't have great remote access to their computers. I'm trying to get a finicky internal website to be automated with some financial data, but Finance needs to be running the script since they have access to the non-testing site. Currently, the amazing WebDriver UDF uses ConsoleWrite to output debugging data, which works great on my computer. Finance isn't tech savy and would really like a one-file solution. I need to be able to capture this output and email it back to myself in the case of an error (which happens a lot). This code can be inserted to the beginning of my script to allow me to run my script from the exe, capture the output, and (with another function) email the results back to myself. In case anyone is interested, it's kind of a neat way to do things, I thought ; Required for using /AutoIt3ExecuteScript on another AutoIt3 Script #pragma compile(AutoItExecuteAllowed, True) ; Run Au3Stripper #AutoIt3Wrapper_Run_Au3Stripper=y ; Merge only, just add in all required constants and functions #Au3Stripper_Parameters=/mo #include <AutoItConstants.au3> ParentOnlyCode() Main() Func ParentOnlyCode() ; The parent is compiled. Skip this if not compiled. If Not @Compiled Then Return ; The child is named exactly like the source code (ScriptName.au3) Local $sAu3File = StringReplace(@ScriptFullPath, ".exe", ".au3") ; File Install the source code to the current directory FileInstall(@ScriptFullPath, $sAu3File) ; The command to execute Local $sCmd = '"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sAu3File & '"' ; Run the command and capture the Console output Local $iPID = Run($sCmd, "", @SW_HIDE, $STDERR_MERGED) If @error Then ; Do something here in case of a Run error Exit MsgBox(0, "", "Run Error: " & @error) EndIf ; Wait for the script to close ProcessWaitClose($iPID) ; Capture the exit code Local $iExitCode = @extended ; Read the Console output Local $sText = StdoutRead($iPID) $sText &= @CRLF & @CRLF & "Exit code: " & $iExitCode ; Write it to a file FileWrite(@ScriptDir & "\output.txt", $sText) ; Optionally, delete the Au3 file here FileDelete($sAu3File) ; Done. Don't execute the Main script. Exit EndFunc Func Main() ; This text would normally be lost in a Compiled script, it will be written to output.txt ConsoleWrite("Doing Main stuff" & @CRLF) EndFunc
    1 point
  3. RAMzor

    ListBox events

    The issue that the value in ListBox can be changed without control is focused - only mouse pointer hovers over a ListBox and mouse wheel will change the value. Even arrows up and down not really change a value (only move it). This is very useful option but very "danger" because the value visually changed without really be accepted. Hope I made my self clear because my English is lame 🤪 @Zedna Thanks a lot but it still not worked as you said...
    1 point
  4. You're welcome, and it certainly has; I cannot thank you enough. I am certainly interested in learning more about this program and I look forward to being able to use this to further automate the entire process of my text entry. This will be fun!
    1 point
  5. Please use this tool when you post code. You can do a silent install of Notepad++ by using /S. See other switches for a complete run command.
    1 point
  6. LAST VERSION - 1.0 19-May-12 I think many of you would like to perform some action (for example, to call the dialog box) when a user clicks on the tray tip. Here is a simple way to do it. Unfortunately, without .dll do not seem possible. Note, only AutoIt window can be registered as a source window, see example. AITray.dll (x86 and x64) Previous downloads: 74 AITray.zip Example #Include <WindowsConstants.au3> Opt('TrayAutoPause', 0) Opt('WinTitleMatchMode', 3) Opt('WinWaitDelay', 0) Global Const $NIN_BALLOONSHOW = $WM_USER + 2 Global Const $NIN_BALLOONHIDE = $WM_USER + 3 Global Const $NIN_BALLOONUSERCLICK = $WM_USER + 5 Global Const $NIN_BALLOONTIMEOUT = $WM_USER + 4 $hForm = GUICreate('') If @AutoItX64 Then $hDll = DllOpen(@ScriptDir & '\AITray_x64.dll') Else $hDll = DllOpen(@ScriptDir & '\AITray.dll') EndIf If $hDll <> -1 Then $Ret = DllCall($hDll, 'int', 'AISetTrayRedirection', 'hwnd', WinGetHandle(AutoItWinGetTitle()), 'hwnd', $hForm) If (@Error) Or (Not $Ret[0]) Then DllClose($hDll) Exit EndIf Else Exit EndIf GUIRegisterMsg($WM_USER + 1, 'WM_TRAYNOTIFY') TrayTip('Tip', 'This is a tray tip, click here.', 10, 1) While 1 Sleep(1000) WEnd DllCall($hDll, 'int', 'AIRemoveTrayRedirection') DllClose($hDll) Func WM_TRAYNOTIFY($hWnd, $iMsg, $wParam, $lParam) Switch $hWnd Case $hForm Switch $lParam Case $NIN_BALLOONSHOW ConsoleWrite('Balloon tip show.' & @CR) Case $NIN_BALLOONHIDE ConsoleWrite('Balloon tip hide.' & @CR) Case $NIN_BALLOONUSERCLICK ConsoleWrite('Balloon tip click.' & @CR) Case $NIN_BALLOONTIMEOUT ConsoleWrite('Balloon tip close.' & @CR) EndSwitch EndSwitch EndFunc ;==>WM_TRAYNOTIFY
    1 point
  7. This should work. $string = "I:\test\\xxx\jjj\\\kkk\k.jpg" $string=StringRegExpReplace($string,"\\{2,}","\\") ConsoleWrite($string & @CRLF) Saludos
    1 point
  8. Hi. I'm not sure if you really mean remove or mean replace woth only one "\". I guess second. So here is my try with StringRegExpReplace(): Local $string = "I:\test\\xxx\jjj\\\kkk\k.jpg" $string = StringRegExpReplace($string, "\\+", "\\") ConsoleWrite($string & @CRLF) Explanation: searchstring - \\+ - first \ is only masking second\ (otherwise it has another function) and + means one till all \ Replace it with \\. Here the first \ is masking the second \ again. Conrad
    1 point
  9. Well I dunno, but I guess we could give you this. Fist step is: learn to always check the helpfile when you have a question. The helpfile explains this on the GUICtrlSetColor() page. And if you're wondering how to disable theming:
    1 point
  10. Melba23

    Getting image size

    Steveiwonder, This code works for me: $sPassed_File_Name = "Fred.PNG" Local $sDir_Name = StringRegExpReplace($sPassed_File_Name, "(^.*\\)(.*)", "\1") Local $sFile_Name = StringRegExpReplace($sPassed_File_Name, "^.*\\", "") Local $sDOS_Dir = FileGetShortName($sDir_Name, 1) Local $oShellApp = ObjCreate("shell.application") If IsObj($oShellApp) Then Local $oDir = $oShellApp.NameSpace($sDOS_Dir) If IsObj($oDir) Then Local $oFile = $oDir.Parsename($sFile_Name) If IsObj($oFile) Then ConsoleWrite($oDir.GetDetailsOf($oFile, 31) & @CRLF) Else $iError = 3 EndIf Else $iError = 2 EndIf Else $iError = 1 EndIfIt gives me ?567 x 282? as an output - needs a bit of formatting, but it is correct. The value 31 should work in Vista and Win 7 - in XP use 26. I hope this helps. M23
    1 point
  11. Mat

    Getting image size

    #Include <GDIPlus.au3> _GDIPlus_Startup () Local $hImage = _GDIPlus_ImageLoadFromFile("C:\Users\Steveiwonder\Pictures\Untitled.png") If @error Then MsgBox(16, "Error", "Does the file exist?") Exit 1 EndIf ConsoleWrite(_GDIPlus_ImageGetWidth($hImage) & @CRLF) ConsoleWrite(_GDIPlus_ImageGetHeight($hImage) & @CRLF) _GDIPlus_ImageDispose ($hImage) _GDIPlus_ShutDown ()
    1 point
  12. n3ne you need to subclass the hidden parent window 'AutoIt v3' to get the custom WM_USER+1 callback message registered with the Notification Area toolbar for tray icon events. you want the NIN_BALLOONUSERCLICK and NIN_BALLOONTIMEOUT notifications (NIN_BALLOONTIMEOUT also sent if traytip close icon clicked). the drawback is subclassing... the SetWindowLong call can occasionally fails to subclass the AutoIt v3 hidden window. on one slow machine (old 1.4gig Athlon running XP) SetWindowLong will occasionally give 'Access is denied.' error. on my faster machines (2.2G Athlon, 2.6G P4) I can't get it to error at all, even running multiple instances. (multiple instances to check that subclassing worked for every instance) YMMV so test away see example script notes *** I see there is a problem with the traytip not appearing again when an instance sets a TrayTip when another instance is already displaying a traytip but that would have to be a windows issue. you could also use the messages TTM_ACTIVATE or WM_ACTIVATEAPP = True and WM_LBUTTONUP with Hi/Lo word lparam tooltip coordinates hittest to discriminate between a click on tooltip or close button (using GuiRegisterMsg or subclassing tooltip). but again, more workarounds... an alternative to subclassing the AutoIt v3 gui is to create your own tray icon with Shell_NotifyIconW API, handle the WM_USER+1 callback message with GuiRegisterMsg and check for the NIN_BALLOONUSERCLICK and NIN_BALLOONTIMEOUT notifications. Holgers ModernMenu UDF does this, but like customdrawn/ownerdrawn controls its more work. Cheers Edit: with further testing launching multiple instances I get 1 access denied in 20 to 30 instances on P4 and 3 or 4 access denied in 20 instances on Athlon creating a tray icon with Shell_NotifyIconW is best approach... Edit2: typos Edit3: found problem: example updated with ProgAndys AutoItWinGetHandle function Access denied error caused by using AutoItWinGetTitle with WinGetHandle to retrieve the AutoIt v3 window handle without first editing the title. sometimes you overlook the obvious... Edit4: added Return SetError(0, 0, 1) to _SubclassWin(), another typo ;Author: rover 07/04/09 ;MSDN reference: ;Shell_NotifyIcon Function ;http://msdn.microsoft.com/en-us/library/bb762159(VS.85).aspx #include <GUIConstantsEX.au3> #include <Constants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <StaticConstants.au3> Global Const $NIN_BALLOONTIMEOUT = $WM_USER + 4 Global Const $NIN_BALLOONUSERCLICK = $WM_USER + 5 ;Global Const $GWLP_WNDPROC = -4; for SetWindowLongPtr Global $wProcNew = 0, $wProcOld = 0, $iMsg, $iError = 0 ;get handle to AutoIt v3 hidden gui Global $hGUI1 = _AutoItWinGetHandle() ;$hGUI1 = WinGetHandle(AutoItWinGetTitle()) ;will work without GUICreate but global vars must be set in WndProc instead of GUICtrlCreateDummy/GUICtrlSendToDummy ;NOTE: _WinAPI_SetWindowLong() in WinAPI.au3 consistently returns 'The specified procedure could not be found' error 127 ;error is due to the call being SetWindowLong instead of SetWindowLongW, ;using SetWindowLongW the error message is 'The operation completed successfully. Global $hGUI2 = GUICreate("Traytip click detect", 260, 150, @DesktopWidth - 400, @DesktopHeight - 300) Global $cTooltipClose = GUICtrlCreateDummy() Global $cTooltipClick = GUICtrlCreateDummy() Global $cLabel1 = GUICtrlCreateLabel("Traytip area clicked", 70, 80, 120, 16, $SS_CENTER) Global $cLabel2 = GUICtrlCreateLabel("", 10, 110, 240, 16, $SS_CENTER) GUICtrlSetBkColor(-1, 0xFFFFFF) Global $cButton = GUICtrlCreateButton("Create Traytip", 70, 30, 120, 25) GUISetState() ;subclass AutoIt v3 gui to get tray icon/traytip notifications _SubclassWin($hGUI1, $wProcNew, $wProcOld) Global $sLastError = _WinAPI_GetLastErrorMessage() ConsoleWrite('- GetLastErrorMessage ' & $sLastError & "- Error: " & _WinAPI_GetLastError() & @CRLF) ConsoleWrite('+$wProcOld = ' & $wProcOld & @CRLF) GUICtrlSetData($cLabel2, $sLastError) If StringInStr($sLastError, "Access is denied.") <> 0 Then GUICtrlSetBkColor($cLabel2, 0xFF0000) EndIf While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $cButton TrayTip("Clear", "", 1) TrayTip("I'm a title", "I'm the message", 5, 1) Case $cTooltipClick GUICtrlSetData($cLabel2, "") GUICtrlSetColor($cLabel2, 0x0000FF) Sleep(100) GUICtrlSetData($cLabel2, "Tooltip clicked") ConsoleWrite("!NIN_BALLOONUSERCLICK" & @CRLF) Case $cTooltipClose GUICtrlSetData($cLabel2, "") GUICtrlSetColor($cLabel2, 0xFF0000) Sleep(100) GUICtrlSetData($cLabel2, "Tooltip closed") ConsoleWrite("-NIN_BALLOONTIMEOUT" & @CRLF) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _SubclassWin($hWnd, ByRef $hProcNew, ByRef $hProcOld) If $hProcNew <> 0 Or $hProcOld <> 0 Then Return SetError(1, 0, 0) $hProcNew = DllCallbackRegister("_AutoItWndProc", "int", "hwnd;uint;wparam;lparam") If @error Or $hProcNew = 0 Then Return SetError(2, 0, 0) $hProcOld = DllCall("User32.dll", "int", "SetWindowLongW", "hwnd", _ $hWnd, "int", $GWL_WNDPROC, "ptr", DllCallbackGetPtr($hProcNew)) If @error Or $hProcOld[0] = 0 Then $hProcOld = 0 Return SetError(3, 0, 0) EndIf $hProcOld = $hProcOld[0] Return SetError(0, 0, 1) EndFunc;==>_SubclassWin Func _RestoreWndProc($hWnd, ByRef $hProcNew, ByRef $hProcOld) If $hProcOld <> 0 Then _WinAPI_SetWindowLong($hWnd, $GWL_WNDPROC, $hProcOld) If $hProcNew <> 0 Then DllCallbackFree($hProcNew) $hProcNew = 0 $hProcOld = 0 EndFunc;==>_RestoreWndProc Func OnAutoItExit() _RestoreWndProc($hGUI1, $wProcNew, $wProcOld) EndFunc;==>OnAutoItExit Func _AutoItWndProc($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Switch $iMsg Case $WM_USER + 1;AutoIt callback message value for tray icon (1025), can be retrieved with ReadProcessMemory and TRAYDATA struct Switch $ilParam Case $NIN_BALLOONTIMEOUT; timeout and by tooltip close icon GUICtrlSendToDummy($cTooltipClose) Case $NIN_BALLOONUSERCLICK GUICtrlSendToDummy($cTooltipClick) EndSwitch EndSwitch ; pass the unhandled messages to default WindowProc Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $iMsg, $iwParam, $ilParam) EndFunc;==>_AutoItWndProc ;=============================================================================== ; ; Function Name: _AutoItWinGetHandle ; Description:: Returns the Windowhandle of AutoIT-Window ; Parameter(s): -- ; Requirement(s): -- ; Return Value(s): Autoitwindow Handle ; Author(s): Prog@ndy ; ;=============================================================================== ; Func _AutoItWinGetHandle() Local $oldTitle = AutoItWinGetTitle() Local $x = Random(1248578, 1249780) AutoItWinSetTitle("qwrzu" & $x) Local $x = WinGetHandle("qwrzu" & $x) AutoItWinSetTitle($oldTitle) Return $x EndFunc;==>_AutoItWinGetHandle
    1 point
×
×
  • Create New...