Jess Posted September 12, 2017 Posted September 12, 2017 Hi, I am trying to wrap up the column name in a list view in a way that if a column name is more that 1 word, then the first word in the name comes in first line and then the other words in subsequent lines in the particular column name. Can anyone help me in that ?
Moderators Melba23 Posted September 12, 2017 Moderators Posted September 12, 2017 Jess, Here is a good example of how to do it: M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Jess Posted September 14, 2017 Author Posted September 14, 2017 Hi @Melba23 thanks for this help. I have one query, If I have more than 3 columns lets say 10 or 12, I am adding it in $aHdrInfo variable then it shows an error which is "Array variable has incorrect number of subscripts or subscript dimension range exceeded." Can you help in this?
Moderators Melba23 Posted September 14, 2017 Moderators Posted September 14, 2017 Jess, I suggest you post the code which gives you the problem, otherwise we cannot help - see here how to do it. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Jess Posted September 15, 2017 Author Posted September 15, 2017 Hi @Melba23 I tried the multiline header and it was working fine, until I tried to give the background color to the headers. So should I post the code in this thread or I need to create a new one?
Moderators Melba23 Posted September 15, 2017 Moderators Posted September 15, 2017 Jess, Posing it here would be fine. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Jess Posted September 18, 2017 Author Posted September 18, 2017 expandcollapse popup#include <GUIConstants.au3> #include <WinAPIShellEx.au3> #include <FontConstants.au3> #include <GuiListView.au3> #include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include "GuiHeaderEx.au3" Opt( "MustDeclareVars", 1 ) Global Const $tagNMCUSTOMDRAW = "struct;" & $tagNMHDR & ";dword dwDrawStage;handle hdc;" & $tagRECT & _ ";dword_ptr dwItemSpec;uint uItemState;lparam lItemlParam;endstruct" Global $hHeader ; Left/right margin Global $iHdrLins = 3 ; Line 1 Line 2 Line 3 | Line height Global $aHdrInfo = [ [ "Column 1", "", "", 4, 16, $DT_CENTER, "Styles", 0, 0, 0], _ ; Item 1 [ "Column 2", "Line 2", "", 4, 16, $DT_CENTER, "Fonts", 0, 0, 0, 0], _ ; Item 2 [ "Column 3", "Line 2", "Line 3", 4, 16, $DT_CENTER, "ForeColors", 0, 0, 0, 0 ], _ ; Item 3 [ "Column 4", "Line 2", "", 4, 16, $DT_CENTER, "BackColor", 0, 0, 0, 0 ], _ [ "Column 1", "", "", 4, 16, $DT_CENTER, "BackColor", 0, 0, 0, 0 ], _ [ "Column 4", "Line 2", "", 4, 16, $DT_CENTER, "BackColor", 0, 0, 0, 0 ], _ [ "Column 4", "Line 2", "", 4, 16, $DT_CENTER, "BackColor", 0, 0, 0, 0 ], _ [ "Column 4", "Line 2", "", 4, 16, $DT_CENTER, "BackColor", 0, 0, 0, 0 ], _ [ "Column 4", "Line 2", "", 4, 16, $DT_CENTER, "BackColor", 0, 0, 0, 0 ], _ [ "Column 4", "Line 2", "", 4, 16, $DT_CENTER, "BackColor", 0, 0, 0, 0 ], _ ; Item 4 [ "Column 4", "Line 2", "", 4, 16, $DT_CENTER, "BackColor", 0, 0, 0, 0 ], _ [ "Column 4", "Line 2", "", 4, 16, $DT_CENTER, "BackColor", 0, 0, 0, 0 ], _ [ "Column 4", "Line 2", "", 4, 16, $DT_CENTER, "BackColor", 0, 0, 0, 0 ], _ [ "Column 4", "Line 2", "", 4, 16, $DT_CENTER, "BackColor", 0, 0, 0, 0 ], _ [ "Column 4", "Line 2", "", 4, 16, $DT_CENTER, "BackColor", 0, 0, 0, 0 ]] Example() Func Example() ; Create GUI GUICreate(" My GUI input acceptfile", 900, 570, -1, -1) GUISetBkColor(0x3e65a0) ; Create ListView Global $idListview = GUICtrlCreateListView("", 2, 185, 900, 330, -1) ;$WS_EX_CLIENTEDGE+$LVS_EX_FULLROWSELECT+$LVS_EX_HEADERDRAGDROP ) _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FLATSB, $LVS_REPORT,$LVS_EX_DOUBLEBUFFER)) Local $hListView = GUICtrlGetHandle( $idListView ) ;GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; GUISetState(@SW_SHOW) ; Header control $hHeader = _GUICtrlListView_GetHeader( $hListView ) Local $iHeaderHeight = 68 ; Header height 50 pixels Local $hDC = _WinAPI_GetDC( $hHeader ), $hFont = _SendMessage( $hHeader, $WM_GETFONT ), $hObject = _WinAPI_SelectObject( $hDC, $hFont ), $tLogFont = DllStructCreate( $tagLOGFONT ) _WinAPI_GetObject( $hFont, DllStructGetSize( $tLogFont ), DllStructGetPtr( $tLogFont ) ) _WinAPI_SelectObject( $hDC, $hObject ) _WinAPI_ReleaseDC( $hHeader, $hDC ) ; Background color for Header item 4 $aHdrInfo[3][7] = 0x00FF00 ; Green background, BGR $aHdrInfo[3][8] = _WinAPI_CreateSolidBrush( $aHdrInfo[3][7] ) ; Brush with background color ; Set height of Header items by applying a text font with a suitable height Local $hHdrFont = _GUICtrlHeader_SetItemHeightByFont( $hHeader, $iHeaderHeight ) ; Add columns to ListView _GUICtrlListView_AddColumn( $hListView, "", 99 ) ; Delete header texts to avoid that they are _GUICtrlListView_AddColumn( $hListView, "", 99 ) ; drawn in $CDDS_ITEMPREPAINT stage below. _GUICtrlListView_AddColumn( $hListView, "", 99 ) _GUICtrlListView_AddColumn( $hListView, "", 99 ) _GUICtrlListView_AddColumn( $hListView, "", 99 ) _GUICtrlListView_AddColumn( $hListView, "", 99 ) _GUICtrlListView_AddColumn( $hListView, "", 99 ) _GUICtrlListView_AddColumn( $hListView, "", 99 ) _GUICtrlListView_AddColumn( $hListView, "", 99 ) _GUICtrlListView_AddColumn( $hListView, "", 99 ) _GUICtrlListView_AddColumn( $hListView, "", 99 ) _GUICtrlListView_AddColumn( $hListView, "", 99 ) _GUICtrlListView_AddColumn( $hListView, "", 99 ) _GUICtrlListView_AddColumn( $hListView, "", 99 ) _GUICtrlListView_AddColumn( $hListView, "", 99 ) Local $pListViewProc = DllCallbackGetPtr( DllCallbackRegister( "ListViewProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) ) _WinAPI_SetWindowSubclass( $hListView, $pListViewProc, 9999, $hHdrFont ) ; SubclassId = 9999, $pData = $hHdrFont ; Show GUI GUISetState( @SW_SHOW ) ; Message loop While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; Cleanup _WinAPI_RemoveWindowSubclass( $hListView, $pListViewProc, 9999 ) GUIDelete() EndFunc Func ListViewProc( $hWnd, $iMsg, $wParam, $lParam, $iSubclassId, $hHdrFont ) #forceref $iSubclassId Switch $iMsg Case $WM_NOTIFY Local $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) Local $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) ) Local $iCode = DllStructGetData( $tNMHDR, "Code" ) Switch $hWndFrom Case $hHeader Switch $iCode Case $NM_CUSTOMDRAW Local $tNMCustomDraw = DllStructCreate( $tagNMCUSTOMDRAW, $lParam ) Local $dwDrawStage = DllStructGetData( $tNMCustomDraw, "dwDrawStage" ) Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify parent window of any item related drawing operations Case $CDDS_ITEMPREPAINT ; Before an item is drawn: Default painting (frames and background) Return $CDRF_NOTIFYPOSTPAINT ; Notify parent window of any post item related drawing operations Case $CDDS_ITEMPOSTPAINT ; After an item is drawn: Custom painting (item texts) Local $iIndex = DllStructGetData( $tNMCustomDraw, "dwItemSpec" ) ; Item index Local $hDC = DllStructGetData( $tNMCustomDraw, "hdc" ) ; Device context _WinAPI_SelectObject( $hDC, $hHdrFont ) ; Set text font _WinAPI_SetBkMode( $hDC, $TRANSPARENT ) ; Transparent background Switch $aHdrInfo[$iIndex][7] Case "Styles" _WinAPI_SelectObject( $hDC, $aHdrInfo[$iIndex][8] ) Case "Fonts" _WinAPI_SelectObject( $hDC, $aHdrInfo[$iIndex][8] ) Case "ForeColors" _WinAPI_SelectObject( $hDC, $aHdrInfo[0][9] ) ; Bold _WinAPI_SetTextColor( $hDC, $aHdrInfo[$iIndex][8] ) Case "BackColor" _WinAPI_SelectObject( $hDC, $aHdrInfo[0][8] ) _WinAPI_SetBkColor( $hDC, $aHdrInfo[$iIndex][8] ) Local $tRECT = DllStructCreate( $tagRECT ) DllStructSetData( $tRECT, 1, DllStructGetData( $tNMCustomDraw, 6 ) + 1 ) DllStructSetData( $tRECT, 2, DllStructGetData( $tNMCustomDraw, 7 ) + 1 ) DllStructSetData( $tRECT, 3, DllStructGetData( $tNMCustomDraw, 8 ) - 2 ) DllStructSetData( $tRECT, 4, DllStructGetData( $tNMCustomDraw, 9 ) - 2 ) _WinAPI_FillRect( $hDC, $tRECT, $aHdrInfo[$iIndex][8] ) EndSwitch ; First line DllStructSetData( $tNMCustomDraw, "Left", DllStructGetData( $tNMCustomDraw, "Left" ) + $aHdrInfo[$iIndex][3] ) ; Left margin DllStructSetData( $tNMCustomDraw, "Right", DllStructGetData( $tNMCustomDraw, "Right" ) - $aHdrInfo[$iIndex][3] ) ; Right margin DllStructSetData( $tNMCustomDraw, "Top", DllStructGetData( $tNMCustomDraw, "Top" ) + 2 ) ; 2 pixel top margin DllStructSetData( $tNMCustomDraw, "Bottom", DllStructGetData( $tNMCustomDraw, "Top" ) + $aHdrInfo[$iIndex][4] ) ; Line height DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aHdrInfo[$iIndex][0], "int", StringLen( $aHdrInfo[$iIndex][0] ), "struct*", DllStructGetPtr( $tNMCustomDraw, "Left" ), "uint", $aHdrInfo[$iIndex][6] ) ; _WinAPI_DrawText ; Line two, three and four For $i = 1 To 2 Switch $aHdrInfo[$iIndex][6] Case "Styles" _WinAPI_SelectObject( $hDC, $aHdrInfo[$iIndex][8+$i] ) Case "Fonts" _WinAPI_SelectObject( $hDC, $aHdrInfo[$iIndex][8+$i] ) Case "ForeColors" _WinAPI_SetTextColor( $hDC, $aHdrInfo[$iIndex][8+$i] ) EndSwitch DllStructSetData( $tNMCustomDraw, "Top", DllStructGetData( $tNMCustomDraw, "Top" ) + $aHdrInfo[$iIndex][4] ) ; 2 pixel top margin DllStructSetData( $tNMCustomDraw, "Bottom", DllStructGetData( $tNMCustomDraw, "Bottom" ) + $aHdrInfo[$iIndex][4] ) DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $aHdrInfo[$iIndex][$i], "int", StringLen( $aHdrInfo[$iIndex][$i] ), "struct*", DllStructGetPtr( $tNMCustomDraw, "Left" ), "uint", $aHdrInfo[$iIndex][5] ) ; _WinAPI_DrawText Next Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch EndSwitch EndSwitch ; Call next function in subclass chain Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam )[0] EndFunc I just want o give background color the headers in column list view. Here is the code. Please review it. Thanks
Moderators Melba23 Posted September 18, 2017 Moderators Posted September 18, 2017 Jess, It looks to me as if you have amended the $aHdrInfo array by removing a column and as a result the coordinates used by the rest of the script are no longer valid. I suggest you post in the UDF thread to which I linked you earlier and ask the author to help because my attempts at amending your code have alas not been successful. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Jess Posted September 18, 2017 Author Posted September 18, 2017 Hi @Melba23, I did not understand to which thread you are referring to. Is it the thread I started before this one?
Moderators Melba23 Posted September 18, 2017 Moderators Posted September 18, 2017 Jess, The thread from which you got the code you are using and to which I linked you in post #2: That way the original author can help you. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now