Sign in to follow this  
Followers 0
mpower

Whole GUI flicker on resize

13 posts in this topic

#1 ·  Posted (edited)

Hi peeps, are you able to please help me out with reducing/eliminating the flicker when the GUI is being resized?

The example is attached. 

Reason for zip is that I'm using a couple of UDFs (namely: Ribbon bar and ModernMenuRaw so I've included them in the attached archive).

Source here:

#Region ### includes ###
#include-once
#NoTrayIcon
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Ribbonsbar.au3>
#include <GuiListView.au3>
#include <EditConstants.au3>
#EndRegion ### includes ###

Opt("GUIResizeMode", 802)
Global $appname = 'Example App', $appver = '1.0', $additemsgui_W = 400, $additemsgui_H = 150

#Region ### $maingui ###
$maingui = GUICreate($appname & ' ' & $appver, @DesktopWidth, 600, -1, -1, BitOr($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
$hBar = _RibbonsBar_Create($maingui, 0, 0, 0, 0, 'blue')
$hTab_Home = _RibbonsBar_Create_Tab($hBar, 'Home')
$hItem_FileOps = _RibbonsBar_Create_TabItem($hTab_Home, 'File operations' , 225 )
$hGrandButton_New = _RibbonsBar_Create_GrandButton($hItem_FileOps,'',412,'New',52, True )
_RibbonsBar_GrandButtons_Enable($hGrandButton_New, 0)
$hDropDownNew = _RibbonsBar_Create_ContextMenu($hGrandButton_New)
$hDropDownNew_1 = _GUICtrlCreateODMenuItem("Standard ...", $hDropDownNew, "smallIcons.dll", 261)
$hDropDownNew_2 = _GUICtrlCreateODMenuItem("Manual ...", $hDropDownNew, "smallIcons.dll", 382)
$hGrandButton_Open = _RibbonsBar_Create_GrandButton($hItem_FileOps,'',453,'Open',52, False )
_RibbonsBar_GrandButtons_Enable($hGrandButton_Open, 0)
$hGrandButton_Save = _RibbonsBar_Create_GrandButton($hItem_FileOps,'',514,'Save',52, True )
_RibbonsBar_GrandButtons_Enable($hGrandButton_Save, 0)
$hDropDownSave = _RibbonsBar_Create_ContextMenu($hGrandButton_Save)
$hDropDownSave_1 = _GUICtrlCreateODMenuItem("Save", $hDropDownSave, "smallIcons.dll", 287)
$hDropDownSave_2 = _GUICtrlCreateODMenuItem("Save As ...", $hDropDownSave, "smallIcons.dll", 286)
$hGrandButton_Export = _RibbonsBar_Create_GrandButton($hItem_FileOps,'',337,'Export',62, True )
_RibbonsBar_GrandButtons_Enable($hGrandButton_Export, 0)
$hDropDownExport = _RibbonsBar_Create_ContextMenu($hGrandButton_Export)
$hDropDownExport_1 = _GUICtrlCreateODMenuItem("To Excel", $hDropDownExport, "smallIcons.dll", 1243)
$hItem_ItemOps = _RibbonsBar_Create_TabItem ( $hTab_Home, 'Item operations' , 393 )
$hGrandButton_AddItems = _RibbonsBar_Create_GrandButton($hItem_ItemOps,'',301,'Add item(s)',72, True )
$hDropDownAddItems = _RibbonsBar_Create_ContextMenu($hGrandButton_AddItems)
_RibbonsBar_GrandButtons_Enable($hGrandButton_AddItems, 0)
$hDropDownAddItems_1 = _GUICtrlCreateODMenuItem("From Catalogue", $hDropDownAddItems, "smallIcons.dll", 173)
$hDropDownAddItems_2 = _GUICtrlCreateODMenuItem("From Quote", $hDropDownAddItems, "smallIcons.dll", 143)
$hDropDownAddItems_3 = _GUICtrlCreateODMenuItem("Paste", $hDropDownAddItems, "smallIcons.dll", 9)
$hGrandButton_DelItems = _RibbonsBar_Create_GrandButton($hItem_ItemOps,'',615,'Delete item(s)',82, False )
_RibbonsBar_GrandButtons_Enable($hGrandButton_DelItems, 0)
$SmallButton_Undo = _RibbonsBar_Create_SmallButton($hItem_ItemOps,'',728,1,'Undo (Test: click to enable grand buttons)',230)
$SmallButton_Redo = _RibbonsBar_Create_SmallButton($hItem_ItemOps,'',194,2,'Redo (Test: click to disable grand buttons)',230)
_RibbonsBar_SmallButtons_Enable($SmallButton_Redo, 0)
$hTab_Help = _RibbonsBar_Create_Tab( $hBar, 'Help' )
$hItem_Information = _RibbonsBar_Create_TabItem ( $hTab_Help, 'Information' , 120 )
$hGrandButton_About = _RibbonsBar_Create_GrandButton($hItem_Information,'',631,'Help','',False)
$hGrandButton_About = _RibbonsBar_Create_GrandButton($hItem_Information,'',644,'About','',False)
_RibbonsBar_Tab_SetState($hTab_Home)
GUISwitch($maingui)
WinMove($maingui, "", Default, Default, 800, Default)
$wPos = WinGetPos($maingui)
WinMove($maingui, "", @DesktopWidth/2 - $wPos[2]/2, @DesktopHeight/2 - $wPos[3]/2, Default, Default)
$wPos = WinGetPos($maingui)
$mainlistview = GUICtrlCreateListView('Col 1|Col 2|Col 3|Col 4|Col 5|Col 6', -2, 120, _
                $wPos[2], $wPos[3], Default)
_GUICtrlListView_SetExtendedListViewStyle($mainlistview, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES, $LVS_EX_FLATSB))
_GUICtrlListView_SetColumnWidth($mainlistview, 0, 120)
_GUICtrlListView_SetColumnWidth($mainlistview, 1, 250)
_GUICtrlListView_SetColumnWidth($mainlistview, 2, 50)
_GUICtrlListView_SetColumnWidth($mainlistview, 3, 100)
_GUICtrlListView_SetColumnWidth($mainlistview, 4, 100)
_GUICtrlListView_SetColumnWidth($mainlistview, 5, 50)
#EndRegion ### $additemsgui ###

#Region ### $additemsgui ###
$additemsgui = GUICreate('Add item(s) from Catalogue', $additemsgui_W, $additemsgui_H, 0, 0, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX), $WS_EX_MDICHILD, $maingui)
GUISetBkColor(0xf2f8ff)
GUISetFont(10, 400)
$additems_addlabel = GUICtrlCreateLabel('Start typing below to add item(s) from catalogue (min 2 chars):', 10, 15, $additemsgui_W - 20, 21)
$additemsinput = GUICtrlCreateInput('', 10, 45, $additemsgui_W - 20, Default)
GUICtrlSendMsg(-1, $EM_SETCUEBANNER, False, 'Enter an item number here')
$additemsbn_add = GUICtrlCreateButton('Add', 10, 85, 110, 40)
#EndRegion ### $additemsgui ###


GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO") ; Register WM_GETMINMAXINFO
GUISetState(@SW_SHOW, $maingui)

GUICtrlSetResizing($mainlistview, BitOR($GUI_DOCKLEFT, $GUI_DOCKRIGHT, $GUI_DOCKTOP))

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $maingui
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
                Case $hDropDownAddItems_1
                    GUISetState(@SW_DISABLE, $maingui)
                    $mPos = WinGetPos($maingui)
                    WinMove($additemsgui, '', $mPos[0] + (($mPos[2]/2) - ($additemsgui_W/2)), $mPos[1] + (($mPos[3]/2) - ($additemsgui_H/2)))
                    GUICtrlSetData($additemsinput, '')
                    GUISetState(@SW_SHOW, $additemsgui)
                    _WinAPI_SetFocus(ControlGetHandle('', '', $additems_addlabel))
                Case $hDropDownNew_1
                    ConsoleWrite('Clicked "New" menu item 1'&@CRLF)
                Case $hDropDownNew_2
                    ConsoleWrite('Clicked "New" menu item 2'&@CRLF)
            EndSwitch
        Case $additemsgui
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUISetState(@SW_ENABLE, $maingui)
                    GUISetState(@SW_HIDE, $additemsgui)
            EndSwitch
    EndSwitch
    Switch _RibbonsBar_GetMsg()
        Case $hGrandButton_Open
            ConsoleWrite('open...'&@CRLF)
        Case $SmallButton_Undo
            _RibbonsBar_GrandButtons_Enable($hGrandButton_New, 1)
            _RibbonsBar_GrandButtons_Enable($hGrandButton_Save, 1)
            _RibbonsBar_GrandButtons_Enable($hGrandButton_Export, 1)
            _RibbonsBar_GrandButtons_Enable($hGrandButton_AddItems, 1)
            _RibbonsBar_GrandButtons_Enable($hGrandButton_DelItems, 1)
            _RibbonsBar_GrandButtons_Enable($hGrandButton_Open, 1)
            If _RibbonsBar_SmallButtons_GetState($SmallButton_Undo) = 1 Then
                ConsoleWrite('undo...'&@CRLF)
            EndIf
        Case $SmallButton_Redo
            _RibbonsBar_GrandButtons_Enable($hGrandButton_New, 0)
            _RibbonsBar_GrandButtons_Enable($hGrandButton_Save, 0)
            _RibbonsBar_GrandButtons_Enable($hGrandButton_Export, 0)
            _RibbonsBar_GrandButtons_Enable($hGrandButton_AddItems, 0)
            _RibbonsBar_GrandButtons_Enable($hGrandButton_DelItems, 0)
            _RibbonsBar_GrandButtons_Enable($hGrandButton_Open, 0)
            If _RibbonsBar_SmallButtons_GetState($SmallButton_Redo) = 1 Then
                ConsoleWrite('redo...'&@CRLF)
            EndIf
        Case $hTab_Home
            _RibbonsBar_Tab_SetState($hTab_Home)
        Case $hGrandButton_Export
            _RibbonsBar_ContextMenu_SetState($hDropDownExport)
        Case $hGrandButton_Save
            _RibbonsBar_ContextMenu_SetState($hDropDownSave)
        Case $hGrandButton_AddItems
            _RibbonsBar_ContextMenu_SetState($hDropDownAddItems)
        Case $hGrandButton_New
            _RibbonsBar_ContextMenu_SetState($hDropDownNew)
        Case $hTab_Help
            _RibbonsBar_Tab_SetState($hTab_Help)
    EndSwitch
