michaelslamet Posted December 24, 2012 Share Posted December 24, 2012 (edited) Hi, All I have an inputbox that contain a path complete with a jpg filename. Is it possible when user move the mouse pointer to the inputbox, the application display the picture? Thanks in advance. Michael. Edited January 4, 2013 by michaelslamet Link to comment Share on other sites More sharing options...
UEZ Posted December 24, 2012 Share Posted December 24, 2012 It is possible. Checkout GUIGetCursorInfo() to get mouse hover information and e.g. GDI+ functions to display the image in a seperate GUI as a preview. Br, 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
guinness Posted December 24, 2012 Share Posted December 24, 2012 (edited) To add to what UEZ said, search _SetBitmap in the Forum too and maybe WM_HOVER. Edited December 24, 2012 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
UEZ Posted December 24, 2012 Share Posted December 24, 2012 (edited) Here one way to do it. expandcollapse popup;coded by UEZ 2012 #include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172 Global $sPathKey = "HKLM64\SOFTWARE\AutoIt v3\AutoIt\" If @OSArch = "x64" Then $sPathKey = "HKLM\SOFTWARE\Wow6432Node\AutoIt v3\AutoIt\" Global $sImage1 = RegRead($sPathKey, "InstallDir") & "\Examples\GUI\msoobe.jpg" Global $sImage2 = RegRead($sPathKey, "InstallDir") & "\Examples\GUI\Torus.png" Global $hGUI = GUICreate("Test", 300, 100) Global $iInput = GUICtrlCreateInput($sImage1, 20, 20, 200, 20) Global $iInput2 = GUICtrlCreateInput($sImage2, 20, 60, 200, 20) Global $iBtn = GUICtrlCreateButton("Exit", 240, 26, 50, 50) Global $hGui_PreviewSize = 200, $iBGColor = 0xF0F0F0 Global $hGui_Preview = GUICreate("", $hGui_PreviewSize, $hGui_PreviewSize + 58, -1, -1, $WS_POPUP + $WS_BORDER, $WS_EX_TOPMOST, $hGUI) Global $idPic = GUICtrlCreatePic("", 0, 0, $hGui_PreviewSize, $hGui_PreviewSize) Global $idLabel_Info = GUICtrlCreateLabel("", 0, $hGui_PreviewSize + 8, $hGui_PreviewSize * 2, 50) GUICtrlSetFont(-1, 9, 400, 0, "Arial", 5) GUICtrlSetColor(-1, $iBGColor) GUICtrlSetBkColor(-1, 0x222222) GUISetState(@SW_HIDE, $hGui_Preview) GUISetState(@SW_SHOW, $hGUI) ControlFocus($hGUI, "", $iBtn) Global $aMouseInfo, $aPosCtrl, $aPosWin, $hBmp_Tmp, $sFile, $bShow = False, $bHide = False Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $iBtn If $hBmp_Tmp Then _WinAPI_DeleteObject($hBmp_Tmp) _GDIPlus_Shutdown() GUIDelete($hGui_Preview) GUIDelete($hGUI) Exit EndSwitch If WinActive($hGUI) Then $aMouseInfo = GUIGetCursorInfo($hGUI) Switch $aMouseInfo[4] Case $iInput $sFile = GUICtrlRead($iInput) If FileExists($sFile) And Not $bShow Then ShowPreview($sFile, $iInput) $bShow = True $bHide = False EndIf Case $iInput2 $sFile = GUICtrlRead($iInput2) If FileExists($sFile) And Not $bShow Then ShowPreview($sFile, $iInput2) $bShow = True $bHide = False EndIf Case Else If Not $bHide Then GUISetState(@SW_HIDE, $hGui_Preview) $bHide = True EndIf $bShow = False EndSwitch EndIf Until False Func ShowPreview($sFile, $iCtrl) $aPosWin = WinGetPos($hGUI) $aPosCtrl = ControlGetPos($hGUI, "", $iCtrl) WinMove($hGui_Preview, "", $aPosWin[0] + $aPosCtrl[0] + $aPosCtrl[2], $aPosWin[1] + $aPosCtrl[1] + $aPosCtrl[3]) $hBmp_Tmp = _GetImage($sFile, $hGui_PreviewSize, $iBGColor) _hBmpToPicControl($idPic, $hBmp_Tmp, 1) GUISetState(@SW_SHOWNOACTIVATE, $hGui_Preview) EndFunc ;==>ShowPreview 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, StringRegExpReplace($sFile, ".*\\(.*)", "$1") & @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 ;==>_GetImage 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 ;==>_GetScale 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 ;==>_hBmpToPicControl Edit: added @SW_SHOWNOACTIVATE as suggested by PhoenixXL - it's smoother now. Edit2: added WinActive() check to display preview only when window is active (good catch michaelslamet) Br, UEZ Edited January 4, 2013 by UEZ AZJIO 1 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
michaelslamet Posted December 25, 2012 Author Share Posted December 25, 2012 UEZ and guinness, Many thanks for your kindness and example. I'm going to try the example, adjust it for my need and post the result here. Thanks again! :-) Link to comment Share on other sites More sharing options...
michaelslamet Posted December 25, 2012 Author Share Posted December 25, 2012 This example works perfectly! Without this sample code, I dont think I can go this far. Since I have more than a image inputbox to preview, I change the sample code to a function. It work great with 1 inputbox but when it come to more than 1 inputbox, the previewbox shown on and off (refresh) This is the code: expandcollapse popup;coded by UEZ 2012, error because of modified by michaelslamet #include <GUIConstantsEx.au3> #include <GDIPlus.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) _GDIPlus_Startup() Global Const $STM_SETIMAGE = 0x0172 Global $sPathKey = "HKLM64\SOFTWARE\AutoIt v3\AutoIt\" If @OSArch = "x64" Then $sPathKey = "HKLM\SOFTWARE\Wow6432Node\AutoIt v3\AutoIt\" Global $sImage = RegRead($sPathKey, "InstallDir") & "\Examples\GUI\msoobe.jpg" Global $hGUI = GUICreate("Test", 300, 100) Global $iInput = GUICtrlCreateInput($sImage, 20, 40, 200, 20) Global $iInput2 = GUICtrlCreateInput($sImage, 20, 70, 200, 20) Global $iBtn = GUICtrlCreateButton("Exit", 240, 26, 50, 50) Global $hGui_PreviewSize = 300 Global $hGui_Preview = GUICreate("", $hGui_PreviewSize, $hGui_PreviewSize + 58, -1, -1, $WS_POPUP + $WS_BORDER, $WS_EX_TOPMOST, $hGUI) Global $idPic = GUICtrlCreatePic("", 0, 0, $hGui_PreviewSize, $hGui_PreviewSize) Global $idLabel_Info = GUICtrlCreateLabel("" , 0, $hGui_PreviewSize + 8, $hGui_PreviewSize * 2, 50) GUICtrlSetFont(-1, 9, 400, 0, "Arial", 5) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, 0x222222) GUISetState(@SW_HIDE, $hGui_Preview) GUISetState(@SW_SHOW, $hGUI) Global $aMouseInfo, $aPosCtrl, $aPosWin, $hBmp_Tmp, $bShow = False Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $iBtn If $hBmp_Tmp Then _WinAPI_DeleteObject($hBmp_Tmp) _GDIPlus_Shutdown() GUIDelete($hGui_Preview) GUIDelete($hGUI) Exit EndSwitch DisplayPreview($iInput) DisplayPreview($iInput2) Until False 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, StringRegExpReplace($sFile, ".*\\(.*)", "$1") & @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 DisplayPreview($iInput10) $aMouseInfo = GUIGetCursorInfo($hGUI) If $aMouseInfo[4] = $iInput10 Then If FileExists(GUICtrlRead($iInput10)) And Not $bShow Then $aPosWin = WinGetPos($hGUI) $aPosCtrl = ControlGetPos($hGUI, "", $iInput10) WinMove($hGui_Preview, "", $aPosWin[0] + $aPosCtrl[0] + $aPosCtrl[2], $aPosWin[1] + $aPosCtrl[1] + $aPosCtrl[3]) $hBmp_Tmp = _GetImage(GUICtrlRead($iInput10), $hGui_PreviewSize) _hBmpToPicControl($idPic, $hBmp_Tmp, 1) GUISetState(@SW_SHOW, $hGui_Preview) $bShow = True EndIf Else GUISetState(@SW_HIDE, $hGui_Preview) $bShow = False EndIf EndFunc Link to comment Share on other sites More sharing options...
UEZ Posted December 25, 2012 Share Posted December 25, 2012 Have a look to post #4 again. Br, 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
michaelslamet Posted December 25, 2012 Author Share Posted December 25, 2012 UEZ, This is really out of my logic, I really hope someday I can program as good as you guys here, especially like UEZ and another experts. The example code works really great and I successfully implement it in my small personal used application. Thanks a lot!! Link to comment Share on other sites More sharing options...
PhoenixXL Posted December 25, 2012 Share Posted December 25, 2012 @SW_SHOWNOACTIVATE will not take the focus from the parent GUI My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
michaelslamet Posted January 4, 2013 Author Share Posted January 4, 2013 Hi UEZ, I need help again regarding this topic. When this application run, and then I activate another application/window (so this application run in the background), when the mouse move to filename area, it will bring the application to the foreground and display/preview the image. This is pretty annoying. Any idea how to solve this? Thanks a lot Link to comment Share on other sites More sharing options...
michaelslamet Posted January 4, 2013 Author Share Posted January 4, 2013 Ok, got it I check if the application window active before preview. If it is not then dont preview. was: GUISetState(@SW_SHOWNOACTIVATE, $hGui_Preview) now: If WinGetState($judul_sw) = 15 Then GUISetState(@SW_SHOWNOACTIVATE, $hGui_Preview) EndIf Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now