Jump to content
Sign in to follow this  
Rodger

Capture TreeView as an image

Recommended Posts

Rodger

Hello,

Does somebody know how I can capture an expanded TreeView as a whole which can be scrolled up and down as an image and save this image to a file ?

Thank you.

Rodger

Edited by Rodger

Share this post


Link to post
Share on other sites
l3ill

If you mean what I think you mean...

...Irfanview has a function that will allow such captures. Quasi Vertical Panorama Image.

From the IrfanView help file

Create Panorama image
 
  
Click on the Image Menu, then Create Panorama image. A dialog allows you to create a panorama image.
 
You can add single images vertically or horizontally. The first image in the chain will be used as the base for the next images.

There is also an option to insert filenames into the panorama image (top left corner of the single image) or add some empty space between the images. 0 pixels means no space (default).

Note: If you want to create images with multiple rows/columns at same time, use the Contact Sheet feature from Thumbnails window.

Share this post


Link to post
Share on other sites
l3ill

And if that is what you are looking for and want to script it...

>check out this post

It is designed to capture an entire webpage no matter how long, I assume it could be adapted to do what you are going for as well.

Good luck !

Bill

Share this post


Link to post
Share on other sites
Rodger

Thanks for the response.

I will look at the suggestions you made.  It concerns a treeview made with autoit (GUICtrlCreateTreeView).

Edited by Rodger

Share this post


Link to post
Share on other sites
Melba23

Rodger,

In that case you should be able to read the treeview content into a list and scroll it that way. I will see what I can come up with this afternoon. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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
Melba23

Rodger,

This seems to work quite well: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiListBox.au3>
#include <GuiTreeView.au3>
#include <String.au3>
#include <StaticConstants.au3>

$hGUI = GUICreate("Test", 500, 500)
GUISetBkColor(0xC4C4C4)

$cTV = GUICtrlCreateTreeView(10, 10, 230, 200)
For $i1 = 0 To 9
    $cItem = GUICtrlCreateTreeViewItem("Item " & $i1, $cTV)
    For $i2 = 0 To 9
        $cSubItem = GUICtrlCreateTreeViewItem("SubItem " & $i1 & $i2, $cItem)
        For $i3 = 0 To 9
            GUICtrlCreateTreeViewItem("SubSubItem " & $i1 & $i2 & $i3, $cSubItem)
        Next
    Next
Next
$cList = GUICtrlCreateList("", 260, 10, 230, 210, BitOr($WS_BORDER, $WS_VSCROLL)) ; Omit $LBS_SORT
$cButton = GUICtrlCreateButton("Image Treeview", 10, 300, 100, 30)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            $hItem = _GUICtrlTreeView_GetFirstItem($cTV)
            If $hItem Then
                _TV_Image($hGUI, $cList, $cTV, $hItem)
            Else
                MsgBox($MB_SYSTEMMODAL +$MB_ICONERROR, "Oops", "TreeView is empty")
            EndIf
    EndSwitch
WEnd

Func _TV_Image($hGUI, $cList, $cTV, $hItem)

    _GUICtrlListBox_BeginUpdate($cList)

    $aPos = ControlGetPos($hGUI, "", $cList)
    $cLabel = GUICtrlCreateLabel("Working", $aPos[0], $aPos[1], $aPos[2], $aPos[3], BitOr($SS_CENTER, $SS_CENTERIMAGE))
    GUICtrlSetBkColor($cLabel, 0xFFFFFF)

    $hItem = _GUICtrlTreeView_GetFirstItem($cTV)
    Do
        _Image_Item($cList, $cTV, $hItem)
        $hItem = _GUICtrlTreeView_GetNextSibling($cTV, $hItem)
    Until $hItem = 0

    GUICtrlDelete($cLabel)

    _GUICtrlListBox_EndUpdate($cList)

EndFunc

Func _Image_Item($cList, $cTV, $hItem)

    Do
        $sText = _GuiCtrlTreeView_GetText($cTV, $hItem)
        $iLevel = _GuiCtrlTreeView_Level($cTV, $hItem)
        $sLevel = ""
        If $iLevel Then
            $sLevel = _StringRepeat("--- ", $iLevel)
        EndIf
        _GUICtrlListBox_AddString($cList, $sLevel & $sText)
        $hItem = _GuiCtrlTreeView_GetNext($cTV, $hItem)
    Until $hItem = 0

