Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 12/19/2019 in all areas

  1. Example 1: better to just overwrite (A) the variable (same memory location, so the number of (re)writes doesn't matter). But every extra function call costs performance. Example 2: Fastest evaluation uses Switch, not If/Then/Else, e.g., Switch $b_Input Case True ; do something Case Else ; do something else EndSwitch Example 3: AFAIK, boolean "True" is converted to 1, so "While 1" is marginally faster than "While True".
    2 points
  2. Just comment the _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\test.bmp") line out?
    1 point
  3. I think _WinAPI_DeleteObject($hBitmap) did not delete the object resulting in a memory leak, try this with _GDIPlus_ImageDispose($hBitmap) in your loop. #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <WinAPIHObj.au3> Local $handle = WinGetHandle("[CLASS:SciTEWindow]", "") Local $iRegion_X = 10, $iRegion_Y = 10, $iRegion_W = 100, $iRegion_H = 100 ; Initialize GDI+ library _GDIPlus_Startup() Local $hBitmap = Capture_Window($handle, _WinAPI_GetWindowWidth($handle), _WinAPI_GetWindowHeight($handle)) _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\test.bmp") ; Create 24 bit bitmap clone Local $hClone = _GDIPlus_BitmapCloneArea($hBitmap, $iRegion_X, $iRegion_Y, $iRegion_W, $iRegion_H, $GDIP_PXF24RGB) _GDIPlus_ImageSaveToFile($hClone, @ScriptDir & "\GDIPlus_Image.bmp") ; Clean up resources _GDIPlus_ImageDispose($hClone) _GDIPlus_ImageDispose($hBitmap) ; Shut down GDI+ library _GDIPlus_Shutdown() Func Capture_Window($hWnd, $w, $h) If Not IsHWnd($hWnd) Then Return SetError(1, 0, 0) If Int($w) < 1 Then Return SetError(2, 0, 0) If Int($h) < 1 Then Return SetError(3, 0, 0) Local Const $hDC_Capture = _WinAPI_GetDC(HWnd($hWnd)) Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture) Local Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $w, $h) Local Const $hObjectOld = _WinAPI_SelectObject($hMemDC, $hHBitmap) DllCall("gdi32.dll", "int", "SetStretchBltMode", "hwnd", $hDC_Capture, "uint", 4) DllCall("user32.dll", "int", "PrintWindow", "hwnd", $hWnd, "handle", $hMemDC, "int", 0) _WinAPI_DeleteDC($hMemDC) _WinAPI_SelectObject($hMemDC, $hObjectOld) _WinAPI_ReleaseDC($hWnd, $hDC_Capture) Local Const $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]") Local Const $aFullScreen = WinGetPos($hFullScreen) Local Const $c1 = $aFullScreen[2] - @DesktopWidth, $c2 = $aFullScreen[3] - @DesktopHeight Local Const $wc1 = $w - $c1, $hc2 = $h - $c2 If (($wc1 > 1 And $wc1 < $w) Or ($w - @DesktopWidth > 1) Or ($hc2 > 7 And $hc2 < $h) Or ($h - @DesktopHeight > 1)) And (BitAND(WinGetState(HWnd($hWnd)), 32) = 32) Then Local $hBmp_t = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap) $hBmp = _GDIPlus_BitmapCloneArea($hBmp_t, 8, 8, $w - 16, $h - 16) _GDIPlus_BitmapDispose($hBmp_t) Else $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap) EndIf _WinAPI_DeleteObject($hHBitmap) Return $hBmp EndFunc ;==>Capture_Window
    1 point
  4. Here a more robust approach : #include <Constants.au3> #include <Array.au3> #include <WinAPIProc.au3> #include <File.au3> Opt("MustDeclareVars", 1) Opt("ExpandEnvStrings", 1) Const $sFileName = @ScriptDir & "\David Bowie Starman.wav" Local $sDrive, $sDir, $sName, $sExt _PathSplit($sFileName, $sDrive, $sDir, $sName, $sExt) Local $sDefault = RegRead("HKEY_CLASSES_ROOT\" & $sExt, "") $sDefault = RegRead("HKEY_CLASSES_ROOT\" & $sDefault & "\shell\open\command", "") $sDefault = StringRegExp($sDefault, '^"(.+?)"', $STR_REGEXPARRAYMATCH)[0] _PathSplit($sDefault, $sDrive, $sDir, $sName, $sExt) Local $aList1 = _FindProcess($sName & $sExt) Run(@ComSpec & ' /c start "dummy title" "' & $sFileName & '"') Sleep(2000) Local $aList2 = _FindProcess($sName & $sExt) MsgBox ($MB_SYSTEMMODAL,"",CompareFileList ($aList2, $aList1)) Func _FindProcess($sProcessName) Local $aList = ProcessList(), $aPID[$aList[0][0]] $aPID[0] = 0 For $i = 1 To $aList[0][0] If $aList[$i][0] = $sProcessName Then $aPID[0] += 1 $aPID[$aPID[0]] = $aList[$i][1] EndIf Next ReDim $aPID[$aPID[0] + 1] Return $aPID EndFunc ;==>_FindProcess Func CompareFileList (ByRef $aListAfter, ByRef $aListBefore) For $i = 1 to $aListAfter[0] _ArraySearch ($aListBefore, $aListAfter[$i], 1) If @error Then Return $aListAfter[$i] Next Return 0 EndFunc This can be applied to ANY file extensions. You could also run the default program instead. Would save you all list creation and comparaison...
    1 point
  5. #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <WinAPIHObj.au3> Local $handle = WinGetHandle("[CLASS:SciTEWindow]", "") Local $hClone, $hImage, $iX, $i ; Initialize GDI+ library _GDIPlus_Startup() Local $hBitmap = Capture_Window($handle, _WinAPI_GetWindowWidth($handle), _WinAPI_GetWindowHeight($handle)) ;ConsoleWrite(_WinAPI_GetWindowWidth($handle)) _GDIPlus_ImageSaveToFile($hBitmap, @ScriptDir & "\test.bmp") ; Create 24 bit bitmap clone $iX = _GDIPlus_ImageGetWidth($hBitmap) $iY = _GDIPlus_ImageGetHeight($hBitmap) $hClone = _GDIPlus_BitmapCloneArea($hBitmap, 0, 0, $iX, $iY, $GDIP_PXF24RGB) _GDIPlus_ImageSaveToFile($hClone, @ScriptDir & "\GDIPlus_Image.bmp") ; Clean up resources _GDIPlus_ImageDispose($hClone) _WinAPI_DeleteObject($hBitmap) ; Shut down GDI+ library _GDIPlus_Shutdown() Func Capture_Window($hWnd, $w, $h) If Not IsHWnd($hWnd) Then Return SetError(1, 0, 0) If Int($w) < 1 Then Return SetError(2, 0, 0) If Int($h) < 1 Then Return SetError(3, 0, 0) Local Const $hDC_Capture = _WinAPI_GetDC(HWnd($hWnd)) Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture) Local Const $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $w, $h) Local Const $hObjectOld = _WinAPI_SelectObject($hMemDC, $hHBitmap) DllCall("gdi32.dll", "int", "SetStretchBltMode", "hwnd", $hDC_Capture, "uint", 4) DllCall("user32.dll", "int", "PrintWindow", "hwnd", $hWnd, "handle", $hMemDC, "int", 0) _WinAPI_DeleteDC($hMemDC) _WinAPI_SelectObject($hMemDC, $hObjectOld) _WinAPI_ReleaseDC($hWnd, $hDC_Capture) Local Const $hFullScreen = WinGetHandle("[TITLE:Program Manager;CLASS:Progman]") Local Const $aFullScreen = WinGetPos($hFullScreen) Local Const $c1 = $aFullScreen[2] - @DesktopWidth, $c2 = $aFullScreen[3] - @DesktopHeight Local Const $wc1 = $w - $c1, $hc2 = $h - $c2 If (($wc1 > 1 And $wc1 < $w) Or ($w - @DesktopWidth > 1) Or ($hc2 > 7 And $hc2 < $h) Or ($h - @DesktopHeight > 1)) And (BitAND(WinGetState(HWnd($hWnd)), 32) = 32) Then Local $hBmp_t = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap) $hBmp = _GDIPlus_BitmapCloneArea($hBmp_t, 8, 8, $w - 16, $h - 16) _GDIPlus_BitmapDispose($hBmp_t) Else $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap) EndIf _WinAPI_DeleteObject($hHBitmap) Return $hBmp EndFunc ;==>Capture_Window
    1 point
  6. @CYCho Personally, I think it would be good to add some of this functionality to the UDF, but not everything. For example, auto-updating to the latest UDF version could result in your application failing due to a script breaking change or an unintended bug in the release. To get the version number of the local copy, why not just #include it and obtain the value from $__WDVERSION?
    1 point
  7. May 2012. Michael Sun (from Microsoft) answered a guy who had a similar problem, in this link. He proposed a workaround as there is no solution for this. Here are some sentences found in the link : - Michael Sun : "We are not saying that we cannot put duplicate values into the ComboBox. Actually, I just feel confused. If an app put duplicate values in the ComboBox, I will feel confused which one should I select. What's the difference between the duplicate values ? In my post, I provided a workaround which can prevent the SelectedIndex changing to the first item named chris. However, if we open the ComboBox again, its SelectedIndex value will change back to the first item named chris. I don't think the issue can be easily fixed since it's related to the underlying Win32 control in the OS level. Could you please make the three "chris" in the ComboBox be a little different?" - OP : "if I should not use duplicate values means why the combo box allows me to add the values, why the combobox is not throwing any exception while binding itself., and why selectedvalue is property given ?" - Michael Sun : "Please try my workaround and let me know the result. I cannot figure out other ways right now since it's related to an OS level issue as I mentioned in my last post."
    1 point
  8. Zedna

    GUI array file open - exists?

    Look at these functions (and examples for them in helpfile): _FileListToArray() StringSplit() StringReplace() -> replace '-' by '| ' in filename for GUICtrlCreateListViewItem() GUICtrlCreateListView() GUICtrlCreateListViewItem() ShellExecute()
    1 point
  9. As for the Windows standard controls, all functionality can be implemented in AutoIt. The only option in your special case is probably to implement an Owner-Drawn ComboBox. I'll add an example that supports correct selection of multiple items with the same text in this thread. But at least I need the weekend and maybe all Christmas depending on how much time I can find to code AutoIt.
    1 point
  10. Yep, confused PID and Name of process just by guessing / assuming :), but still your code reports this to me: > PID = <7812> Name = <vlc.exe> CommandLine = <--started-from-file "C:\_Data\!_Keep\AMT-Workbench_MPV-Test\123.mp3"> Maybe you have to increase sleep time (and remove the "vlc.exe" check, works for me without it)? Edit: #include <Array.au3> #include <WinAPIProc.au3> $sFilename = '"' & @ScriptDir & '\123.mp3"' $iPID = Run(@ComSpec & ' /c start "Titel" ' & $sFilename,"",@SW_HIDE) ConsoleWrite("< ------------------------------------------------------------------------------" & @CRLF) ConsoleWrite("+ Filename : <" & $sFilename & ">" & @CRLF) ConsoleWrite("+ PID Run(...) : <" & $iPID & ">" & @CRLF) ConsoleWrite("< ------------------------------------------------------------------------------" & @CRLF) Sleep(2000) ; wait for the default program to launch $aList = ProcessList() For $i = 1 To $aList[0][0] if StringInStr(_WinAPI_GetProcessCommandLine($aList[$i][1]),$sFilename) then ConsoleWrite("> PID = <" & $aList[$i][1] & ">" & _ " Name = <" & $aList[$i][0] & ">" & _ " CommandLine = <" & _WinAPI_GetProcessCommandLine($aList[$i][1]) & ">" & @CRLF) EndIf Next ConsoleWrite("< ------------------------------------------------------------------------------" & @CRLF) Reports to me: > PID = <800> Name = <vlc.exe> CommandLine = <--started-from-file "C:\_Data\!_Keep\AMT-Workbench_MPV-Test\123.mp3">
    1 point
  11. A few things. This this is a free program I took a look at it. The installer looks like it can be easily automated via Control functions instead of mouse clicks. That will be infinitely better to use IF you had too. Second is I spent a few minutes looking at the FAQ and found "how to run this from a network drive" Multi-user installation to a network drive For intermediate/advanced users, here's another way to install to a network drive for use by any number of users: Install CleanUp! as normal on any machine. Make sure you are connected to the network drive you want to install CleanUp! on - you'll only need around 400K free on the disk (though obviously much more would be recommended just for good system performance outside of CleanUp!). Copy all the files from the CleanUp! installation folder into the deired network folder. Please be sure to copy all the files - including the on-line Help and contents files (*.hlp and *.cnt) - so as to stay within the intent of the (freeware) license. Now you can go to any machine that is also connected to that drive and run CleanUp! directly from that directory. From this you can derive that the installer is simply extracting a "portable" application so you can easily just copy this folder to any machines and it would be "installed" and then of course automate anything as needed with AutoIT
    1 point
  12. I have given the link to this thread as an answer in another thread. There the OP described his problems with "false positives". Later the thread was merged/moved in here by a moderator, including my contribution. Now my answer is outside the original context, and appears therefore pointless . Perhaps it would be a good idea to simply remove the link.
    1 point
  13. A new version (v1.1.0) was just published to the Downloads section of the forum.
    1 point
  14. Subz

    input box help

    Basic example #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Example() Func Example() GUICreate("listview items", 220, 250) Local $idListview = GUICtrlCreateListView("Computers", 10, 10, 200, 150) _GUICtrlListView_SetColumnWidth($idListview, 0, $LVSCW_AUTOSIZE_USEHEADER) Local $idComputer = GUICtrlCreateInput("", 10, 170, 200, 20) _GUICtrlEdit_SetCueBanner($idComputer, "Enter Computer Name") Local $idAdd = GUICtrlCreateButton("Add Computer", 10, 195, 95, 20) Local $idSuffix = GUICtrlCreateInput("$", 110, 195, 100, 20) _GUICtrlEdit_SetCueBanner($idSuffix, "Add Suffix [Optional]") Local $idRead = GUICtrlCreateButton("Read List", 10, 220, 200, 20) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idAdd $vSuffix = GUICtrlRead($idSuffix) If GUICtrlRead($idComputer) <> "" Then GUICtrlCreateListViewItem(GUICtrlRead($idComputer) & $vSuffix, $idListview) EndIf Case $idRead $iListView = _GUICtrlListView_GetItemCount($idListview) If $iListView = 0 Then ContinueLoop For $i = 0 To $iListView SplashTextOn("Computers", _GUICtrlListView_GetItemText($idListview, $i), 250, 50) Sleep(1000) Next SplashOff() EndSwitch WEnd EndFunc
    1 point
  15. No need - I will lock it right now! M23
    1 point
  16. nobody is going to walk you through decompiling, and i think if you type the word three times in dark mode the thread locks itself.
    1 point
  17. This information is stored in the registry and can be retrieved using the RegRead() function. Here's a quick way to read this info from the registry and display it in message boxes. #RequireAdmin #include <MsgBoxConstants.au3> Local $manufacturer = RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\BIOS", "SystemManufacturer") Local $model = RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\BIOS", "SystemProductName") MsgBox($MB_SYSTEMMODAL, "", "Manufacturer: " & $manufacturer) MsgBox($MB_SYSTEMMODAL, "", "Model: " & $model)
    1 point
  18. Like I said in my reply, the INDEX doesn't change, just the order OF the indexes. So when you read the indexes, [1] holds whatever index is holding the information for column one. That index number may contain the information from the original column 2 or 3. The original list, if you haven't moved any columns would be 1|2|3. So if you move column 3 to the first column, the column indexes would read 3|1|2. You'd need to read the order of the columns, find out what index is in which column, read the row in the order of the indexes. You can't use a simple loop as you would do if the listview didn't have movable columns. They do exactly what the help file says they do, they programmatically set the column order instead of having to move them by hand. The first one reads the column order, the second one sets them to the exact same order they're already in, so using it is pointless the way you're doing it. The column set command does NOT change the indexes that are applied to the columns, it merely moves the index to the columns you specify.
    1 point
×
×
  • Create New...