Sign in to follow this  
Followers 0
AndyS01

_WinAPI_SetWindowPos() doesn't work on ListView control

13 posts in this topic

I'm trying to dynamically change the height of a ListView control and using _WinAPI_SetWindowPos() does not do anything.

I am forced to create the listview with _GUICtrlListView_Create() because of other issues.

I don't know of any other was to change a contoll's size dynamically.

Here is a test script:

#include <\AutoIT-src\myLib\MyDebug.au3>
_DebugSetup(@ScriptName & "_debug.txt", False, 6, "D:\temp\x.log") ; 6 = Notepad; 2 = to console; 4 = to a file
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
Opt("GUICloseOnESC", 1) ; ESC closes GUI
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
Opt('MustDeclareVars', 1)
OnAutoItExitRegister("ExitStageLeft")
Opt("GUIEventOptions", 1) ;0=default, 1=just notification, 2=GuiCtrlRead tab index
Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Global $hMainWin_hWnd
Global $hListView_hWnd = 0
Global $iListView_ID = 0
Global $mwTitle = ""

_Main()
Exit (1)

Func _Main()

$mwTitle = "Test Script"
$hMainWin_hWnd = GUICreate($mwTitle, 300, 500, 100, 100)

$hListView_hWnd = [color=#ff0000]_GUICtrlListView_Create[/color]($hMainWin_hWnd, "lv", 5, 5, 300 - 50, 500 - 40)
_DebugOut("+++: Listview handle: " & Hex($hListView_hWnd))

GUICtrlCreateButton("Higher", 10, 500 - 30, 50, 25)
GUICtrlSetOnEvent(-1, "higher")

GUICtrlCreateButton("Lower", 60, 500 - 30, 50, 25)
GUICtrlSetOnEvent(-1, "lower")
GUISetOnEvent($GUI_EVENT_CLOSE, 'ExitStageLeft')
GUISetState() ; Make everything visible

While (1)
Sleep(250)
WEnd
Exit
EndFunc   ;==>_Main

Func ExitStageLeft()
Exit (1)
EndFunc   ;==>ExitStageLeft

Func higher()
changeHeight(20)
EndFunc   ;==>higher

Func lower()
changeHeight(-20)
EndFunc   ;==>lower

Func changeHeight($dh)
_DebugOut("+++: changeHeight(" & $dh & ") entered")
Local $cur_h, $cur_w, $w, $h, $ret, $ar

$ar = getWidthHeight()
$cur_w = $ar[0]
$cur_h = $ar[1]

$h = $cur_h + $dh
$w = $cur_w

_DebugOut("+++: calling _WinAPI_SetWindowPos(" & Hex($hListView_hWnd) & ", 10, 10 , " & $w & ", " & $h & ", 0x200)")

$ret =[color=#ff0000] _WinAPI_SetWindowPos[/color]($hListView_hWnd, -1, -1, -1, $w, $h, 0x200) ;  0x200 = $SWP_NOOWNERZORDER
_DebugOut("+++: $ret after _WinAPI_SetWindowPos() = " & $ret)

If (Not $ret) Then
MsgBox(0, "ERROR", "_WinAPI_SetWindowPos(" & Hex($hListView_hWnd) & ", -1, -1 , " & $w & ", " & $h & ", 0x200) failed")
Exit (1)
EndIf

$ar = getWidthHeight()

If ($ar[0] == $cur_w) Or ($ar[1] == $cur_h) Then
MsgBox(16, "ERROR", "Failed to change size at all")
Exit (1)
EndIf

If ($ar[0] <> $w) Or ($ar[1] <> $h) Then
MsgBox(16, "ERROR", "Failed to change size correctly")
Exit (1)
EndIf

EndFunc   ;==>changeHeight

Func getWidthHeight()
Local $ar[2]

$ar[0] = _WinAPI_GetWindowWidth($hListView_hWnd)
_DebugOut("+++: _WinAPI_GetWindowWidth(" & Hex($hListView_hWnd) & ") = " & $ar[0])

$ar[1] = _WinAPI_GetWindowHeight($hListView_hWnd)
_DebugOut("+++: _WinAPI_GetWindowHeight(" & Hex($hListView_hWnd) & ") = " & $ar[1])

Return ($ar)
EndFunc   ;==>getWidthHeight

Share this post


Link to post
Share on other sites



What about using WinMove instead?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

First of all, _WinAPI_SetWindowPos isn't going to affect a control, it looks like it's for windows only. Second, why must you use the _GUICtrlListView_Create function to make the listview? What are you trying to do with it that the native function won't do?


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

I tried WinMove() with the same results.

Share this post


Link to post
Share on other sites

I need to use _GUICtrlListView_Create() due to a bug somewhere that causes strange results when mouse clicking on an item in the listview. I think I posted something about that sometime last year.

Share this post


Link to post
Share on other sites

AndyS01,

If you actually allow the script to run rather than testing the results of the function, it works very nicely with WinMove as this script shows: :)

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

Opt("GUICloseOnESC", 1) ; ESC closes GUI
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
Opt('MustDeclareVars', 1)
OnAutoItExitRegister("ExitStageLeft")
Opt("GUIEventOptions", 1) ;0=default, 1=just notification, 2=GuiCtrlRead tab index
Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Global $hMainWin_hWnd
Global $hListView_hWnd = 0
Global $iListView_ID = 0
Global $mwTitle = ""

_Main()

While (1)
    Sleep(250)
WEnd

Exit (1)

Func _Main()

    $mwTitle = "Test Script"
    $hMainWin_hWnd = GUICreate($mwTitle, 300, 500, 100, 100)
    GUISetOnEvent($GUI_EVENT_CLOSE, 'ExitStageLeft')
    GUISetBkColor(0xFFCCCC)

    $hListView_hWnd = _GUICtrlListView_Create($hMainWin_hWnd, "lv", 5, 5, 300 - 50, 500 - 40)
    _GUICtrlListView_SetColumnWidth($hListView_hWnd, 0, 300 - 70)

    For $i = 1 To 50
        _GUICtrlListView_AddItem($hListView_hWnd, "ListView Item " & $i)
    Next

    GUICtrlCreateButton("Higher", 10, 500 - 30, 50, 25)
    GUICtrlSetOnEvent(-1, "higher")

    GUICtrlCreateButton("Lower", 60, 500 - 30, 50, 25)
    GUICtrlSetOnEvent(-1, "lower")

    GUISetState() ; Make everything visible

EndFunc   ;==>_Main

Func ExitStageLeft()
    Exit (1)
EndFunc   ;==>ExitStageLeft

Func higher()
    changeHeight(20)
EndFunc   ;==>higher

Func lower()
    changeHeight(-20)
EndFunc   ;==>lower

Func changeHeight($dh)

    Local $ar = WinGetPos($hListView_hWnd)
    WinMove($hListView_hWnd, "", 5, 5, $ar[2], $ar[3] + $dh)

EndFunc   ;==>changeHeight

Does it work for you too? ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks Melba23, I could've sworn it worked when I last used WinMove, so was a taken back a bit when told it didn't work! :)


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Right. It all works now. Actually, it was working all along as you said, but I was getting bogus results when I looked to see if the size actually changed. I changed it to use _WinAPI_GetWindowPlacement() to get the size and it all checked out OK. I can resize and verify that the resize worked.