EndFunc
I hope it is clear enough to follow without comments, but please do ask if there is anything you do not understand. :)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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
KaFu

Based on >this example by wraithdu and the standard help-file example for GUICtrlCreateListView().

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <SendMessage.au3>
#include <ScreenCapture.au3>
 
 
Example()
 
Func Example()
Local $listview, $button, $item1, $item2, $item3, $msg
 
GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0x00E0FFFF) ; will change background color
 
$listview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
$button = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
$item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
$item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview)
$item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
GUICtrlCreateInput("", 20, 200, 150)
GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping
GUISetState()
GUICtrlSetData($item2, "ITEM1")
GUICtrlSetData($item3, "||COL33")
GUICtrlDelete($item1)
 
_Capture_Listview($listview, @ScriptDir & "\listview.jpg")
 
Do
$msg = GUIGetMsg()
 
Select
Case $msg = $button
MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2)
Case $msg = $listview
MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
EndSelect
Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example
 
 
Func _Capture_Listview($hWnd, $sFile)
If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
If Not IsHWnd($hWnd) Then Return SetError(1)
_GDIPlus_Startup()
$iWidth = _WinAPI_GetWindowWidth($hWnd)
$iHeight = _WinAPI_GetWindowHeight($hWnd)
_WinCapture($hWnd, $sFile, $iWidth, $iHeight)
_GDIPlus_Shutdown()
EndFunc   ;==>_Capture_Listview
 
Func _WinCapture($hWnd, $sFile, $iWidth = -1, $iHeight = -1)
Local $iH, $iW, $hDDC, $hCDC, $hBMP
 
If $iWidth = -1 Then $iWidth = _WinAPI_GetWindowWidth($hWnd)
If $iHeight = -1 Then $iHeight = _WinAPI_GetWindowHeight($hWnd)
 
$hDDC = _WinAPI_GetDC($hWnd)
$hCDC = _WinAPI_CreateCompatibleDC($hDDC)
$hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iWidth, $iHeight)
_WinAPI_SelectObject($hCDC, $hBMP)
 
_SendMessage($hWnd, 0x000F, $hCDC, 0) ; $WM_PAINT = 0x000F
 
DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hWnd, "hwnd", $hCDC, "int", 1)
; PW_CLIENTONLY = 1  Only the client area of the window is copied to hdcBlt. By default, the entire window is copied.
 
#cs
Local $WM_PAINT = 0x000F
Local $WM_PRINT = 0x317
Local $PRF_CHILDREN = 0x10; Draw all visible child windows.
Local $PRF_CLIENT = 0x4 ; Draw the window's client area.
Local $PRF_OWNED = 0x20 ; Draw all owned windows.
Local $PRF_NONCLIENT = 0x2 ; Draw the window's Title area.
Local $PRF_ERASEBKGND = 0x8 ; Erases the background before drawing the window
Local $Ret = _SendMessage($hWnd, $WM_PAINT, $hCDC, 0)
$Ret = _SendMessage($hWnd, $WM_PRINT, $hCDC, BitOR($PRF_CHILDREN, $PRF_CLIENT, $PRF_OWNED, $PRF_NONCLIENT, $PRF_ERASEBKGND))
#ce
 
_WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, 0, 0, 0x00330008)
 
_WinAPI_ReleaseDC($hWnd, $hDDC)
_WinAPI_DeleteDC($hCDC)
 
_ScreenCapture_SaveImage($sFile, $hBMP, True)
 
; Return $hBMP
EndFunc   ;==>_WinCapture

Share this post


Link to post
Share on other sites
Melba23

billo,

Saving the content of the list to a file is simple - just write the lines to a file as they are written to the list. Reading the list back in from the file is equally trivial. :)

I have no idea how to get the list content into an image though. I imagine that you would need a GDI guru like UEZ using something liek _GDIPlus_GraphicsDrawString for that. ;)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

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  

×