José,
How do you increase the header height in this example.
http://www.jose.it-berater.org/smfforum/index.php?topic=4365.msg15152#msg15152
I tried changing the -> change me lines but the header background and size appears to be the same??
James
When processing the WM_SIZE message...
MoveWindow ListView_GetHeader(hListView), 0, 0, LO(WORD, lParam), <wanted height>, %TRUE
Thank you sir.
Might I ask where you got your information?
I did a bit of searching for a c/c++ example awhile back and came up empty.
James
From nowhere. Just trying.
QuoteFrom nowhere. Just trying.
What sets you apart from the rest of the crowd.
Kekule found the Benzol-Ring formula.
John.
WHY KEKULE?
I can tell you.
Kekule had a dream. And in that dream he got in contact with higher consciouness.
In that dream he saw the Benzol-Ring.
Now - what would have happened IF YOU had that same dream?
NOTHING. Because you know nothing about Chemistry and all that stuff.
Or if Kekule would had dreamed about a new motor technology?
NOTHING because he just would not had recognized it.
The same applies to Jose.
He knows that stuff and therefore he gets additional knowledge "from heaven".
This is how it works. It works for me, too.
Just not in Programming but in other fields where i am ahead of mainstream.
You need to work hard, get the Knowledge, and relax.
The rest comes from itself.
You don't know where dreams come from.
Possibly the "Tree of wisdom" as it was shown in the film "AVATAR" has some REAL Pedant in this world.
And we will recognize and connect to it one day.
PS: Lastly i got the knowledge on how to remove all sorts of rheumatic deseases. If you have that problem you may ask me.
I have not that kind of dreams. It's just a matter of logic. If MoveWindow is routinely used to change the size and/or position of windows and controls, why not to change the size of the listview header, that is nothing but a control?
José,
There is something amiss with the original code.
Make the window smaller so you have just the first two columns showing.
Use the listview horz scrollbar to scroll to the last column.
Now make the window bigger. the header does not size correctly
James
That is because the left position of the listview becomes negative. Calculate the displacement and adjust the parameters for MoveWIndow accordingly...
LOCAL pt AS POINT
ListView_GetItemPosition(hListView, 0, pt)
MoveWindow ListView_GetHeader(hListView), pt.x, 0, LO(WORD, lParam) + ABS(pt.x), <wanted height>, %TRUE
Thank you kind sir. Works fine now.
James
Hi Jose
How do you load an icon into CreateWindow() ?
I tried adding the following statements into your code but to no avail with error messages as
hwnd = pWindow.CreateWindow(%NULL, "Multiline Header ListView", %SS_ICON, 0, 0, 0, 0, -1, -1, CODEPTR(WindowProc))
pWindow.hIcon = LoadIcon (%NULL, "Logo")
Error 598 in C:\PB CWindows\Multi Header line ListView\CW_LV_MultilineHeader.bas(71:023): METHOD or PROPERTY name expected
Line 71: pWindow.hIcon = LoadIcon (%NULL, "Logo") ;
1) Do not use the %SS_ICON style. That style belongs to satic controls, not main windows.
2) You need to add a resource file to your application that contains the icon.
3) hIcon is not a method of the CWindow class
To load the icon from the embedded resource file, use:
pWindow.BigIcon = LoadIcon(pWindow.hInstance, "Logo")
pWindow.SmallIcon = LoadIcon(pWindow.hInstance, "Logo")
Many Thanks Jose
it works .
Hi Jose
Sorry to bother you again
In Dialogs, we can remove the minimize and maximize buttons as well as fixing the frame of the
dialog (so that users cannot resize the dialog). How do we manipulate these styles with CreateWindow() ?
Thank you in advance.
This has been resolved by having set the styles
hwnd = pWindow.CreateWindow(%NULL, "Multiline Header ListView", 0, 0, 0, 0,_
%WS_VISIBLE OR %WS_CAPTION OR %WS_SYSMENU, %WS_EX_WINDOWEDGE, CODEPTR(WindowProc))
Yes, I was going to post that you have to set the wanted styles instead of the default ones, e.g.
pWindow.CreateWindow(%NULL, "Multiline Header ListView", 0, 0, 0, 0, _
%WS_OVERLAPPED OR %WS_CAPTION OR %WS_SYSMENU OR %WS_THICKFRAME OR %WS_CLIPCHILDREN OR %WS_CLIPSIBLINGS, 0, CODEPTR(WindowProc))
Windows styles:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx
Thanks Jose
Hi Jose
How do you set the background color and forecolor within the ListView Control ?
I tried the following statement but saw no change
CONTROL SET COLOR hwnd, %IDC_LISTVIEW, RGB(0,100,0) ,RGB(255,248,220)
It works for dialog but looks like it can't work for the CWindow class
Thank you in advance
with this code
' // Paint the background
LOCAL hBrush AS DWORD
hBrush = CreateSolidBrush(RGB(228,120,51))
InflateRect @pnmcd.rc, -2, -2
FillRect @pnmcd.hdc, @pnmcd.rc, hBrush
SetBkMode @pnmcd.hdc, %TRANSPARENT
' // Change your text color here...
SetTextColor @pnmcd.hdc, RGB(92,51,23)
in the %CDDS_PREPAINT notification message.
Please note that you can't use DDT statements with SDK windows. DDT statements are only for DDT dialogs.
That was to change the color of the header in the multi heder example. If what you want to change is the color of the listview, then see this example:
' ########################################################################################
' Microsoft Windows
' File: CW_LV_CustomDraw_HDPI.pbtpl
' Contents: Template - CWindow with a custom draw ListView (High DPI)
' Compilers: PBWIN 10+, PBCC 6+
' Headers: Windows API headers III
' Copyright (c) 2014 José Roca. Freeware. Use at your own risk.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#COMPILE EXE
#DIM ALL
%UNICODE = 1
#INCLUDE ONCE "CWindow.inc" ' // CWindow class
#INCLUDE ONCE "ListViewCtrl.inc" ' // ListView control wrapper functions
%IDC_LISTVIEW = 1001
' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
' // Set process DPI aware
SetProcessDPIAware
' // Create an instance of the class
LOCAL pWindow AS IWindow
pWindow = CLASS "CWindow"
IF ISNOTHING(pWindow) THEN EXIT FUNCTION
' // Create the main window
LOCAL hwnd AS DWORD
hwnd = pWindow.CreateWindow(%NULL, "Custom Draw ListView (High DPI)", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
' // Change the class style to avoid flicker
pWindow.ClassStyle = %CS_DBLCLKS
' // Set the client size
pWindow.SetClientSize 565, 320
' // Center the window
pWindow.CenterWindow
' // Add a ListView control
LOCAL hListView AS DWORD
hListView = pWindow.AddListView(hwnd, %IDC_LISTVIEW, "", 0, 0, 0, 0)
' // Add some extended styles
LOCAL dwExStyle AS DWORD
dwExStyle = ListView_GetExtendedListViewStyle(hListView)
dwExStyle = dwExStyle OR %LVS_EX_FULLROWSELECT OR %LVS_EX_GRIDLINES
ListView_SetExtendedListViewStyle(hListView, dwExStyle)
' // Add the header's column names
LOCAL i AS LONG
FOR i = 0 TO 4
ListView_AddColumn(hListView, i, "Column" & STR$(i), pWindow.ScaleX(110))
NEXT
' // Populate the ListView with some data
FOR i = 0 to 29
ListView_AddItem(hListView, i, 0, "Column 0 Row" + STR$(i))
ListView_SetItemText(hListView, i, 1, "Column 1 Row" + STR$(i))
ListView_SetItemText(hListView, i, 2, "Column 2 Row" + STR$(i))
ListView_SetItemText(hListView, i, 3, "Column 3 Row" + STR$(i))
ListView_SetItemText(hListView, i, 4, "Column 4 Row" + STR$(i))
NEXT
' // Select the fist item
ListView_SelectItem hListView, 0
' // Set the focus in the ListView
SetFocus hListView
' // Default message pump (you can replace it with your own)
pWindow.DoEvents
END FUNCTION
' ########################################################################################
' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
STATIC pWindow AS IWindow ' // Reference to the IWindow interface
LOCAL pNmh AS NMHDR PTR ' // Pointer to a NMHDR structure
LOCAL pLvNm AS NMLISTVIEW PTR ' // Pointer to a NMLISTVIEW structure
LOCAL pLvCd AS NMLVCUSTOMDRAW PTR ' // Pointer to a NMLVCUSTOMDRAW structure
SELECT CASE uMsg
CASE %WM_CREATE
' // Get a reference to the IWindow interface from the CREATESTRUCT structure
pWindow = CWindow_GetObjectFromCreateStruct(lParam)
EXIT FUNCTION
CASE %WM_COMMAND
SELECT CASE LO(WORD, wParam)
' // End the application by sending a %WM_CLOSE message
CASE %IDCANCEL
IF HI(WORD, wParam) = %BN_CLICKED THEN
SendMessage hwnd, %WM_CLOSE, 0, 0
EXIT FUNCTION
END IF
END SELECT
CASE %WM_SIZE
' // Resize the ListView control and its header
IF wParam <> %SIZE_MINIMIZED THEN
LOCAL hListView AS DWORD
hListView = GetDlgItem(hwnd, %IDC_LISTVIEW)
pWindow.MoveWindow hListView, 5, 5, pWindow.ClientWidth - 10, pWindow.ClientHeight - 10, %TRUE
END IF
CASE %WM_NOTIFY
' // Processs notify messages sent by the list view control
pNmh = lParam
SELECT CASE @pNmh.idFrom
CASE %IDC_LISTVIEW
pLvNm = lParam
SELECT CASE @pLvNm.hdr.code
CASE %NM_CUSTOMDRAW
pLvCd = lParam
SELECT CASE @pLvCd.nmcd.dwDrawStage
CASE %CDDS_PREPAINT, %CDDS_ITEMPREPAINT
' // Tell the list view to send the %CDDS_ITEMPREPAINT OR %CDDS_SUBITEM notification message
FUNCTION = %CDRF_NOTIFYSUBITEMDRAW
EXIT FUNCTION
CASE %CDDS_ITEMPREPAINT OR %CDDS_SUBITEM
@pLvCd.clrTextBk = %RGB_PaleTurquoise
@pLvCd.clrText = %BLACK
' // Tell the list view to draw itself
FUNCTION = %CDRF_DODEFAULT
EXIT FUNCTION
END SELECT
END SELECT
END SELECT
CASE %WM_DESTROY
' // Close the main window
PostQuitMessage 0
EXIT FUNCTION
END SELECT
FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
END FUNCTION
' ========================================================================================
And this one changes the color of the first column to grey and alternates the color of the other columns in each line to pale turquoise and white.
' ########################################################################################
' Microsoft Windows
' File: CW_LV_CustomDraw_HDPI.pbtpl
' Contents: Template - CWindow with a custom draw ListView (High DPI)
' Compilers: PBWIN 10+, PBCC 6+
' Headers: Windows API headers III
' Copyright (c) 2014 José Roca. Freeware. Use at your own risk.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#COMPILE EXE
#DIM ALL
%UNICODE = 1
#INCLUDE ONCE "CWindow.inc" ' // CWindow class
#INCLUDE ONCE "ListViewCtrl.inc" ' // ListView control wrapper functions
%IDC_LISTVIEW = 1001
' ========================================================================================
' Main
' ========================================================================================
FUNCTION WinMain (BYVAL hInstance AS DWORD, BYVAL hPrevInstance AS DWORD, BYVAL lpszCmdLine AS WSTRINGZ PTR, BYVAL nCmdShow AS LONG) AS LONG
' // Set process DPI aware
SetProcessDPIAware
' // Create an instance of the class
LOCAL pWindow AS IWindow
pWindow = CLASS "CWindow"
IF ISNOTHING(pWindow) THEN EXIT FUNCTION
' // Create the main window
LOCAL hwnd AS DWORD
hwnd = pWindow.CreateWindow(%NULL, "Custom Draw ListView (High DPI)", 0, 0, 0, 0, 0, 0, CODEPTR(WindowProc))
' // Change the class style to avoid flicker
pWindow.ClassStyle = %CS_DBLCLKS
' // Set the client size
pWindow.SetClientSize 565, 320
' // Center the window
pWindow.CenterWindow
' // Add a ListView control
LOCAL hListView AS DWORD
hListView = pWindow.AddListView(hwnd, %IDC_LISTVIEW, "", 0, 0, 0, 0)
' // Add some extended styles
LOCAL dwExStyle AS DWORD
dwExStyle = ListView_GetExtendedListViewStyle(hListView)
dwExStyle = dwExStyle OR %LVS_EX_FULLROWSELECT OR %LVS_EX_GRIDLINES
ListView_SetExtendedListViewStyle(hListView, dwExStyle)
' // Add the header's column names
LOCAL i AS LONG
FOR i = 0 TO 4
ListView_AddColumn(hListView, i, "Column" & STR$(i), pWindow.ScaleX(110))
NEXT
' // Populate the ListView with some data
FOR i = 0 to 29
ListView_AddItem(hListView, i, 0, "Column 0 Row" + STR$(i))
ListView_SetItemText(hListView, i, 1, "Column 1 Row" + STR$(i))
ListView_SetItemText(hListView, i, 2, "Column 2 Row" + STR$(i))
ListView_SetItemText(hListView, i, 3, "Column 3 Row" + STR$(i))
ListView_SetItemText(hListView, i, 4, "Column 4 Row" + STR$(i))
NEXT
' // Select the fist item
ListView_SelectItem hListView, 0
' // Set the focus in the ListView
SetFocus hListView
' // Default message pump (you can replace it with your own)
pWindow.DoEvents
END FUNCTION
' ########################################################################################
' ========================================================================================
' Main callback function.
' ========================================================================================
FUNCTION WindowProc (BYVAL hwnd AS DWORD, BYVAL uMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
STATIC pWindow AS IWindow ' // Reference to the IWindow interface
LOCAL pNmh AS NMHDR PTR ' // Pointer to a NMHDR structure
LOCAL pLvNm AS NMLISTVIEW PTR ' // Pointer to a NMLISTVIEW structure
LOCAL pLvCd AS NMLVCUSTOMDRAW PTR ' // Pointer to a NMLVCUSTOMDRAW structure
SELECT CASE uMsg
CASE %WM_CREATE
' // Get a reference to the IWindow interface from the CREATESTRUCT structure
pWindow = CWindow_GetObjectFromCreateStruct(lParam)
EXIT FUNCTION
CASE %WM_COMMAND
SELECT CASE LO(WORD, wParam)
' // End the application by sending a %WM_CLOSE message
CASE %IDCANCEL
IF HI(WORD, wParam) = %BN_CLICKED THEN
SendMessage hwnd, %WM_CLOSE, 0, 0
EXIT FUNCTION
END IF
END SELECT
CASE %WM_SIZE
' // Resize the ListView control and its header
IF wParam <> %SIZE_MINIMIZED THEN
LOCAL hListView AS DWORD
hListView = GetDlgItem(hwnd, %IDC_LISTVIEW)
pWindow.MoveWindow hListView, 5, 5, pWindow.ClientWidth - 10, pWindow.ClientHeight - 10, %TRUE
END IF
CASE %WM_NOTIFY
' // Processs notify messages sent by the list view control
pNmh = lParam
SELECT CASE @pNmh.idFrom
CASE %IDC_LISTVIEW
pLvNm = lParam
SELECT CASE @pLvNm.hdr.code
CASE %NM_CUSTOMDRAW
pLvCd = lParam
SELECT CASE @pLvCd.nmcd.dwDrawStage
CASE %CDDS_PREPAINT, %CDDS_ITEMPREPAINT
' // Tell the list view to send the %CDDS_ITEMPREPAINT OR %CDDS_SUBITEM notification message
FUNCTION = %CDRF_NOTIFYSUBITEMDRAW
EXIT FUNCTION
CASE %CDDS_ITEMPREPAINT OR %CDDS_SUBITEM
IF @pLvCd.iSubItem = 0 THEN
' // Paint the first column with a gray background
@pLvCd.clrTextBk = %LTGRAY
@pLvCd.clrText = %BLACK
ELSE
IF (@pLvCd.nmcd.dwItemSpec MOD 2) = 0 THEN
' // Paint the columns of odd rows with a white background
@pLvCd.clrTextBk = %WHITE
@pLvCd.clrText = %BLACK
ELSE
' // Paint the columns of even rows with a pale turquoise background
@pLvCd.clrTextBk = %RGB_PaleTurquoise
@pLvCd.clrText = %BLACK
END IF
END IF
' // Tell the list view to draw itself
FUNCTION = %CDRF_DODEFAULT
EXIT FUNCTION
END SELECT
END SELECT
END SELECT
CASE %WM_DESTROY
' // Close the main window
PostQuitMessage 0
EXIT FUNCTION
END SELECT
FUNCTION = DefWindowProc(hwnd, uMsg, wParam, lParam)
END FUNCTION
' ========================================================================================
Many thanks Jose
These are truly awesome codes !
Sir Jose
How to make these ListViews editable whereby user can enter data into it?
Probably would need a series of textboxes to form an editable grid.
Thank you in advance.
Recently, there have been posts about it in the PB forum. See:
http://www.powerbasic.com/support/pbforums/showthread.php?t=59366&highlight=listview
Thanks Jose
But I wasn't able to access the site, probably it has gone down again?
Paul,
If you have Poffs installed, just type "59366" in the search box and you will get Gary's code...
Pierre
Thanks Pierre
But unfortunately I don't have the POFFs installed
If you want it, then you can download from Gary's site: POFFS (http://www.garybeene.com/sw/poffs.htm)
Thanks Pierre
finally got it
I appreciate your help