I find it interesting that the first parameter to WinMove() is documented as the window title, but a window (or control) handle can also be used. Makes it really useful for resizing controls.

Thanks for looking at this for me.

Andy

Share this post


Link to post
Share on other sites

Mmmh,

I didn't read all, but for a own listview I use controlsetpos. Also have a look at the "default" keyword.

A quick exctract from a bigger script:

;; get the position of the of the horizontal splitter of the left side mother GUI (sidbar with splitter)

$hsPos = ControlGetPos($leftGUI,"",$hSplitter)

DIM $hsl=$hsPos[0], $hst=$hsPos[1], $hsw=$hsPos[2], $hsh=$hsPos[3]

;; Change left sidebar listview position based on changes of the splitter

GuiCTrlSetPos($leftGui_Listview1, 0, $hst+2+15+22,default,$lgh-$hst-15-8-22)

HTH, Reinhard

Share this post


Link to post
Share on other sites

ReFran,

I didn't read all, but for a own listview I use controlsetpos

As the OP uses the GUIListView UDF to create the ListView, GuiCtrlSetPos will not work - he needs to use WinMove. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

AndyS01,

I find it interesting that the first parameter to WinMove() is documented as the window title, but a window (or control) handle can also be used

From the Help file - <Using AutoIt - Window Titles and Text (Advanced)>: :)

"A window handle is a special value that Windows assigns to windows each time they are created. When you have a handle you may use it in place of the title parameter in any of the function calls that use the title/text convention"

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

As the OP uses the GUIListView UDF to create the ListView, GuiCtrlSetPos will not work - he needs to use WinMove. :)

Aaah,

I start by standard with GuiCtrlCreate ... and use UDF only if I need it. So I didn't notice that.

Thanks for enlightening, Reinhard

Edited by ReFran

Share this post


Link to post
Share on other sites

First of all, _WinAPI_SetWindowPos isn't going to affect a control, it looks like it's for windows only.

Yes it will.

A control is a child window that an application uses in conjunction with another window to enable user interaction.

The difference you will notice is that window-functions uses window-coordinates and control-based client-coords

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