Jump to content

set a pic ontop on a listview ??


AlienStar
 Share

Recommended Posts

Strange... this script works for me, pic "head_main.jpg" provided below

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 620, 290)
$listview_st = GUICtrlCreateListView("#|sections", 20, 20, 579, 243)

$idPic = GUICtrlCreatePic("head_main.jpg",20, 20,579,25)
GuiCtrlSetState($idPic, $GUI_ONTOP)

GUISetState(@SW_SHOW, $hGUI)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

GUIDelete($hGUI)

274582217_piccoveringlistviewheader.png.f2bef7fc864b33008c9f8b907d1a2697.png

downloadable pic below, to be renamed "head_main.jpg"

head_main.jpg.8af5f6911ef2a1ed15db7c99ba325d3b.jpg

Edited by pixelsearch
Link to comment
Share on other sites

It does not work for me either. I have added a colored .jpg (a bit shifted) so it can be better visualized.

PicBehind.jpg.ebf50efbaf3003e74b2aaf6cecba6eb2.jpg

Win7 Pro SP1 64 / AutoIt 3.3.12.0

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Does this other way of doing it satisfy your needs ?
(Main GUI is less high in this script, so the resulting pic takes less place when displayed below)

Also, what should happen when the user clicks on the "now-hidden" listview header ?

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

$hGUI = GUICreate("Test", 620, 140)

$listview_st = GUICtrlCreateListView("#|sections", 30, 20, 579, 93)
ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($listview_st))) ; Melba23's way

GUICtrlCreateListViewItem("1|100", $listview_st)
GUICtrlCreateListViewItem("2|200", $listview_st)

$hGUI_Child = GUICreate("", 579, 25, 30, 20, $WS_CHILD, -1, $hGUI)
$idPic = GUICtrlCreatePic("head_main.jpg", 0, 0, 579, 25)

GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI_Child)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

GUIDelete($hGUI_Child)
GUIDelete($hGUI)

1087675867_piccoveringlistviewheader2.png.3eeff9b004a09d8956934281ed282ef2.png

Edited by pixelsearch
typo
Link to comment
Share on other sites

This works !
The functionality of the "now-hidden" listview header is preserved.

PicListview.jpg.1f798d3a471d88aa4ed40861c8cbc66f.jpg

In case the graphic extends into the area of the list view items, it will be overwritten by clicked fields. I do not know the intention of the OP, but for me this is ok (and is also logic). Otherwise this area would be deprived of its meaning.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

2 hours ago, pixelsearch said:

Does this other way of doing it satisfy your needs ?
(Main GUI is less high in this script, so the resulting pic takes less place when displayed below)

Also, what should happen when the user clicks on the "now-hidden" listview header ?

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

$hGUI = GUICreate("Test", 620, 140)

$listview_st = GUICtrlCreateListView("#|sections", 30, 20, 579, 93)
ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($listview_st))) ; Melba23's way

GUICtrlCreateListViewItem("1|100", $listview_st)
GUICtrlCreateListViewItem("2|200", $listview_st)

$hGUI_Child = GUICreate("", 579, 25, 30, 20, $WS_CHILD, -1, $hGUI)
$idPic = GUICtrlCreatePic("head_main.jpg", 0, 0, 579, 25)

GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI_Child)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

GUIDelete($hGUI_Child)
GUIDelete($hGUI)

1087675867_piccoveringlistviewheader2.png.3eeff9b004a09d8956934281ed282ef2.png

thanks so much my friend it works :)

Link to comment
Share on other sites

@AlienStar & Musashi : glad the 2nd way worked for you :)
As you can see in the pic of my precedent post (zoomed below) the green selection of 1st row overlaps just a bit above the pic.

1232473142_piccoveringoverlap.png.28b4ede09880e8c16056cae6b8e5a388.png

To avoid this, may I suggest to retrieve the exact height of the listview header with this kind of line in the script :

$iHeaderHeight = _WinAPI_GetWindowHeight($hHeader)

Now that we got the exact height in the variable $iHeaderHeight, it's easy to use this variable as the height of the child gui and as the height of the pic, leading us to :

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