WEnd

Func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam)
    If $hWnd = $maingui Then
        $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
        DllStructSetData($tagMaxinfo, 7,  800) ; W (min size)
        DllStructSetData($tagMaxinfo, 8,  600) ; H (min size)
        Return 0
    EndIf
EndFunc   ;==>WM_GETMINMAXINFO

Thanks heaps in advance!

example.zip

Edited by mpower

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

lots of downloads already..... just wondering if anyone had any problems in getting it to run or anything? any ideas on how to reduce/eliminate the flicker?

Edited by mpower

Share this post


Link to post
Share on other sites

no luck?

Share this post


Link to post
Share on other sites

I see that your main control is a listview. Some GUI styles can reduce listview flicker significantly.

Here is an example with a lot of flicker:

#Include <GuiListView.au3>
#Include <WindowsConstants.au3>
#Include <GUIConstantsEx.au3>

$maingui = GUICreate('Test', @DesktopWidth/2, @DesktopHeight/2, _
  @DesktopWidth/2 - (@DesktopWidth/2)/2, @DesktopHeight/2 - (@DesktopHeight/2)/2, _
  BitOR($WS_SIZEBOX,$WS_TABSTOP,$WS_MINIMIZEBOX))

$maingui_lv = GUICtrlCreateListView('Col 1|Col 2|Col 3|Col 4|Col 5|Col 6|Col 7|Col 8|Col 9', _
  0, 0, @DesktopWidth/2, @DesktopHeight/2 - 23, _
  BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS))

_GUICtrlListView_SetExtendedListViewStyle($maingui_lv, _
  BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES))

GUICtrlSetResizing($maingui_lv, $GUI_DOCKBORDERS) ; Prevents horizontal scrollbar

For $i = 0 To 100
  GUICtrlCreateListViewItem( _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) , $maingui_lv)
Next

GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
  Local $iWidth
  $iWidth = BitAND($lParam, 0xFFFF) ; _WinAPI_LoWord
  _GUICtrlListView_SetColumnWidth($maingui_lv, 0, ($iWidth-17)*0.20)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 1, ($iWidth-17)*0.30)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 2, ($iWidth-17)*0.03)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 3, ($iWidth-17)*0.08)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 4, ($iWidth-17)*0.07)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 5, ($iWidth-17)*0.07)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 6, ($iWidth-17)*0.10)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 7, ($iWidth-17)*0.10)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 8, ($iWidth-17)*0.05)
  Return $GUI_RUNDEFMSG
EndFunc

Here is the same example with $WS_CLIPCHILDREN style on the GUI and $WS_EX_COMPOSITED on the listview.

#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

$maingui = GUICreate('Test', @DesktopWidth/2, @DesktopHeight/2, _
  @DesktopWidth/2 - (@DesktopWidth/2)/2, @DesktopHeight/2 - (@DesktopHeight/2)/2, _
  $WS_OVERLAPPEDWINDOW + $WS_CLIPCHILDREN)

; $WS_CLIPCHILDREN and $WS_EX_COMPOSITED reduces flicker
; $WS_EX_COMPOSITED is not compatible with a header

$maingui_lv = GUICtrlCreateListView('Col 1|Col 2|Col 3|Col 4|Col 5|Col 6|Col 7|Col 8|Col 9', _
  0, 0, @DesktopWidth/2, @DesktopHeight/2, _
  BitOR($LVS_NOCOLUMNHEADER, $LVS_REPORT, $LVS_SHOWSELALWAYS), _
  $WS_EX_COMPOSITED)

_GUICtrlListView_SetExtendedListViewStyle($maingui_lv, _
  BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES))

