• Welcome to Jose's Read Only Forum 2023.
 

Increase header height

Started by James C. Fuller, April 21, 2013, 09:52:47 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

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

Paul Yuen


Paul Yuen

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

José Roca

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.

José Roca

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
' ========================================================================================


José Roca

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
' ========================================================================================


Paul Yuen

Many thanks Jose

These are truly awesome codes !

Paul Yuen

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.

José Roca


Paul Yuen

Thanks Jose

But I wasn't able to access the site, probably it has gone down again?

Pierre Bellisle

Paul,
If you have Poffs installed, just type "59366" in the search box and you will get Gary's code...

Pierre

Paul Yuen

Thanks Pierre

But unfortunately I don't have the POFFs installed

Pierre Bellisle

#27
If you want it, then you can download from Gary's site: POFFS

Paul Yuen

Thanks Pierre
finally got it
I appreciate your help