$hGUI = GUICreate("Test", 620, 140)

$listview_st = GUICtrlCreateListView("#|sections", 30, 20, 579, 93)
GUICtrlCreateListViewItem("1|100", $listview_st)
GUICtrlCreateListViewItem("2|200", $listview_st)

$hHeader = _GUICtrlListView_GetHeader($listview_st)
$iHeaderHeight = _WinAPI_GetWindowHeight($hHeader)

; ControlDisable($hGUI, "", HWnd(_GUICtrlListView_GetHeader($listview_st))) ; Melba23's way.
ControlDisable($hGUI, "", $hHeader) ; seems ok without HWnd($hHeader) as in line before ?

$hGUI_Child = GUICreate("", 579, $iHeaderHeight, 30, 20, $WS_CHILD, -1, $hGUI)
$idPic = GUICtrlCreatePic("head_main.jpg", 0, 0, 579, $iHeaderHeight)

GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI_Child)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

GUIDelete($hGUI_Child)
GUIDelete($hGUI)

No more overlap :

596372759_piccoveringlistviewheader3.png.891463b40763c2d433b736843bbd7cb0.png

Link to comment
Share on other sites

Hi AlienStar :)
Sooner or later, you will need to resize your GUI, maximize it, restore it etc...
When this day comes, you won't be able to do it with the script above because the pic won't cover the listview headers anymore (tested right now), also style $WS_CHILD will then create some display issues after the parent GUI is resized.

To prevent this, here is an amended script taking care of a resizable / maximizable parent GUI. It requires :
* A child window created with $WS_POPUP style and $WS_EX_MDICHILD extended style.
* A pic control which resizes and repositions itself according to any new child window size.
* Message WM_SIZE needs to be registered.
* Events $GUI_EVENT_MAXIMIZE and $GUI_EVENT_RESTORE are added inside the While... Wend loop.

Thanks to Melba23 & Nine for some ideas in the script and I hope it will work for you.

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

;======================
$hGUI = GUICreate("Test", 620, 140, -1, -1, BitOr($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))

$idListView = GUICtrlCreateListView("#|sections", 30, 20, 579, 93)
$hListView = GUICtrlGetHandle($idListView)

$hHeader = _GUICtrlListView_GetHeader($idListView)
$iHeaderHeight = _WinAPI_GetWindowHeight($hHeader)
; ControlDisable($hGUI, "", $hHeader)

For $i = 1 To 20
    GUICtrlCreateListViewItem($i & "|" & $i*100, $idListView)
Next

;======================
$hGUI_Child = GUICreate("", 579, $iHeaderHeight, 30, 20, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)

$idPic = GUICtrlCreatePic("head_main.jpg", 0, 0, 579, $iHeaderHeight)
GUICtrlSetResizing($idPic, $GUI_DOCKAUTO) ; +++
; GUICtrlSetState($idPic, $GUI_DISABLE)

_Resize() ; prevent pic from overlapping above an eventual vertical scrollbar arrow

GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI_Child)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
            _Resize()

        Case $idPic
            ConsoleWrite("Pic clicked" & @lf)
            ; GUISetState(@SW_HIDE, $hGUI_Child)
            ; Sleep(1000)
            ; GUISetState(@SW_SHOW, $hGUI_Child)
    EndSwitch
WEnd

GUIDelete($hGUI)
GUIDelete($hGUI_Child)

;============================================
Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam, $lParam

    If $hWnd = $hGUI Then
        _Resize()
    EndIf

EndFunc

