Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/10/2022 in all areas

  1. Hello $CitrixTitle="TextOfCitrixWindowTitle" while WinExists($CitrixTitle) Sleep 200 WEnd MsgBox(64,"Citrix Window closed","Going to logoff",30) Shutdown(0)
    2 points
  2. KaFu

    Better thumbnail creation

    Here's my take, adjust the brushes white, green and red as desired (I know green and red should be black 🙂, but with green and red the example is better and you see what's going on). #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <GDIPlus.au3> ; Create GUI with a ListView control Global $hGUI = GUICreate("ListView", 700, 420, -1, -1, $WS_OVERLAPPEDWINDOW) Global $hListView = _GUICtrlListView_Create($hGUI, "", 70, 0, 630, 420, BitOR($LVS_ICON, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING)) GUISetState(@SW_SHOW, $hGUI) ; Create and load ImageList control with thumbnails _GDIPlus_Startup() Global $sPath = StringReplace(@AutoItExe, "autoit3.exe", "Examples\GUI") Local $aFile = _FileListToArray($sPath, Default, $FLTA_FILES) If @error = 0 Then ; found some files Global $SizeX = 160 ; width of each thumbnail Global $SizeY = 100 ; height of each thumbnail Global $hImgLst = _GUIImageList_Create($SizeX, $SizeY) ; create an imagelist control Global $aImgFiles[1] ; create an array to hold the names of images we load Global $_dHash_hBitmap_SmallScale = _GDIPlus_BitmapCreateFromScan0($SizeX, $SizeY) Global $_dHash_hBitmap_SmallScale_Graphics = _GDIPlus_ImageGetGraphicsContext($_dHash_hBitmap_SmallScale) Global $hBrush_White = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) Global $hBrush_Green = _GDIPlus_BrushCreateSolid(0xFF00FF00) Global $hBrush_Red = _GDIPlus_BrushCreateSolid(0xFFFF0000) For $i = 1 To $aFile[0] $sFile = $sPath & "\" & $aFile[$i] Switch StringRight($sFile, 4) Case ".png", ".jpg", ".gif" Case Else ContinueLoop EndSwitch Local $hImage = _GDIPlus_ImageLoadFromFile($sFile) ; try to load the image from the file ; ShellExecute($sPath & "\" & $aFile[$i]) If $hImage <> 0 Then $iImage_iWidth = _GDIPlus_ImageGetWidth($hImage) $iImage_iHeight = _GDIPlus_ImageGetHeight($hImage) If $iImage_iWidth > Round($iImage_iHeight * ($SizeX / $SizeY)) Then ConsoleWrite("+ ") $iImage_Resized_Width = $SizeX $iImage_Offset_X = 0 $iImage_Resized_Height = Round($iImage_iHeight / ($SizeX / $SizeY)) $iImage_Offset_Y = Round(($SizeY - $iImage_Resized_Height) / 2) Else ConsoleWrite("- ") $iImage_Resized_Width = Round($SizeX / ($SizeX / $SizeY)) $iImage_Offset_X = Round(($SizeX - $iImage_Resized_Width) / 2) $iImage_Resized_Height = $SizeY $iImage_Offset_Y = 0 EndIf ConsoleWrite($aFile[$i] & @TAB & @TAB & $iImage_Resized_Width & "x" & $iImage_Resized_Height & @TAB & $iImage_Offset_X & "x" & $iImage_Offset_Y & @CRLF) $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage) _GDIPlus_GraphicsSetInterpolationMode($hGraphics, $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC) Local $hImageScaled = _GDIPlus_ImageResize($hImage, $iImage_Resized_Width, $iImage_Resized_Height) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_ImageDispose($hImage) ; clean up _GDIPlus_GraphicsFillRect($_dHash_hBitmap_SmallScale_Graphics, 0, 0, $SizeX, $SizeY, $hBrush_White) If $iImage_Offset_X Then ConsoleWrite("a" & @CRLF) _GDIPlus_GraphicsFillRect($_dHash_hBitmap_SmallScale_Graphics, 0, 0, $iImage_Offset_X, $SizeY, $hBrush_Green) ConsoleWrite("0x0 - " & $iImage_Offset_X & "x" & $SizeY & @CRLF) _GDIPlus_GraphicsFillRect($_dHash_hBitmap_SmallScale_Graphics, $iImage_Resized_Height + $iImage_Offset_X, 0, $iImage_Offset_X, $SizeY, $hBrush_Red) ConsoleWrite($iImage_Resized_Height + $iImage_Offset_X & "x0 - " & $iImage_Offset_X & "x" & $SizeY & @CRLF) Else ConsoleWrite("b" & @CRLF) _GDIPlus_GraphicsFillRect($_dHash_hBitmap_SmallScale_Graphics, 0, 0, $SizeX, $iImage_Offset_Y, $hBrush_Green) ConsoleWrite("0x0 - " & $SizeX & "x" & $iImage_Offset_Y & @CRLF) _GDIPlus_GraphicsFillRect($_dHash_hBitmap_SmallScale_Graphics, 0, $iImage_Resized_Height + $iImage_Offset_Y, $SizeX, $iImage_Offset_Y, $hBrush_Red) ConsoleWrite("0x" & $iImage_Resized_Height + $iImage_Offset_Y & " - " & $SizeX & "x" & $iImage_Offset_Y & @CRLF) EndIf _GDIPlus_GraphicsDrawImageRect($_dHash_hBitmap_SmallScale_Graphics, $hImageScaled, $iImage_Offset_X, $iImage_Offset_Y, $iImage_Resized_Width, $iImage_Resized_Height) ; draw loaded file to existing buffer _GDIPlus_ImageDispose($hImageScaled) Local $Bmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($_dHash_hBitmap_SmallScale) ; create a handle to the bitmap object Local $iIndex = _GUIImageList_Add($hImgLst, $Bmp) ; add the bitmap to the ImageList and note the index number _WinAPI_DeleteObject($Bmp) ; clean up If $iIndex <> -1 Then ReDim $aImgFiles[$iIndex + 1] ; make room in the array for the file name of the image just loaded $aImgFiles[$iIndex] = $aFile[$i] ; store the file name of the image just loaded EndIf EndIf Next _GDIPlus_GraphicsDispose($_dHash_hBitmap_SmallScale_Graphics) _GDIPlus_BitmapDispose($_dHash_hBitmap_SmallScale) _GDIPlus_BrushDispose($hBrush_White) _GDIPlus_BrushDispose($hBrush_Green) _GDIPlus_BrushDispose($hBrush_Red) _GUICtrlListView_SetImageList($hListView, $hImgLst, 0) ; assign the ImageList to the ListView ; Add the thumbnails as items to the ListView, and use the file names as captions For $i = 0 To UBound($aImgFiles) - 1 _GUICtrlListView_AddItem($hListView, $aImgFiles[$i], $i) Next EndIf Do Local $Msg = GUIGetMsg() Until $Msg = $GUI_EVENT_CLOSE _GDIPlus_Shutdown() GUIDelete() Exit
    1 point
  3. It works... with a funny script. The background is light grey because it's the color I choosed on my computer. On yours it should be white. #include <File.au3> #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <GDIPlus.au3> #include <WindowsConstants.au3> ; Create GUI with a ListView control Global $hGUI = GUICreate("ListView", 700, 420, -1, -1, $WS_OVERLAPPEDWINDOW) Global $hListView = _GUICtrlListView_Create($hGUI, "", 70, 0, 630, 420, _ BitOR($LVS_ICON, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING)) GUISetState(@SW_SHOW, $hGUI) ; Create and load ImageList control with thumbnails _GDIPlus_Startup() Global $sPath = StringReplace(@AutoItExe, "autoit3.exe", "Examples\GUI") Local $aFile = _FileListToArray($sPath, Default, $FLTA_FILES) If @error = 0 Then ; found some files Global $SizeX = 160 ; width of each thumbnail Global $SizeY = 100 ; height of each thumbnail Global $fRatioThumb = $SizeX / $SizeY Global $hImgLst = _GUIImageList_Create($SizeX, $SizeY) ; create an imagelist control Global $aImgFiles[1] ; create an array to hold the names of images we load ; create GUI2 visible... under the screen down left corner Local $hGUI2 = GUICreate("", $SizeX, $SizeY, 0, @DesktopHeight, $WS_POPUP) GUISetState(@SW_SHOW, $hGUI2) ; mandatory line or nothing will work For $i = 1 To $aFile[0] $sFile = $sPath & "\" & $aFile[$i] Switch StringRight($sFile, 4) Case ".png", ".jpg", ".gif" Case Else ContinueLoop EndSwitch Local $hImage = _GDIPlus_ImageLoadFromFile($sFile) ; try to load the image from the file If $hImage <> 0 Then $iImage_iWidth = _GDIPlus_ImageGetWidth($hImage) $iImage_iHeight = _GDIPlus_ImageGetHeight($hImage) $fRatioImage = $iImage_iWidth / $iImage_iHeight Switch True Case $fRatioThumb < $fRatioImage ConsoleWrite("+ ") $iImage_Resized_Width = $SizeX $iImage_Offset_X = 0 $iImage_Resized_Height = Round($iImage_Resized_Width / $fRatioImage) $iImage_Offset_Y = Floor(($SizeY - $iImage_Resized_Height) / 2) Case $fRatioThumb > $fRatioImage ConsoleWrite("- ") $iImage_Resized_Height = $SizeY $iImage_Offset_Y = 0 $iImage_Resized_Width = Round($iImage_Resized_Height * $fRatioImage) $iImage_Offset_X = Floor(($SizeX - $iImage_Resized_Width) / 2) Case Else ConsoleWrite("= ") $iImage_Resized_Width = $SizeX $iImage_Offset_X = 0 $iImage_Resized_Height = $SizeY $iImage_Offset_Y = 0 EndSwitch ConsoleWrite($aFile[$i] & @TAB & @TAB & $iImage_Resized_Width & "x" & $iImage_Resized_Height & @TAB & $iImage_Offset_X & "x" & $iImage_Offset_Y & @CRLF) Local $hImageScaled = _GDIPlus_ImageResize($hImage, $iImage_Resized_Width, $iImage_Resized_Height) ; resize the image (maintain aspect ratio) _GDIPlus_ImageDispose($hImage) Local $idPic = GUICtrlCreatePic("", $iImage_Offset_X, $iImage_Offset_Y, $iImage_Resized_Width, $iImage_Resized_Height) Local $hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageScaled) _WinAPI_DeleteObject(GUICtrlSendMsg($idPic, 0x0172, 0, $hBmp)) ; STM_SETIMAGE = 0x0172, $IMAGE_BITMAP = 0 _WinAPI_DeleteObject($hBmp) _GDIPlus_ImageDispose($hImageScaled) Local $idLabel, $idLabel2 If $iImage_Resized_Width <> $SizeX Then $idLabel = GuiCtrlCreateLabel("", 0, 0, $iImage_Offset_X, $SizeY) GUICtrlSetBkColor(-1, 0x000000) ; black label (left side of pic) $idLabel2 = GuiCtrlCreateLabel("", $iImage_Offset_X + $iImage_Resized_Width, 0, $iImage_Offset_X, $SizeY) GUICtrlSetBkColor(-1, 0x000000) ; black label (right side of pic) ElseIf $iImage_Resized_Height <> $SizeY Then $idLabel = GuiCtrlCreateLabel("", 0, 0, $SizeX, $iImage_Offset_Y) GUICtrlSetBkColor(-1, 0x000000) ; black label (above pic) $idLabel2 = GuiCtrlCreateLabel("", 0, $iImage_Offset_Y + $iImage_Resized_Height, $SizeX, $iImage_Offset_Y) GUICtrlSetBkColor(-1, 0x000000) ; black label (under pic) EndIf Local $hBmp2 = _WinCapture($hGUI2, $SizeX, $SizeY) ; capture the client area of hGUI2 (off the screen) Local $iIndex = _GUIImageList_Add($hImgLst, $hBmp2) ; add the bitmap to the ImageList and note the index number _WinAPI_DeleteObject($hBmp2) GUICtrlDelete($idPic) GUICtrlDelete($idLabel) GUICtrlDelete($idLabel2) If $iIndex <> -1 Then ReDim $aImgFiles[$iIndex + 1] ; make room in the array for the file name of the image just loaded $aImgFiles[$iIndex] = $aFile[$i] ; store the file name of the image just loaded EndIf EndIf Next _GUICtrlListView_SetImageList($hListView, $hImgLst, 0) ; assign the ImageList to the ListView ; Add the thumbnails as items to the ListView, and use the file names as captions For $i = 0 To UBound($aImgFiles) - 1 _GUICtrlListView_AddItem($hListView, $aImgFiles[$i], $i) Next GUIDelete($hGUI2) EndIf Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _GDIPlus_Shutdown() GUIDelete($hGUI) ;======================================== Func _WinCapture($hWnd, $iWidth, $iHeight) Local $hSrcDC, $hDestDC, $hBmp $hSrcDC = _WinAPI_GetDC($hWnd) $hBmp = _WinAPI_CreateCompatibleBitmap($hSrcDC, $iWidth, $iHeight) $hDestDC = _WinAPI_CreateCompatibleDC($hSrcDC) _WinAPI_SelectObject($hDestDC, $hBmp) _WinAPI_PrintWindow($hWnd, $hDestDC, True) ; True = only the client area _WinAPI_BitBlt($hDestDC, 0, 0, $iWidth, $iHeight, $hSrcDC, 0, 0, $SRCCOPY) _WinAPI_DeleteDC($hDestDC) _WinAPI_ReleaseDC($hWnd, $hSrcDC) Return $hBmp EndFunc ;==>_WinCapture Updates : * Nov 9, 2022 : Create GUI2 off the screen in one pass. * Nov 10, 2022 : Add a 3rd parameter True to _WinAPI_PrintWindow() to capture only the client area (though GUI2 got only a $WS_POPUP style, then it makes no difference in this case) * Nov 11, 2022 : Use TimRude's calculation (from his last script) to keep thumbnail ratio always = original image ratio. The vertical black bars will then have a different width, depending on the original images.
    1 point
  4. @TimRude try to subclass the listview, it should intercept the right-click before it reaches it : #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <WinAPIShellEx.au3> OnAutoItExitRegister('OnAutoItExit') Global $g_hListView ; Register DLL callback that will be used as window subclass procedure Global $g_hDll = DllCallbackRegister('_SubclassProc', 'lresult', 'hwnd;uint;wparam;lparam;uint_ptr;dword_ptr') Global $g_pDll = DllCallbackGetPtr($g_hDll) Example() Func Example() Local $hGUI, $hImage $hGUI = GUICreate("ListView Create (v" & @AutoItVersion & ")", 400, 300) $g_hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle($g_hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) ; Install window subclass callback _WinAPI_SetWindowSubclass($g_hListView, $g_pDll, 1000, 0) GUISetState(@SW_SHOW) ; Load images $hImage = _GUIImageList_Create() _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_hListView, 0xFF0000, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_hListView, 0x00FF00, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($g_hListView, 0x0000FF, 16, 16)) _GUICtrlListView_SetImageList($g_hListView, $hImage, 1) ; Add columns _GUICtrlListView_InsertColumn($g_hListView, 0, "Column 1", 100) _GUICtrlListView_InsertColumn($g_hListView, 1, "Column 2", 100) _GUICtrlListView_InsertColumn($g_hListView, 2, "Column 3", 100) ; Add items _GUICtrlListView_AddItem($g_hListView, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 2", 1) _GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 3", 2) _GUICtrlListView_AddItem($g_hListView, "Row 2: Col 1", 1) _GUICtrlListView_AddSubItem($g_hListView, 1, "Row 2: Col 2", 1) _GUICtrlListView_AddItem($g_hListView, "Row 3: Col 1", 2) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func _SubclassProc($hWnd, $iMsg, $wParam, $lParam, $iID, $pData) #forceref $iID, $pData If $iMsg = $WM_RBUTTONDOWN Then Return 0 Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_SubclassProc Func OnAutoItExit() _WinAPI_RemoveWindowSubclass($g_hListView, $g_pDll, 1000) DllCallbackFree($g_hDll) EndFunc ;==>OnAutoItExit
    1 point
  5. Current version v1.4: GetOpt.zip
    1 point
  6. Grosminet, I have never used that message for detecting thumb movement on a slider - I always use $SB_THUMBTRACK via a $WM_H/VSCROLL message like this: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> $hGUI = GUICreate("Test", 500, 500) $cSlider = GUICtrlCreateSlider(10, 10, 200, 20) $hSlider = GUICtrlGetHandle($cSlider) GUISetState() GUIRegisterMsg($WM_HSCROLL, "_WM_HSCROLL") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_HSCROLL($hWnd, $iMsg, $wParam, $lParam) If $lParam = $hSlider Then If _WinAPI_LoWord($wParam) = 5 Then ;$SB_THUMBTRACK ConsoleWrite(GUICtrlRead($cSlider) & " - " & @MSEC & @CRLF) EndIf EndIf Return $GUI_RUNDEFMSG EndFunc M23
    1 point
  7. Thanks, but it didn't work, but I worked around it by using a tool called KeyTweak. It allows you to remap your keyboard keys real easily. So I replaced the Caps Lock with a key not found on my keyboard(without a numpad). Didn't keep the script short like you since I won't use the key just for volume, but also more advanced scripts. #include <Misc.au3> HotKeySet("{NUMPADMULT}", "HoldModifier") While 1 Sleep(100) WEnd Func HoldModifier() If _IsPressed("6A") Then HotKeySet("1", "VolUp") HotKeySet("2", "VolDown") HotKeySet("3", "VolMute") while _IsPressed("6A") sleep(0) WEnd HotKeySet("1") HotKeySet("2") HotKeySet("3") EndIf EndFunc Func VolUp() Send("{VOLUME_UP}") EndFunc Func VolDown() Send("{VOLUME_DOWN}") EndFunc Func VolMute() Send("{VOLUME_MUTE}") EndFunc
    1 point
×
×
  • Create New...