Jump to content

Taskbar Live Preview - Thumbnail not updating


spudw2k
 Share

Go to solution Solved by Nine,

Recommended Posts

I have an issue with the live preview not updating to reflect the GUI state.  I have a script demo below to illustrate the problem I am having. 

Symptoms / Behavior

1) Text field is masked when it is not focused
2) If the text field is unmasked when the GUI is minimized, the text field should become masked when GUI is minimized (via WM_ACTIVATE) but the live preview still shows the input field unmasked

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>

Opt("GUIOnEventMode", 1)

Dim $aGUI[1] = ["hwnd|id"]
Enum $hGUI = 1, $idInput, $idBtn, $iGUILast
ReDim $aGUI[$iGUILast]

#Region - UI Creation
$aGUI[$hGUI] = GUICreate("Demo", 508, 130, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU, $WS_MINIMIZEBOX))
$aGUI[$idInput] = GUICtrlCreateInput("This will mask when focus is lost", 22, 22, 462, 34, BitOR($SS_CENTER, $ES_PASSWORD))
GUICtrlSetFont(-1, 18, $FW_BOLD, Default, "Consolas")
Const $ES_PASSWORDCHAR = GUICtrlSendMsg(-1, $EM_GETPASSWORDCHAR, 0, 0)
$aGUI[$idBtn] = GUICtrlCreateButton("Button", 220, 80, 60, 30)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_ACTIVATE, "WM_ACTIVATE")
GUISetOnEvent($GUI_EVENT_CLOSE, "GUIEvents")
#EndRegion - UI Creation

Show()
GUISetState(@SW_SHOW)

While 1
    Sleep(10)
WEnd

#Region - UI Event Functions
Func GUIEvents()
    $iCtrl = @GUI_CtrlId
    Switch $iCtrl
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
EndFunc   ;==>GUIEvents

Func GUIMinimize()
    Hide()
    GUISetState(@SW_MINIMIZE)
EndFunc   ;==>GUIMinimize

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $iIDFrom = BitAND($wParam, 0xFFFF) ; LoWord - this gives the control which sent the message
    Local $iCode = BitShift($wParam, 16) ; HiWord - this gives the message that was sent
    Switch $iCode
        Case $EN_SETFOCUS
            Switch $iIDFrom
                Case $aGUI[$idInput]
                    Show()
            EndSwitch
        Case $EN_KILLFOCUS
            Switch $iIDFrom
                Case $aGUI[$idInput]
                    Hide()
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_COMMAND

Func WM_ACTIVATE($hWnd, $iMsg, $wParam, $lParam)
    Local $iCode = BitAND($wParam, 0xFFFF)
    Switch $hWnd
        Case $aGUI[$hGUI]
            Switch $iCode
                Case 0 ; WA_INACTIVE
                    Hide()
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_ACTIVATE
#EndRegion - UI Event Functions

#Region - Additonal Functions
Func InputboxMask($iCtrl, $bMask = True)
    Switch $bMask
        Case False
            GUICtrlSendMsg($iCtrl, $EM_SETPASSWORDCHAR, 0, 0)
        Case True
            GUICtrlSendMsg($iCtrl, $EM_SETPASSWORDCHAR, $ES_PASSWORDCHAR, 0)
    EndSwitch
    Local $aRes = DllCall("user32.dll", "int", "RedrawWindow", "hwnd", GUICtrlGetHandle($iCtrl), "ptr", 0, "ptr", 0, "dword", 5)
EndFunc   ;==>InputboxMask

Func Hide()
    GUICtrlSetState($aGUI[$idBtn], $GUI_FOCUS)
    InputboxMask($aGUI[$idInput])
EndFunc   ;==>Hide

Func Show()
    InputboxMask($aGUI[$idInput], False)
EndFunc   ;==>Show
#EndRegion - Additonal Functions

 

I am hoping either there is a way to intercept the minimize event and handle it on my own after masking the field, or a way to update the thumbnail.  Any help would be much appreciated.

 

 

Edit: I don't have a working solution yet, but it seems that the function below and associated example is a good place for me to explore.

_WinAPI_DwmSetIconicLivePreviewBitmap()

 