;============================================
Func _Resize()

    Local $aTag   = _WinAPI_GetWindowRect($hHeader)
    Local $Left   = DllStructGetData($aTag, "Left"), _
          $Top    = DllStructGetData($aTag, "Top"), _
          $Right  = DllStructGetData($aTag, "Right"), _
          $Bottom = DllStructGetData($aTag, "Bottom")

    ; WinMove($hGUI_Child, "", $Left, $Top, $Right - $Left, $Bottom - $Top)

    ; a more precise way (pic won't overlap above an eventual vertical scrollbar arrow)
    Local $aLVPos = WinGetPos($hListView) ; including eventual scrollbars
    Local $aClientSize = WinGetClientSize($hListView) ; excluding eventual scrollbars
    WinMove($hGUI_Child, "", $Left, $Top, _
        $Right - $Left - ($aLVPos[2] - $aClientSize[0] - 4), _
        $Bottom - $Top)

EndFunc

1957192735_piccoveringlistviewheader5.png.1b1ea331722454593699f786ef01406f.png

Edited by pixelsearch
prevent pic from overlapping above an eventual vertical scrollbar arrow
Link to comment
Share on other sites

7 hours ago, pixelsearch said:

Hi AlienStar :)
Sooner or later, you will need to resize your GUI, maximize it, restore it etc...
When this day comes, you won't be able to do it with the script above because the pic won't cover the listview headers anymore (tested right now), also style $WS_CHILD will then create some display issues after the parent GUI is resized.

To prevent this, here is an amended script taking care of a resizable / maximizable parent GUI. It requires :
* A child window created with $WS_POPUP style and $WS_EX_MDICHILD extended style.
* A pic control which resizes and repositions itself according to any new child window size.
* Message WM_SIZE needs to be registered.
* Events $GUI_EVENT_MAXIMIZE and $GUI_EVENT_RESTORE are added inside the While... Wend loop.

Thanks to Melba23 & Nine for some ideas in the script and I hope it will work for you.

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

;======================
$hGUI = GUICreate("Test", 620, 140, -1, -1, BitOr($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))

$idListView = GUICtrlCreateListView("#|sections", 30, 20, 579, 93)
$hListView = GUICtrlGetHandle($idListView)

$hHeader = _GUICtrlListView_GetHeader($idListView)
$iHeaderHeight = _WinAPI_GetWindowHeight($hHeader)
; ControlDisable($hGUI, "", $hHeader)

For $i = 1 To 20
    GUICtrlCreateListViewItem($i & "|" & $i*100, $idListView)
Next

;======================
$hGUI_Child = GUICreate("", 579, $iHeaderHeight, 30, 20, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)

$idPic = GUICtrlCreatePic("head_main.jpg", 0, 0, 579, $iHeaderHeight)
GUICtrlSetResizing($idPic, $GUI_DOCKAUTO) ; +++
; GUICtrlSetState($idPic, $GUI_DISABLE)

_Resize() ; prevent pic from overlapping above an eventual vertical scrollbar arrow

GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOW, $hGUI_Child)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
            _Resize()

        Case $idPic
            ConsoleWrite("Pic clicked" & @lf)
            ; GUISetState(@SW_HIDE, $hGUI_Child)
            ; Sleep(1000)
            ; GUISetState(@SW_SHOW, $hGUI_Child)
    EndSwitch
WEnd

GUIDelete($hGUI)
GUIDelete($hGUI_Child)

;============================================
Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    #forceref $iMsg, $wParam, $lParam

    If $hWnd = $hGUI Then
        _Resize()
    EndIf

EndFunc

;============================================
Func _Resize()

    Local $aTag   = _WinAPI_GetWindowRect($hHeader)
    Local $Left   = DllStructGetData($aTag, "Left"), _
          $Top    = DllStructGetData($aTag, "Top"), _
          $Right  = DllStructGetData($aTag, "Right"), _
          $Bottom = DllStructGetData($aTag, "Bottom")

    ; WinMove($hGUI_Child, "", $Left, $Top, $Right - $Left, $Bottom - $Top)

    ; a more precise way (pic won't overlap above an eventual vertical scrollbar arrow)
    Local $aLVPos = WinGetPos($hListView) ; including eventual scrollbars
    Local $aClientSize = WinGetClientSize($hListView) ; excluding eventual scrollbars
    WinMove($hGUI_Child, "", $Left, $Top, _
        $Right - $Left - ($aLVPos[2] - $aClientSize[0] - 4), _
        $Bottom - $Top)

EndFunc

1957192735_piccoveringlistviewheader5.png.1b1ea331722454593699f786ef01406f.png

you are so amazing my friend thanks so much :) :) 

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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