GUICtrlSetResizing($maingui_lv, $GUI_DOCKBORDERS) ; Prevents horizontal scrollbar

For $i = 0 To 100
  GUICtrlCreateListViewItem( _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) &"|"& _
  Random(0 ,1000000, 1) , $maingui_lv)
Next

_GUICtrlListView_SetColumnWidth($maingui_lv, 0, (@DesktopWidth/2 - 17) * 0.20)
_GUICtrlListView_SetColumnWidth($maingui_lv, 1, (@DesktopWidth/2 - 17) * 0.30)
_GUICtrlListView_SetColumnWidth($maingui_lv, 2, (@DesktopWidth/2 - 17) * 0.03)
_GUICtrlListView_SetColumnWidth($maingui_lv, 3, (@DesktopWidth/2 - 17) * 0.08)
_GUICtrlListView_SetColumnWidth($maingui_lv, 4, (@DesktopWidth/2 - 17) * 0.07)
_GUICtrlListView_SetColumnWidth($maingui_lv, 5, (@DesktopWidth/2 - 17) * 0.07)
_GUICtrlListView_SetColumnWidth($maingui_lv, 6, (@DesktopWidth/2 - 17) * 0.10)
_GUICtrlListView_SetColumnWidth($maingui_lv, 7, (@DesktopWidth/2 - 17) * 0.10)
_GUICtrlListView_SetColumnWidth($maingui_lv, 8, (@DesktopWidth/2 - 17) * 0.05)

GUISetState()
GUIRegisterMsg($WM_SIZE, "WM_SIZE")

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_SIZE($hWnd, $msg, $wParam, $lParam)
  Local $iHeight, $iWidth
  $iWidth = BitAND($lParam, 0xFFFF) ; _WinAPI_LoWord
  $iHeight = BitShift($lParam, 16) ; _WinAPI_HiWord
  _GUICtrlListView_SetColumnWidth($maingui_lv, 0, ($iWidth - 17) * 0.20)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 1, ($iWidth - 17) * 0.30)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 2, ($iWidth - 17) * 0.03)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 3, ($iWidth - 17) * 0.08)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 4, ($iWidth - 17) * 0.07)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 5, ($iWidth - 17) * 0.07)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 6, ($iWidth - 17) * 0.10)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 7, ($iWidth - 17) * 0.10)
  _GUICtrlListView_SetColumnWidth($maingui_lv, 8, ($iWidth - 17) * 0.05)
  _WinAPI_MoveWindow($maingui_lv, 0, 0, $iWidth, $iHeight)
  Return $GUI_RUNDEFMSG
EndFunc
Because of _WinAPI_MoveWindow in WM_SIZE function this example is more CPU/GPU intensive while you are resizing.

Unfortunately $WS_EX_COMPOSITED is not compatible with a header. If you need a header, you can add a header control, or you can add an empty listview with only the header. In both cases you have to take care of synchronization.

But this will not help at the flicker in the toolbar.

The easiest way to get rid of all flicker is probably to use a resizing technique, where you only see the window border, while you are resizing with the mouse. The window is resized when you release the mouse button. Take a look at the green post in this thread.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

@LarsJ: It's not the main problem. The OP's script is perfect, all the wrong belong to AutoIt!

@mpower: Luckily, we can fix it!

The first problem:

Not sure why AutoIt throw CS_HREDRAW and CS_VREDRAW style flag into its class "AutoIt v3 GUI". Those flags force the GUI repaint every time you resize it, and every controls of it must be repainted too.

This line will fix it:

_WinAPI_SetClassLongEx($maingui, $GCL_STYLE, BitAND(_WinAPI_GetClassLongEx($maingui, $GCL_STYLE), BitNOT(1), BitNOT(2)))

1 and 2 is the value of CS_HREDRAW and CS_VREDRAW. So the above line will unset those flags.

Be sure to include <WinAPI.au3> or you will get error messages.

The second problem:

The resizing handling of AutoIt is terrible. If implemented right, your controls and GUI should not flickring. But it was done wrong. So you have 2 options:

1. Do as @LarsJ sugguest, add $WS_CLIPCHILDREN when you create the $maingui. It should work immediately, all the GUI, and the listview no longer flicker. 

But, when you resize, you can see, some part near the top-right corner of the listview is not repainted, now welcome to the tearing problem.

Since the GUI now don't take care of painting its children, if you resize GUI fast enough, the region which the GUI marks that it should not paint and leave for controls, in our case, is the listview, is not same as the position of the listview. If good, it's smaller. If bad, it's larger, and some part of the GUI is not painted by both the GUI, and the listview. 