Edited by spudw2k
Link to comment
Share on other sites

  • Solution

This works well for me :

#include <GUIConstants.au3>
#include <Constants.au3>
#include <FontConstants.au3>
#include <WinAPIGdi.au3>

Opt("GUIOnEventMode", 1)
Opt("GUIEventOptions", 1)

Dim $aGUI[1] = ["hwnd|id"]
Enum $hGUI = 1, $idInput, $idBtn, $iGUILast
ReDim $aGUI[$iGUILast]

#Region - UI Creation
$aGUI[$hGUI] = GUICreate("Demo", 508, 130, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU, $WS_MINIMIZEBOX))
$aGUI[$idInput] = GUICtrlCreateInput("This will mask when focus is lost", 22, 22, 462, 34, BitOR($SS_CENTER, $ES_PASSWORD))
GUICtrlSetFont(-1, 18, $FW_BOLD, Default, "Consolas")
Const $ES_PASSWORDCHAR = GUICtrlSendMsg(-1, $EM_GETPASSWORDCHAR, 0, 0)
$aGUI[$idBtn] = GUICtrlCreateButton("Button", 220, 80, 60, 30)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUISetOnEvent($GUI_EVENT_CLOSE, GUIEvents)
GUISetOnEvent($GUI_EVENT_MINIMIZE, GUIEvents)
GUISetOnEvent($GUI_EVENT_RESTORE, GUIEvents)
#EndRegion - UI Creation

Show()
GUISetState(@SW_SHOW)

While 1
  Sleep(10)
WEnd

#Region - UI Event Functions
Func GUIEvents()
  $iCtrl = @GUI_CtrlId
  Switch $iCtrl
    Case $GUI_EVENT_CLOSE
      Exit
    Case $GUI_EVENT_MINIMIZE
      GUICtrlSendMsg($aGUI[$idInput], $EM_SETSEL, 0, -1)
      GUISetState(@SW_MINIMIZE)
    Case $GUI_EVENT_RESTORE
      GUISetState(@SW_RESTORE)
  EndSwitch
EndFunc   ;==>GUIEvents

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
  Local $iIDFrom = BitAND($wParam, 0xFFFF)   ; LoWord - this gives the control which sent the message
  Local $iCode = BitShift($wParam, 16)   ; HiWord - this gives the message that was sent
  Switch $iCode
    Case $EN_SETFOCUS
      Switch $iIDFrom
        Case $aGUI[$idInput]
          Show()
      EndSwitch
    Case $EN_KILLFOCUS
      Switch $iIDFrom
        Case $aGUI[$idInput]
          Hide()
      EndSwitch
  EndSwitch
  return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

#EndRegion - UI Event Functions

#Region - Additonal Functions
Func InputboxMask($iCtrl, $bMask = True)
  Switch $bMask
    Case False
      GUICtrlSendMsg($iCtrl, $EM_SETPASSWORDCHAR, 0, 0)
    Case True
      GUICtrlSendMsg($iCtrl, $EM_SETPASSWORDCHAR, $ES_PASSWORDCHAR, 0)
  EndSwitch
  _WinAPI_RedrawWindow($aGUI[$hGUI], 0, 0, $RDW_UPDATENOW)
EndFunc   ;==>InputboxMask

Func Hide()
  InputboxMask($aGUI[$idInput])
EndFunc   ;==>Hide

Func Show()
  InputboxMask($aGUI[$idInput], False)
EndFunc   ;==>Show
#EndRegion - Additonal Functions

 

Link to comment
Share on other sites

Link to comment
Share on other sites

22 hours ago, Nine said:

Not quite.  GUICtrlSendMsg($aGUI[$idInput], $EM_SETSEL, 0, -1) is the key.

Not for my purposes necessarily.   I just needed a way to handle the minimize event, so the GUIEventOptions allowed me to do that (in combination with registering the Minimize and Restore events)...unless I am missing something?

Regardless, you led me to a solution to my problem, and I thank you for that.  I may still play around with the DWM Live Preview stuff in the future--could come in handy. ;) 

Link to comment
Share on other sites

  • spudw2k changed the title to Taskbar Live Preview - Thumbnail not updating

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...