Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/21/2021 in all areas

  1. jchd

    My own Binary() Function

    Make your life simple! Local $n = 53 Local $sBin = _UintToString($n, 2) ConsoleWrite($n & " evaluates as binary " & $sBin & @LF) Func _UintToString($i, $base) Return DllCall("msvcrt.dll", "wstr:cdecl", "_ui64tow", "uint64", $i, "wstr", "", "int", $base)[0] EndFunc ;==>_UintToString You can plug any value to $n and see what it yields.
    3 points
  2. Subz

    Windows 11 and the IE udf

    Microsoft intends to support IE mode until 2029 (we use IE mode within Edge Chromium for some legacy software), have AutoIt code that uses a number of IE functions, including IE embedded and everything appears to be working correctly still.
    2 points
  3. Is there a problem with that notation when using a standalone variable for the index, yes -- which neither of us did. Is there a problem with that notation when using a literal as an index, no. The reported issue seems to be related to using a standalone variable as in index. When using that notation, I have had success with using a literal, an expression, or an enum as an index without any issues. Hopefully the fix allows standalone variables to be used also. If you have more questions, comments, or concerns related to the reported issue, it would probably be best to start a new topic. Example: #include <WinAPIDiag.au3> Enum $THREE = 3, $FOUR Global $i5 = 5, $i6 = 6 $tData = DllStructCreate("ushort value[8]") $tData.value(1) = 1 $tData.value(2) = 2 $tData.value($THREE) = 3 $tData.value($FOUR) = 4 $tData.value($i5) = 5 ;fails $tData.value($i6) = 6 ;fails $tData.value($i5+2) = 7 $tData.value(8) = 8 _WinAPI_DisplayStruct($tData, "ushort value[8]")
    2 points
  4. @TheXman 's answer solves the problem perfectly ( @NewCommer : you should mark it as solution ). Instead of ENUM you could also use ($n+0), but this is probably not the most elegant work-around. Local $n = 1 Local $t = DllStructCreate('int Test[2]') ConsoleWrite("@error = " & @error & @CRLF) $t.Test(1) = 123 $t.Test(2) = 345 MsgBox(0, 0, _ $t.Test(1) & @CRLF & _ $t.Test($n+0) & @CRLF & _ $t.Test($n+1) & @CRLF & _ $t.Test(Number($n)) & @CRLF & _ $t.Test('1'))
    1 point
  5. The post above should answer your question.
    1 point
  6. Just one interesting info: Without my workaround you can avoid dissapearing of RichEdit by setting WS_EX_TOPMOST ExStyle: $Edit = _GUICtrlRichEdit_Create($Main, '', 24, 24, 385, 217, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY), $WS_EX_TOPMOST) But problem with not repainting of vertical scrollbar remains ... (without my workaround) 2) In I firstly tried more simple workaround in Func RichEdit_Refresh()     _WinAPI_InvalidateRect($Edit, 0, False) ; Erase=False but it didn't helped with bad repainting of V scrollbar so I ended up with my more complicated workaround using  _WinAPI_InvalidateRect($Main, $RichEdit_Rect, False) ; Erase=False
    1 point
  7. Here is Rect of Richedit defined as global and determined only once at start: #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <GUIEdit.au3> #include <GuiRichEdit.au3> $Main = GUICreate("Test Edit", 436, 379) $IMGPic = GUICtrlCreatePic(@ScriptDir & '\IMGPic.jpg', 0,0, 436, 379) GUICtrlSetState(-1, 128) $Edit = _GUICtrlRichEdit_Create($Main, '', 24, 24, 385, 217, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY)) $ButtonTest = GUICtrlCreateButton("Test Error", 168, 288, 115, 41) GUISetState(@SW_SHOW) Global $RichEdit_pos = ControlGetPos($Main, '', $Edit) Global $RichEdit_Rect = DllStructCreate($tagRECT) DllStructSetData($RichEdit_Rect, 'Right', $RichEdit_pos[2]+25) ; just test: add width of VScrollBar to area to be invalidating DllStructSetData($RichEdit_Rect, 'Bottom', $RichEdit_pos[3]+25) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $ButtonTest _TestEdit() EndSwitch WEnd Func _TestEdit() _EditSetText(0x000000, 11, 'Time new romans', 'Test11111111') RichEdit_Refresh() EndFunc Func _EditSetText($color, $Editfont, $editfontname, $Edittext, $bkcolor = 0xFFFFFF) _GUICtrlRichEdit_SetSel($Edit, -1, -1) _GUICtrlRichEdit_SetBkColor($Edit, __Color($bkcolor)) _GUICtrlRichEdit_SetCharColor($Edit, __Color($color)) _GUICtrlRichEdit_SetFont($Edit, $Editfont, $editfontname) _GUICtrlRichEdit_AppendText($Edit, $Edittext & @CRLF) _GUICtrlRichEdit_Deselect($Edit) EndFunc Func __Color($iColor) Local $sH = Hex($iColor, 6) Return '0x' & StringRight($sH, 2) & StringMid($sH, 3, 2) & StringLeft($sH, 2) EndFunc ;==>RGB2BGR Func RichEdit_Refresh() _WinAPI_InvalidateRect($Main, $RichEdit_Rect, False) ; Erase=False EndFunc
    1 point
  8. I had a problem with @xrxca's fantastic MultiMon.au3, commented above, with my Windows 10 64-bit configuration. I have four displays, of which only two are the same size. My PC's BIOS displays boot messages on the left monitor, but Windows thinks that it's monitor #2, so I have my Display Settings like the attachment shows ( [2] [1] [3] [4] ). I had to add a few lines to MultiMon.au3 to show the monitors in the correct physical representation, because it was showing Display 2 (primary display) as the 4th hMonitor instead of the 1st. I put an _ArraySort in _GetMonitors() to fix this (at least on my system). I also added a line to the example _ShowMonitorInfo() to provide the hMonitor value(s). See attached "before after" screenshot for the result. #include-Once #include<Array.au3> ;added to fix the display order Global $__MonitorList[1][5] $__MonitorList[0][0] = 0 ; Just for testing ;~ _ArrayDisplay(_GetMonitors()) ;added as another way to see the info _ShowMonitorInfo() ;================================================================================================== ; Function Name: _ShowMonitorInfo() ; Description:: Show the info in $__MonitorList in a msgbox (line 0 is count of monitors and entire Desktop size) ; Parameter(s): n/a ; Return Value(s): n/a ; Author(s): xrxca (autoit@forums.xrx.ca) ;================================================================================================== Func _ShowMonitorInfo() If $__MonitorList[0][0] == 0 Then _GetMonitors() EndIf Local $Msg = "" Local $i = 0 For $i = 0 To $__MonitorList[0][0] $Msg &= $i & " - hnd:" & $__MonitorList[$i][0] ;added for information $Msg &= ", L:" & $__MonitorList[$i][1] & ", T:" & $__MonitorList[$i][2] $Msg &= ", R:" & $__MonitorList[$i][3] & ", B:" & $__MonitorList[$i][4] If $i < $__MonitorList[0][0] Then $Msg &= @CRLF Next MsgBox(0, $__MonitorList[0][0] & " Monitors: ", $Msg) EndFunc ;==>_ShowMonitorInfo ;================================================================================================== ; Function Name: _MaxOnMonitor($Title[, $Text = ''[, $Monitor = -1]]) ; Description:: Maximize a window on a specific monitor (or the monitor the mouse is on) ; Parameter(s): $Title The title of the window to Move/Maximize ; optional: $Text The text of the window to Move/Maximize ; optional: $Monitor The monitor to move to (1..NumMonitors) defaults to monitor mouse is on ; Note: Should probably have specified return/error codes but haven't put them in yet ; Author(s): xrxca (autoit@forums.xrx.ca) ;================================================================================================== Func _MaxOnMonitor($Title, $Text = '', $Monitor = -1) _CenterOnMonitor($Title, $Text, $Monitor) WinSetState($Title, $Text, @SW_MAXIMIZE) EndFunc ;==>_MaxOnMonitor ;================================================================================================== ; Function Name: _CenterOnMonitor($Title[, $Text = ''[, $Monitor = -1]]) ; Description:: Center a window on a specific monitor (or the monitor the mouse is on) ; Parameter(s): $Title The title of the window to Move/Maximize ; optional: $Text The text of the window to Move/Maximize ; optional: $Monitor The monitor to move to (1..NumMonitors) defaults to monitor mouse is on ; Note: Should probably have specified return/error codes but haven't put them in yet ; Author(s): xrxca (autoit@forums.xrx.ca) ;================================================================================================== Func _CenterOnMonitor($Title, $Text = '', $Monitor = -1) $hWindow = WinGetHandle($Title, $Text) If Not @error Then If $Monitor == -1 Then $Monitor = _GetMonitorFromPoint() ElseIf $__MonitorList[0][0] == 0 Then _GetMonitors() EndIf If ($Monitor > 0) And ($Monitor <= $__MonitorList[0][0]) Then ; Restore the window if necessary Local $WinState = WinGetState($hWindow) If BitAND($WinState, 16) Or BitAND($WinState, 32) Then WinSetState($hWindow, '', @SW_RESTORE) EndIf Local $WinSize = WinGetPos($hWindow) Local $x = Int(($__MonitorList[$Monitor][3] - $__MonitorList[$Monitor][1] - $WinSize[2]) / 2) + $__MonitorList[$Monitor][1] Local $y = Int(($__MonitorList[$Monitor][4] - $__MonitorList[$Monitor][2] - $WinSize[3]) / 2) + $__MonitorList[$Monitor][2] WinMove($hWindow, '', $x, $y) EndIf EndIf EndFunc ;==>_CenterOnMonitor ;================================================================================================== ; Function Name: _GetMonitorFromPoint([$XorPoint = -654321[, $Y = 0]]) ; Description:: Get a monitor number from an x/y pos or the current mouse position ; Parameter(s): ; optional: $XorPoint X Position or Array with X/Y as items 0,1 (ie from MouseGetPos()) ; optional: $Y Y Position ; Note: Should probably have specified return/error codes but haven't put them in yet, ; and better checking should be done on passed variables. ; Used to use MonitorFromPoint DLL call, but it didn't seem to always work. ; Author(s): xrxca (autoit@forums.xrx.ca) ;================================================================================================== Func _GetMonitorFromPoint($XorPoint = 0, $y = 0) If @NumParams = 0 then local $MousePos = MouseGetPos() Local $myX = $MousePos[0] Local $myY = $MousePos[1] Elseif ( @NumParams = 1 ) and IsArray($XorPoint) Then Local $myX = $XorPoint[0] Local $myY = $XorPoint[1] Else Local $myX = $XorPoint Local $myY = $y EndIf If $__MonitorList[0][0] == 0 Then _GetMonitors() EndIf Local $i = 0 Local $Monitor = 0 For $i = 1 To $__MonitorList[0][0] If ($myX >= $__MonitorList[$i][1]) _ And ($myX < $__MonitorList[$i][3]) _ And ($myY >= $__MonitorList[$i][2]) _ And ($myY < $__MonitorList[$i][4]) Then $Monitor = $i Next Return $Monitor EndFunc ;==>_GetMonitorFromPoint ;================================================================================================== ; Function Name: _GetMonitors() ; Description:: Load monitor positions ; Parameter(s): n/a ; Return Value(s): 2D Array of Monitors ; [0][0] = Number of Monitors ; [i][0] = HMONITOR handle of this monitor. ; [i][1] = Left Position of Monitor ; [i][2] = Top Position of Monitor ; [i][3] = Right Position of Monitor ; [i][4] = Bottom Position of Monitor ; Note: [0][1..4] are set to Left,Top,Right,Bottom of entire screen ; hMonitor is returned in [i][0], but no longer used by these routines. ; Also sets $__MonitorList global variable (for other subs to use) ; Author(s): xrxca (autoit@forums.xrx.ca) ;================================================================================================== Func _GetMonitors() $__MonitorList[0][0] = 0 ; Added so that the global array is reset if this is called multiple times Local $handle = DllCallbackRegister("_MonitorEnumProc", "int", "hwnd;hwnd;ptr;lparam") DllCall("user32.dll", "int", "EnumDisplayMonitors", "hwnd", 0, "ptr", 0, "ptr", DllCallbackGetPtr($handle), "lparam", 0) DllCallbackFree($handle) Local $i = 0 For $i = 1 To $__MonitorList[0][0] If $__MonitorList[$i][1] < $__MonitorList[0][1] Then $__MonitorList[0][1] = $__MonitorList[$i][1] If $__MonitorList[$i][2] < $__MonitorList[0][2] Then $__MonitorList[0][2] = $__MonitorList[$i][2] If $__MonitorList[$i][3] > $__MonitorList[0][3] Then $__MonitorList[0][3] = $__MonitorList[$i][3] If $__MonitorList[$i][4] > $__MonitorList[0][4] Then $__MonitorList[0][4] = $__MonitorList[$i][4] Next _ArraySort($__MonitorList, 0, 1, 0, 0, 0) ;added to sort it by the first column (hMonitor) so that they line up in physical order like Display Settings-->Rearrange Displays Return $__MonitorList EndFunc ;==>_GetMonitors ;================================================================================================== ; Function Name: _MonitorEnumProc($hMonitor, $hDC, $lRect, $lParam) ; Description:: Enum Callback Function for EnumDisplayMonitors in _GetMonitors ; Author(s): xrxca (autoit@forums.xrx.ca) ;================================================================================================== Func _MonitorEnumProc($hMonitor, $hDC, $lRect, $lParam) Local $Rect = DllStructCreate("int left;int top;int right;int bottom", $lRect) $__MonitorList[0][0] += 1 ReDim $__MonitorList[$__MonitorList[0][0] + 1][5] $__MonitorList[$__MonitorList[0][0]][0] = $hMonitor $__MonitorList[$__MonitorList[0][0]][1] = DllStructGetData($Rect, "left") $__MonitorList[$__MonitorList[0][0]][2] = DllStructGetData($Rect, "top") $__MonitorList[$__MonitorList[0][0]][3] = DllStructGetData($Rect, "right") $__MonitorList[$__MonitorList[0][0]][4] = DllStructGetData($Rect, "bottom") Return 1 ; Return 1 to continue enumeration EndFunc ;==>_MonitorEnumProc Now when I use _CenterOnMonitor, it correctly moves the specified WindowTitle to the specified Monitor number. _CenterOnMonitor("Notepad", "", 1) ;leftmost Sleep(2000) _CenterOnMonitor("Notepad", "", 2) ;middle left Sleep(2000) _CenterOnMonitor("Notepad", "", 3) ;middle right Sleep(2000) _CenterOnMonitor("Notepad", "", 4) ;rightmost Edit: I didn't find MultiMon.au3 anywhere in the AutoIt Examples pages to follow up with my 2 cents, so I stuck it here.
    1 point
  9. In the explorer script, you would simply change "explorer.exe" to the name of your application. Then inside the function, change the class name to the class of the window you're after (Use the AutoIt Window Info Tool, in the same directory where you installed AutoIt, to find this information). For example, this works with Notepad: Local $hRun1 = _Run('notepad.exe', 0, 0, @DesktopWidth/2, @DesktopHeight - 50) Local $hRun2 = _Run('notepad.exe', @DesktopWidth/2, 0, @DesktopWidth/2, @DesktopHeight - 50) Func _Run($sRunCommand, $iX, $iY, $iW, $iH) Local $aWinList_Before = WinList("[CLASS:Notepad]") Run($sRunCommand) Do $aWinList_After = WinList("[CLASS:Notepad]") Until $aWinList_After[0][0] > $aWinList_Before[0][0] Local $hWnd = $aWinList_After[1][1] Sleep(1000) WinMove($hWnd, "", $iX, $iY, $iW, $iH) EndFunc
    1 point
  10. Let me also introduce you my function, I guess it's simple and rather clear. ; Func: _FindLatestLog ; Searches the latest file in specified directory with specified mask ; Example of usage: FindLatestLog (@UserProfileDir & "\AppData\Roaming\Application", "*Waiter*.log") Func _FindLatestLog ($dir, $mask) Local $latestTime = 0, $currentTime = 0 Local $files = _FileListToArray($dir, $mask, 1) If @error = 1 Then ConsoleWrite('Func: FindLog, Error: Path was invalid.' & @CRLF) Return False EndIf If @error = 4 Then ConsoleWrite('Func: FindLog, Error: Log file was not found.' & @CRLF) Return False EndIf For $i = 1 To UBound($files) - 1 $currentFile = $dir & "\" & $files[$i] $currentTime = FileGetTime($currentFile, $FT_MODIFIED, 1) If $currentTime > $latestTime Or $i = 1 Then $latestTime = $currentTime $latestFile = $currentFile EndIf Next ConsoleWrite( "Latest log file: " & $latestFile & ", time modified: " & $latestTime & @CRLF) Return $latestFile EndFunc ;==>_FindLatestLog
    1 point
×
×
  • Create New...