Sign in to follow this  
Followers 0
pejot26

How can I get this effect?

7 posts in this topic

I'm new and only know autoit, so need advice from someone more experienced. My point here is to move the cursor to automatically display the image, a preview (400x400) as the qttabbar. Is this possible without this program? Please quick help ;)

Share this post


Link to post
Share on other sites



Hi, pejot26, welcome to the forum. Your explanation is a bit fuzzy. Are you meaning QTTabBar, the product that turns Windows Explorer into a tabbed browser, or some other application?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

yes, it is QTTabBar

Share this post


Link to post
Share on other sites

So, your explanation is still lacking. Do you want to click on one of the tabs, or are you trying to create a tabbed interface for Windows Explorer, or something else? How about a screenshot showing what you would like to accomplish. Help us help you ;)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Posted Image

Here's what that does preview the selected image without displaying it in other applications. Is it possible to achieve this in autoit to work in the background?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Here a modified version from here:

 

;Original code by Jayson -> http://www.autoitscript.com/forum/topic/127935-list-view-display-thumbnails/#entry888097
;Modified by UEZ 2012
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <File.au3>
#Include <EditConstants.au3>
#Include <Constants.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GDIPlus.au3>
#include <WinAPIvkeysConstants.au3>

Opt('MustDeclareVars', 1)

Global $sExtFilter = "bmp|gif|jpeg|jpg|png|tif|tiff"
Global $hGui, $hGui_Preview, $hGui_PreviewSize, $idPic, $idLabel_Info, $Path, $BRowse, $LV, $Pic, $hLV, $aCtrl, $show, $FSF, $timer, $file_prev, $off = False
Global $hImageList, $sCur, $sLast, $iDX, $iPicState = 0, $DoubleClick = -1
_GDIPlus_Startup()
$hGui = GUICreate("Image Viewer", 490, 620)
$Path = GUICtrlCreateInput("", 10, 10, 400, 20, $ES_READONLY)
$BRowse = GUICtrlCreateButton("Browse", 420, 10, 60, 20)
$LV = GUICtrlCreateListView("",  5, 40, 480, 575, -1, BitOr($WS_EX_CLIENTEDGE, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_SetView($LV, 1)  ;if using AutoIt >= v3.3.12.0 than use 0 instead of 1
_GUICtrlListView_SetIconSpacing($LV, 75, 60)
$hLV = GUICtrlGetHandle($LV)
$Pic = GUICtrlCreatePic("", 200, 80, 440, 440)
GUISetState(@SW_SHOW, $hGui)
$hGui_PreviewSize = 300
$hGui_Preview = GUICreate("", $hGui_PreviewSize, $hGui_PreviewSize + 58, -1, -1, $WS_POPUP + $WS_BORDER, $WS_EX_TOPMOST, $hGui)
$idPic = GUICtrlCreatePic("", 0, 0, $hGui_PreviewSize, $hGui_PreviewSize)
$idLabel_Info  = GUICtrlCreateLabel("" , 0, $hGui_PreviewSize + 8, $hGui_PreviewSize * 2, 50)
GUICtrlSetFont(-1, 10, 400, 0, "Arial", 5)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x222222)
GUISetState(@SW_HIDE, $hGui_Preview)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

$show = False
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GDIPlus_Shutdown()
            Exit
        Case $Browse
           If _Browse() Then $show = True
    EndSwitch
    If $show Then StartPreview()
    If Not WinActive($hGui) Then WinActivate($hGui)
WEnd

Func StartPreview()
    Local $hBmp_Tmp, $file, $iIndex
    $iIndex = _GUICtrlListView_GetSelectedIndices($hLV)
    $file = $FSF & _GUICtrlListView_GetItemText($hLV, $iIndex)
    Local $aPos = _GUICtrlListView_GetItemPosition($hLV, $iIndex)
    If TimerDiff($timer) < 5000 Then
        If $file_prev <> $file Then
            $hBmp_Tmp = _GetImage($file, $hGui_PreviewSize)
            _hBmpToPicControl($idPic, $hBmp_Tmp, 1)
;~          WinMove($hGui_Preview, "", $aPos[0] + $hGui_PreviewSize / 5, Min(@DesktopHeight - ($hGui_PreviewSize + 130), $aPos[1]), $hGui_PreviewSize, $hGui_PreviewSize + 58, 1)
            WinMove($hGui_Preview, "", MouseGetPos(0) - $hGui_PreviewSize - 50, MouseGetPos(1) - $hGui_PreviewSize / 2, $hGui_PreviewSize, $hGui_PreviewSize + 58, 1)
            GUISetState(@SW_SHOW, $hGui_Preview)
            $file_prev = $file
            $off = False
        EndIf
    Else
        If Not $off Then
            GUISetState(@SW_HIDE, $hGui_Preview)
            $off = True
        EndIf
    EndIf
EndFunc

Func Min($a, $b)
    If $a < $b Then Return $a
    Return $b
EndFunc

Func _Browse()
    Local $FL2A, $hBmp, $iCnt = 0
    $FSF = FileSelectFolder("Browse for folder containing pictures", "", "", $hGui)
    If Not @error And FileExists($FSF) Then
        If StringRight($FSF, 1) <> "" Then $FSF &= ""
        $FL2A = _FileListToArray($FSF, "*", 1)
        If Not @Error Then
            If IsPtr($hImageList) Then
                _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($LV))
                _GUiImageList_Destroy($hImageList)
                $hImageList = ""
                _hBmpToPicControl($Pic, $hBmp)
                GUICtrlSetImage($Pic, "")
                $iDX = -1
                $iPicState = 0
                $sCur = ""
                $sLast = ""
            EndIf
            $hImageList = _GUiImageList_Create(60, 60, 5, 3)
            _GUICtrlListView_SetImageList($LV, $hImageList, 0)
            For $i = 1 To $FL2A[0]
                If StringRegExp($FL2A[$i], "(?i).(" & $sExtFilter & ")", 0) Then
                    $hBmp = _GetImage($FSF & $FL2A[$i], 60)
                    _GUiImageList_Add($hImageList, $hBmp)
                    _WinAPI_DeleteObject($hBmp)
                    _GUICtrlListView_AddItem($LV, $FL2A[$i], $iCnt)
                    _GUICtrlListView_SetItemImage($LV, $iCnt, $iCnt)
                    $iCnt += 1
                EndIf
            Next
            GUICtrlSetData($Path, $FSF)
        EndIf
        WinSetTitle($hGui, "", "Images Found: " & $iCnt)
        Return True
    Else
        If $FSF = "" Then $show = False
        Return SetError(1, 0, False)
    EndIf