2. Bypass AutoIt auto resize, manually resize yourself. By intercept the WM_SIZE message. Since your script has only a control (the listview) need to be resized, everything should be simple. (The ribbon is resize automatically so we don't need to care)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

Func WM_SIZE($hwnd, $uMsg, $wParam, $lParam)
    _WinAPI_SetWindowPos(GUICtrlGetHandle($mainlistview), 0, 0, 0, _WinAPI_LoWord($lParam), _WinAPI_HiWord($lParam)-120, _
                BitOR($SWP_NOMOVE, $SWP_NOZORDER))
    Return 1
EndFunc

Now, the GUI is no longer flickering, but the listview is still. Strange?

You can add a flag: $SWP_NOREDRAW to make the listview not repaint itself. But again, you met the tearing guy, since your control is not painted correctly. To solve that, you need to read the third problem

The third problem:

One more time, AutoIt do an odd strange thing: throw the $WS_EX_TRANSPARENT into the ex-style of the listview.

This flag, while it cannot make the control (in our case, the listview) transparent, but can make transparent is possible, if you do right. You can read about this flag in http://blogs.msdn.com/b/oldnewthing/archive/2012/12/17/10378525.aspx

Beside being painted after all the non WS_EX_TRANSPARENT siblings, it also make the parent is painted before, compare with after in normal case.

So, the parent paint itself. Because we have not $WS_EX_CLIPCHILDREN flag, it also ask for it controls paint. The listview also be painted.

After that, the listview is painted, twice, because it has WS_EX_TRANSPARENT! And we get flickering!

So, manually set the ex-style of the listview instead of leaving default. It should be:

$mainlistview = GUICtrlCreateListView('Col 1|Col 2|Col 3|Col 4|Col 5|Col 6', 0, 120, _
                $wPos[2], $wPos[3] - 120, -1, 0x200)

Everything should be OK now. Cheer!

Edited by binhnx
1 person likes this

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites

Listviews in autoit do NOT have WS_EX_TRANSPARENT set by default, that is a Window style setting, not a listview style setting. ListViews use the same value as WS_EX_TRANSPARENT set by default, but that setting is for $LVS_EX_FULLROWSELECT which is a ListView extended style setting. Just because the values are the same does not mean the results are the same.

Also, I'm not sure where you got the CS_HREDRAW and CS_VREDRAW idea from but according to the help file the only style that is forced for a GUI is $WS_EX_WINDOWEDGE and the value of that is 0x00000100, and not 0x00000003, and also according to the help file you can disable that by using -1 in the Extended Style parameter of GUICreate.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

@BrewmanNH:

1. A simple script may make everything clear that AutoIt did or did not:

GUICreate("TEST")
GUICtrlCreateListView("1|2", 0, 0, 350, 350)

While GUIGetMsg() <> -3
  Sleep(10)
WEnd

Check the style. I agree that WS_EX_TRANSPARENT and LVS_EX_FULLROWSELECT has the same value of Hex(0x20) = Int(32), but it's not the same. Window Style/ExStyle is set when creating the window, the control is a window, in Win32 too. It can also be set with SetWindowLong

LVS_EX_FULLROWSELECT is specific style to the listview only, and it cannot be set with SetWindowLong, but using a specified window message, LVM_SETEXTENDEDLISTVIEWSTYLE, and be wrapped in AutoIt by 

_GUICtrlListView_SetExtendedListViewStyle

The OP did everything correctly, but get the un-expected result

2. CS_HREDRAW and CS_VREDRAW is class style, not window style. It cannot be set when creating a window, but when registering the class. So any AutoIt window with class name "AutoIt v3 GUI" should have the same class style. And it actually has the same class style, except you manually re-set it, as I did


99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites

So, you agree with me that you're wrong about WS_EX_TRANSPARENT? Good, glad we're on the same page. ListViews use LV style settings and GUIs use WS style settings and they don't affect each other. So setting a Listview with the FullRowSelect style has nothing whatsoever to do with WS_EX_TRANSPARENT.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

@BrewmanNH: Sadly that not :((

OK, I guess I need to clarify more details about this.

First, every window (GUI) or control, with Windows, should be one window, managed by a window handle (HWND)

Any window does have Style, ExStyle. You can get it with GetWindowLong(A/W) in Windows 32bit and GetWindowLongPtr(A/W) in Windows 64bit. That functions lives in user32.dll. AutoIt wrap it in WinAPI.au3, both, as _WinAPI_GetWindowLong. Similarly, SetWindowLong(A/W) (32bit) and SetWindowLongPtr(A/W) (64bit) are wrapped to _WinAPI_SetWindowLong. All that share style/ex-style have the same prefix $WS_... (with style) and $WS_EX_... (with ex-style). So everywindow, as the word of Win32, or every GUI and control, as the word of AutoIt can have $WS_... style and $WS_EX_... ex-style

Any window can have a specified set of style, like buttons have a set of $BS_..., a listviews have a set of $LVS_... This is normal style and can be set by Get/SetWindowLong function.

Beside that, some specified control, such as ListView, has its set of specific ex-style. This is not related to the normal Window style/ex-style, and also cannot using the Set/GetWindowLong function to deal with it. To set/get that ex-style, you send a specified message to the specified control. AutoIt also wrap it it GUIListView.au3. Open that file, and scroll to the _GUICtrlListView_SetExtendedListViewStyle and GUICtrlListView_GetExtendedListViewStyle functions, you will see how it is implemented.

$WS_EX_TRANSPARENT is totally different with $LVS_EX_FULLROWSELECT. You using SetWindowLong() to set $WS_EX_TRANSPARENT, and GetWindowLong() to get the ex-style, bitor to see it has the flag or not. But $LVS_EX_FULLROWSELECT cannot be retrieved with that. You can only use 

GUICtrlListView_GetExtendedListViewStyle () to get either or not that flag is set. So if you use GetWindowLong(), and see that 0x20 is set, it definitely that you set the $WS_EX_TRANSPARENT. Similarly, when you use GUICtrlListView_GetExtendedListViewStyle () and see that 0x20, you can say anything about $WS_EX_TRANSPARENT but sure that $LVS_EX_FULLROWSELECT is set.

Edited by binhnx

99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites

What has any of that got to do with what you stated?

You said the listview had WS_EX_TRANSPARENT set, it does not, you are wrong. You can try and bullshit around it with pseudo knowledge, but in the end you're still wrong. You won't admit you're wrong, but anyone who reads this can try and show me where I am wrong and I'll admit it. Setting a ListView with FULLROWSELECT does not set window transparency on the listview, it sets it so that the full row of the listview is selected when you click on it. 

This is a simple binary question to you, there are 2 answers, yes and no. Does setting FULLROWSELECT on a ListView control cause it to have WS_EX_TRANSPARENT set on it as well? Your answer will tell us whether you know what you're talking about or not. I don't need another word-wall of text trying to explain what you think, I need a yes or no.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Simple, NO.

Setting LVS_EX_FULLROWSELECT will not make WS_EX_TRANSPARENT to be set.

Setting WS_EX_TRANSPARENT also will not make LVS_EX_FULLROWSELECT to be set.

>This should be a proof. Melba comment also give some information.


99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

Share this post


Link to post
Share on other sites

binhnx, that's perfect thank you for your solution! :D

Share this post


Link to post
Share on other sites

Indeed, it's not perfect yet :)

Finally, You also still need to add $WS_CLIPCHILDREN to the GUI to make things perfect :)


99 little bugs in the code

99 little bugs!

Take one down, patch it around

117 little bugs in the code!

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

  • Similar Content

    • Monica
      By Monica
      Hi guys!! I'm going crazy... please help me -.-
      First, open the attached screenshot. Second: I'd like to grab info from external window. The program is "Metatrader4", a tool for trading and charts analysis.
      The function _GUICtrlListView_GetItemText() return an empty string! I tried to change the index $index (the second parameter) into Number($index), as recommended by other similar posts in this forum, but this did not solve my problem 
      Well, why I'm going mad? Because in my mind an UDF approach works great or it does not work at all; instead, in my code something works and something else does not. I really don't understand why... and you?
      THXX!!!!  
      $handle=ControlGetHandle("Expert - "&$expertname,"",1383);List: Variable|Value For $i=0 To _GUICtrlListView_GetItemCount($handle)-1;WORKS!!! $temp=_GUICtrlListView_GetItemText($handle,0+$i);RETURN EMPTY STRING :-( MsgBox(0, "", $temp) $temp = _GUICtrlListView_GetItemSelected($handle,$i);WORKS!!! MsgBox(0, "", $temp) Next  

    • tcurran
      By tcurran
      Here are two functions to provide pixel-accurate height and width dimensions for a given string.
      The more commonly-used _GDIPlus_GraphicsMeasureString built-in UDF is problematic because it returns the width padded by roughly one en-space (for reasons related to the various ways Windows produces anti-aliased fonts).
      These are AutoIt translations of Pierre Arnaud's C# functions, described in his CodeProject article "Bypass Graphics.MeasureString limitations"
      The first is an all-purpose version that takes a window handle, string, font family, font size (in points), style, and (optionally) width of the layout column (in pixels) as parameters.
      The second, more efficient version is intended for applications where GDI+ fonts are already in use, and takes handles to the existing graphics context, string, font, layout and format as parameters.
      Both functions return a two-row array with the exact width [0] and height [1] of the string (in pixels).
      #include <GDIPlus.au3> #include <GUIConstantsEx.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringInPixels ; Description ...: Returns a pixel-accurate height and width for a given string using a given font, style and size. ; Syntax ........: _StringInPixels($hGUI, $sString, $sFontFamily, $fSize, $iStyle[, $iColWidth = 0]) ; Parameters ....: $hGUI - Handle to the window. ; $sString - The string to be measured. ; $sFontFamily - Full name of the font to use. ; $fSize - Font size in points (half-point increments). ; $iStyle - Combination of 0-normal, 1-bold, 2-italic, 4-underline, 8-strikethrough ; $iColWidth - [optional] If word-wrap is desired, column width in pixels ; Return values .: 2-row array. [0] is width in pixels; [1] is height in pixels. ; Author ........: Tim Curran; adapted from Pierre Arnaud's C# function ; Modified ......: ; Remarks .......: This version is longer and less efficient but works for all purposes. ; Related .......: <https://www.codeproject.com/Articles/2118/Bypass-Graphics-MeasureString-limitations> ; Link ..........: ; Example .......: Example-StringInPixels.au3 ; =============================================================================================================================== #include <GDIPlus.au3> #include <GUIConstantsEx.au3> Func _StringInPixels($hGUI, $sString, $sFontFamily, $fSize, $iStyle, $iColWidth = 0) _GDIPlus_Startup() Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;Create a graphics object from a window handle Local $aRanges[2][2] = [[1]] $aRanges[1][0] = 0 ;Measure first char (0-based) $aRanges[1][1] = StringLen($sString) ;Region = String length Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate($sFontFamily) Local $hFont = _GDIPlus_FontCreate($hFamily, $fSize, $iStyle) _GDIPlus_GraphicsSetTextRenderingHint($hGraphic, $GDIP_TEXTRENDERINGHINT_ANTIALIASGRIDFIT) _GDIPlus_StringFormatSetMeasurableCharacterRanges($hFormat, $aRanges) ;Set ranges Local $aWinClient = WinGetClientSize($hGUI) If $iColWidth = 0 Then $iColWidth = $aWinClient[0] Local $tLayout = _GDIPlus_RectFCreate(10, 10, $iColWidth, $aWinClient[1]) Local $aRegions = _GDIPlus_GraphicsMeasureCharacterRanges($hGraphic, $sString, $hFont, $tLayout, $hFormat) ;get array of regions Local $aBounds = _GDIPlus_RegionGetBounds($aRegions[1], $hGraphic) Local $aWidthHeight[2] = [$aBounds[2], $aBounds[3]] ; Clean up resources _GDIPlus_FontDispose($hFont) _GDIPlus_RegionDispose($aRegions[1]) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() Return $aWidthHeight EndFunc ;==>_StringInPixels ; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringInPixels_gdip ; Description ...: Returns a pixel-accurate height and width for a given string using a GDI+ font, layout and format ; Syntax ........: _StringInPixels_gdip($hGraphic, $sString, $hFont, $tLayout, $hFormat) ; Parameters ....: $hGraphic - Handle to a GDI+ graphics object. ; $sString - The string to be measured. ; $hFont - Handle to a GDI+ font. ; $tLayout - A $tagGDIPRECTF structure that bounds the string. ; $hFormat - Handle to a GDI+ string format. ; Return values .: 2-row array. [0] is width in pixels; [1] is height in pixels. ; Author ........: Tim Curran; adapted from Pierre Arnaud's C# function ; Modified ......: ; Remarks .......: This much more efficient version is for use with GDI+ fonts ; Related .......: ; Link ..........: <https://www.codeproject.com/Articles/2118/Bypass-Graphics-MeasureString-limitations> ; Example .......: Example-StringInPixels.au3 ; =============================================================================================================================== #include <GDIPlus.au3> #include <GUIConstantsEx.au3> Func _StringInPixels_gdip($hGraphic, $sString, $hFont, $tLayout, $hFormat) Local $aRanges[2][2] = [[1]] $aRanges[1][0] = 0 ;Measure first char (0-based) $aRanges[1][1] = StringLen($sString) ;Region = String length _GDIPlus_GraphicsSetTextRenderingHint($hGraphic, $GDIP_TEXTRENDERINGHINT_CLEARTYPEGRIDFIT) _GDIPlus_StringFormatSetMeasurableCharacterRanges($hFormat, $aRanges) ;Set ranges Local $aRegions = _GDIPlus_GraphicsMeasureCharacterRanges($hGraphic, $sString, $hFont, $tLayout, $hFormat) ;get array of regions Local $aBounds = _GDIPlus_RegionGetBounds($aRegions[1], $hGraphic) Local $aWidthHeight[2] = [$aBounds[2], $aBounds[3]] _GDIPlus_RegionDispose($aRegions[1]) Return $aWidthHeight EndFunc ;==>_StringInPixels_gdip  
      _StringInPixels.au3
      Example-StringInPixels.au3
    • anusha
      By anusha
      Hi I have jus started using auto-it . Please correct me if I'm wrong.
      I need to read data from an input in text box and search in excel file and return value in next column of matched cell on GUI.
      I have written below code but i cannot use variable which has data stored. it works only when search string is hard coded.
      Please help out.
       
      Example()
      Func Example()
      Local $GuiMain = GUICreate("EXCEL TEST", 399, 180) ;creates main GUI
      ;~ Local $idOK = GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
      Local $iWidthCell = 70
      Local $idLabel = GUICtrlCreateLabel("PART NUMBER", 10, 30, $iWidthCell,50)
      Local $RUN_1 = GUICtrlCreateButton("OK", 70, 70, 85, 25)
      Local $Input_1 = GUICtrlCreateInput("PART NUMBER", 100, 20, 120, 20)
      Local $sMenutext = GUICtrlRead($Input_1, 1)
      GUISetState(@SW_SHOW, $GuiMain)

          While 1
          $MSG = GUIGetMsg()
          Select
              Case $MSG = $GUI_EVENT_CLOSE
                  Exit
              Case $MSG = $RUN_1
                  Local $oAppl = _Excel_Open()

      Local $sFilePath1 = "D:\Anu_WorkFolder\Components.xlsx"
      Local $oWorkbook = _Excel_BookOpen($oAppl, $sFilePath1, Default, Default, True)
      Local $aResult = _Excel_RangeFind($oWorkbook, $sMenutext , Default, Default, $xlWhole)
    • Earthshine
      By Earthshine
      This baby can do almost any language! I found Gleany on this site and set it up on a fresh win10 install. all i would need to do to make it build an exe of the search files app we discovered is the .NET Target Framework download to build 100 % but the exe works and generates! You also need to add the path the the version of csc.exe that you want to run. MSBuild is part of .NET and can read your .csproj file.
      YOU can develop .NET OR C/C++ on this baby!
      Super lightweight (fit for crappy laptops), and you can use any dev compilers you wish, Ming, MS, etc, whatever.
      To use the build, you need to open the csproj file, else, to check your syntax it can compile individual files as well. The warning are because I do not have the .NET 4.6 Targeting Pack installed... LOL, and I could get rid of the Core warning, yes, I did not want to build a .NET Core.dll I wanted a live x64 exe! Told you MSBUILD could handle .CSPROJ, .VBPROJ, and all others Microsoft. Don't let Visual Code or Visual Studio slow you down, although, this works with Visual Code as well but there is only debugging in CORE.DLL projects

      ListFiles Example.zip
       

    • Miliardsto
      By Miliardsto
      Hello.
      Drag option works only on parent window but as we can see on the parent gui is showed up child gui (on the right side with the color).
      Desired action is when we want to drag whole program we can also drag child gui and child gui will drag with parent gui.
      How to do this?
       
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> GUIRegisterMsg($WM_NCHITTEST, "_NCHITTEST") $hGUI = GUICreate("Test", 500, 500, -1, -1) $cButton_0 = GUICtrlCreateButton("Child 0", 10, 10, 80, 30) $cButton_1 = GUICtrlCreateButton("Child 1", 10, 50, 80, 30) $cButton_2 = GUICtrlCreateButton("Child 2", 10, 90, 80, 30) GUISetState(@SW_SHOW, $hGUI) ; guis Global $hChild_[3] Global $countGUI = UBound($hChild_) - 1 ;MsgBox("","",$countGUI) ; licznik dla GUI Global $gui = 0 $hChild_[0] = GUICreate("Child 0", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0xFF0000) GUISetState(@SW_SHOW, $hChild_[0]) $hChild_[1] = GUICreate("Child 1", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0x00FF00) GUISetState(@SW_HIDE, $hChild_[1]) $hChild_[2] = GUICreate("Child 2", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0x0000FF) GUISetState(@SW_HIDE, $hChild_[2]) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton_0 _All_Hide() GUISetState(@SW_SHOW, $hChild_[0]) $gui = 0 Case $cButton_1 _All_Hide() GUISetState(@SW_SHOW, $hChild_[1]) $gui = 1 Case $cButton_2 _All_Hide() GUISetState(@SW_SHOW, $hChild_[2]) $gui = 2 EndSwitch WEnd Func _All_Hide() GUISetState(@SW_HIDE, $hChild_[0]) GUISetState(@SW_HIDE, $hChild_[1]) GUISetState(@SW_HIDE, $hChild_[2]) EndFunc Func _NCHITTEST($hWnd, $uMsg, $wParam, $lParam) If $hWnd = $hGUI Then Local $aPos = WinGetPos($hWnd) If Abs(BitAND(BitShift($lParam, 16),0xFFFF)- $aPos[1]) < 500 Then Return $HTCAPTION EndIf Return $GUI_RUNDEFMSG EndFunc