Jump to content
wuruoyu

[SOLVED] _GUICtrlToolbar_SetButtonSize cannot retain its size after switching user in Windows 10

Recommended Posts

Issue: Toolbar buttons cannot retain its size after switching user in Windows 10

To replicate the issue:

1. Run script
2. Switch user (Alt + F4 from Desktop)
3. Log in to the same account

Thank you!

#NoTrayIcon
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIToolbar.au3>
#include <GUIImageList.au3>

Opt("GUIOnEventMode", 1)

_main()

Func _main()
    $main = GUICreate("main", 268, 100)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
    GUISetState()

    $ToolbarGUI = GUICreate('', 250, 62, 1, 1, $WS_CHILD, 0, $main)
    $Toolbar = _GUICtrlToolbar_Create($ToolbarGUI, BitOR($BTNS_BUTTON, $BTNS_SHOWTEXT, $TBSTYLE_FLAT, $TBSTYLE_TOOLTIPS), $TBSTYLE_EX_DOUBLEBUFFER)
    $ToolbarImageList = _GUIImageList_Create(32, 32, 5, 3, 2)
    _GUIImageList_AddIcon($ToolbarImageList, "C:\Windows\System32\mmc.exe", 0, 1)
    _GUIImageList_AddIcon($ToolbarImageList, "C:\Windows\System32\cmd.exe", 0, 1)
    _GUICtrlToolbar_SetImageList($Toolbar, $ToolbarImageList)

    _GUICtrlToolbar_AddButton($Toolbar, 10000, 0, 0)
    _GUICtrlToolbar_AddButton($Toolbar, 10001, 1, 1)
    _GUICtrlToolbar_SetButtonSize($Toolbar, 62, 50)
    _GUICtrlToolbar_SetMetrics($Toolbar, 0, 0, 1, 0)
    _GUICtrlToolbar_SetIndent($Toolbar, 1)
    _SendMessage($Toolbar, $TB_AUTOSIZE)

    GUISwitch($main)

    GUICtrlCreateLabel('', 0, 63, 368, 2, $SS_ETCHEDHORZ)

    GUISetState(@SW_SHOWNOACTIVATE, $ToolbarGUI)


    GUISetState(@SW_SHOW, $main)

    While 1
        Sleep(100)
    WEnd
EndFunc   ;==>_main


Func _exit()
    Exit
EndFunc   ;==>_exit

 

before.PNG

after.PNG

Edited by wuruoyu

Share this post


Link to post
Share on other sites

Sigh...It seems to be another idiosyncrasies (not to say bug) of Win 10.  You will need to redraw the buttons when it is newly painted.  Something like this seems to work fine :

#NoTrayIcon
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIToolbar.au3>
#include <GUIImageList.au3>

Opt("GUIOnEventMode", 1)

_main()

Func _main()
  Global $main = GUICreate("main", 268, 100)
  GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
  GUISetState()

  Global $ToolbarGUI = GUICreate('', 250, 62, 1, 1, $WS_CHILD, 0, $main)
  Global $Toolbar = _GUICtrlToolbar_Create($ToolbarGUI, BitOR($BTNS_BUTTON, $BTNS_SHOWTEXT, $TBSTYLE_FLAT, $TBSTYLE_TOOLTIPS), $TBSTYLE_EX_DOUBLEBUFFER)
  $ToolbarImageList = _GUIImageList_Create(32, 32, 5, 3, 2)
  _GUIImageList_AddIcon($ToolbarImageList, "C:\Windows\System32\mmc.exe", 0, 1)
  _GUIImageList_AddIcon($ToolbarImageList, "C:\Windows\System32\cmd.exe", 0, 1)
  _GUICtrlToolbar_SetImageList($Toolbar, $ToolbarImageList)

  _GUICtrlToolbar_AddButton($Toolbar, 10000, 0, 0)
  _GUICtrlToolbar_AddButton($Toolbar, 10001, 1, 1)
  _GUICtrlToolbar_SetButtonSize($Toolbar, 62, 50)
  _GUICtrlToolbar_SetMetrics($Toolbar, 0, 0, 1, 0)
  _GUICtrlToolbar_SetIndent($Toolbar, 1)
  _SendMessage($Toolbar, $TB_AUTOSIZE)

  GUISwitch($main)
  GUICtrlCreateLabel('', 0, 63, 368, 2, $SS_ETCHEDHORZ)

  GUISetState(@SW_SHOWNOACTIVATE, $ToolbarGUI)
  GUIRegisterMsg($WM_PAINT, "_WM_PAINT")
  GUISetState(@SW_SHOW, $main)

  While 1
    Sleep(100)
  WEnd
EndFunc   ;==>_main

Func _WM_PAINT($hWnd, $iMsg, $wParam, $lParam)
  If $hWnd = $ToolbarGUI Then
    _GUICtrlToolbar_SetButtonSize($Toolbar, 62, 50)
    _GUICtrlToolbar_SetMetrics($Toolbar, 0, 0, 1, 0)
    _GUICtrlToolbar_SetIndent($Toolbar, 1)
    _SendMessage($Toolbar, $TB_AUTOSIZE)
  EndIf
  Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_PAINT

Func _exit()
  Exit
EndFunc   ;==>_exit

 

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...