EndFunc

Func _GetImage($sFile, $iWH, $iBkClr = 0xFFFFFF)
    Local $hBmp1, $hBitmap, $hGraphic, $hImage, $iW, $iH, $aGS, $hBmp2, $aFTS
    $aFTS = FileGetTime($sFile)
    If @error Then Return SetError(1, 0, 0)
    $hBmp1 = _WinAPI_CreateBitmap($iWH, $iWH, 1, 32)
    $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp1)
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _WinAPI_DeleteObject($hBmp1)
    _GDIPlus_GraphicsClear($hGraphic, BitOR(0xFF000000, $iBkClr))
    $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    $iW = _GDIPlus_ImageGetWidth($hImage)
    $iH = _GDIPlus_ImageGetHeight($hImage)
    GUICtrlSetData($idLabel_Info, $sFile & @LF & Round(FileGetSize($sFile) / 1024, 0) & " kb (" & $iW & " x " & $iH & ")" & @LF & $aFTS[0] & "/" & $aFTS[1] & "/" & $aFTS[2] & " " & $aFTS[3] & ":" & $aFTS[4] & ":" &$aFTS[5])
    $aGS = _GetScale($iW, $iH, $iWH)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, $aGS[0], $aGS[1], $aGS[2], $aGS[3])
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
    $hBmp2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    Return $hBmp2
EndFunc

Func _GetScale($iW, $iH, $iWH)
    Local $aRet[4]
    If $iW <= $iWH And $iH <= $iWH Then
        $aRet[2] = $iW
        $aRet[3] = $iH
        $aRet[0] = ($iWH - $aRet[2])/2
        $aRet[1] = ($iWH - $aRet[3])/2
    ElseIf $iW > $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iH/($iW/$iWH)
        $aRet[0] = 0
        $aRet[1] = ($iWH - $aRet[3])/2
    ElseIf $iW < $iH Then
        $aRet[2] = $iW/($iH/$iWH)
        $aRet[3] = $iWH
        $aRet[0] = ($iWH - $aRet[2])/2
        $aRet[1] = 0
    ElseIf $iW = $iH Then
        $aRet[2] = $iWH
        $aRet[3] = $iWH
        $aRet[0] = 0
        $aRet[1] = 0
    EndIf
    Return $aRet
EndFunc

Func _hBmpToPicControl($iCID, ByRef $hBmp, $iFlag = 0)
    Local Const $STM_SETIMAGE = 0x0172
    Local Const $IMAGE_BITMAP = 0
    Local $hOldBmp
    $hOldBmp = GUICtrlSendMsg($iCID, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp)
    If $hOldBmp Then _WinAPI_DeleteObject($hOldBmp)
    If $iFlag Then _WinAPI_DeleteObject($hBmp)
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $tInfo2, $aIDX
    $hWndListView = GUICtrlGetHandle($LV)
    $tNMHDR = DllStructCreate('hwnd hWndFrom;int_ptr IDFrom;int Code', $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    $tInfo = DllStructCreate('hwnd hWndFrom;int_ptr IDFrom;int Code;int_ptr VKey;int Flags', $ilParam)
    $tInfo2 = DllStructCreate($tagNMLISTVIEW, $ilParam)
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK
                    $iDX = _GUICtrlListView_GetNextItem($hWndListView)
                    $timer = TimerInit()
                Case $NM_DBLCLK
                    $DoubleClick = _GUICtrlListView_GetNextItem($hWndListView)
                    $timer = TimerInit()
                Case $LVN_KEYDOWN
                    Switch BitAnd(DllStructGetData($tInfo, "VKey"), 0xFFFF)
                        Case $VK_UP
                            $iDX = _GUICtrlListView_GetNextItem($hWndListView) -1
                            If $iDX < 0 Then $iDX = 0
                        Case $VK_DOWN
                            $iDX = _GUICtrlListView_GetNextItem($hWndListView) + 1
                            If $iDX >= _GUICtrlListView_GetItemCount($hWndListView) Then $iDX -= 1
                    EndSwitch
                    $timer = TimerInit()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc
Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

thx :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0