Announcement

Collapse
No announcement yet.

Listview with ProgressBar

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Listview with ProgressBar

    Listview has 2 columns.

    FileName | Progress
    ...
    ...

    Any ideas on how to do this with PB?



    ------------------
    -Greg
    -Greg
    [email protected]
    MCP,MCSA,MCSE,MCSD

  • #2
    Listview has 2 columns.
    FileName | Progress
    You could use a progressbar control instead of trying to use one of the listview columns as a progress bar. That's what I'd do.

    Or are you just trying to put progress text in the second column of the listview, like "processed 1234 of 5678 records?" In this case, you can just use the LVM_SETITEM message; or (again what I'd do), set up the listview to request callbacks for its text, and build the needed text string when the listview control asks for it.

    More Info / Better Description of underlying application needed.

    MCM


    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      I'm building a download manager for a client. He wants to be able
      to supply a filename with URL's and my program will download them.

      He also requests that it shows the filename and a Progress bar
      indicating the current process.

      Also he wants it to download all files at the same time.

      So I imagine something like Napster.

      I'm just wanting an easy way to do this. I'm leaning towards
      using the column in the listview as a progress bar, I think if
      I create 100's of Progress Bar controls, I might run into problems.

      Any ideas?

      ------------------
      -Greg



      [This message has been edited by Gregery D Engle (edited October 18, 2001).]
      -Greg
      [email protected]
      MCP,MCSA,MCSE,MCSD

      Comment


      • #4
        Just found out a good feature WM_PRINT and WM_PRINTCLIENT

        This might 'print' a hidden progressbar to a hdc (like an ownerdrawn listview?)

        It's not a good idea to use separate controls.


        ------------------
        http://www.hellobasic.com
        hellobasic

        Comment


        • #5
          Here you have an example.
          An example for an ownerdraw lv is prob. to be find here too..

          To PB, %WM_PRINT is not declared..


          Code:
          #Compile Exe
           
          Option Explicit
           
          #include "win32api.inc"
          #include "Commctrl.inc"
           
          '%PRF_CHECKVISIBLE = &H00000001
          '%PRF_NONCLIENT = &H00000002
          '%PRF_CLIENT = &H00000004
          '%PRF_ERASEBKGND = &H00000008
          '%PRF_CHILDREN = &H00000010
          '%PRF_OWNED = &H00000020
          %WM_PRINT = &H317
           
          CallBack Function DlgProc() As Long
           
              Dim a   As Long
              Dim R   As Rect
              Dim PS  As PAINTSTRUCT
              Dim T   As String
           
              Select Case CbMsg
              Case %WM_INITDIALOG
           
                  Control Add "msctls_progress32", CbHndl, 100, "", 10, 10, 100, 10, %WS_CHILD' Or %WS_VISIBLE
           
                  Control Send CbHndl, 100, %PBM_SETPOS, 50, 0
           
              Case %WM_PAINT
           
                  BeginPaint CbHndl, PS
                  Control Send CbHndl, 100, %WM_PRINT, PS.hDC, %PRF_CLIENT Or %PRF_ERASEBKGND Or %PRF_NONCLIENT
                  EndPaint   CbHndl, PS
                  Function = 1
                  Exit Function
           
              Case %WM_COMMAND
              Case %WM_SIZE
              Case %WM_SETCURSOR
              Case %WM_DESTROY
              End Select
           
          End Function
           
          Function WinMain ( ByVal hCurInstance  As Long, _
                             ByVal hPrevInstance As Long, _
                             lpszCmdLine         As Asciiz Ptr, _
                             ByVal nCmdShow      As Long ) As Long
           
              Dim a       As Long
              Dim hDlg    As Long
              Dim Result  As Long
           
              Dialog New 0, "What you see is not the progressbar but a painting of it.",,, 240, 180 _
                  ,  %WS_OVERLAPPED _
                  Or %WS_SYSMENU _
                  Or %WS_MINIMIZEBOX _
                  Or %WS_MAXIMIZEBOX _
                  Or %WS_THICKFRAME _
                  Or %WS_CLIPSIBLINGS _
                  Or %WS_CLIPCHILDREN _
                  To hDlg
           
              If hDlg = 0 Then Exit Function
           
              Dialog Show Modal hDlg Call DlgProc To Result
           
              Function = 1
           
          End Function
          ------------------
          http://www.hellobasic.com
          hellobasic

          Comment


          • #6
            Main common controls support NM_CUSTOMDRAW since 4.70 (IE 3).
            It's analog of WM_DRAWITEM.


            ------------------
            E-MAIL: [email protected]

            Comment


            • #7
              Edwin,

              Your code is interesting. How do I specify x,y,xx,yy cordinates?

              I'm thinking of doing sometihng like this:

              DrawProgress hWnd&, Percentage&, x, y, xx, yy, style&

              I assume I could use the hwnd from the Listview instead of the
              dialog. And get location of the column, row and draw it in the
              listview.

              any ideas?

              ------------------
              -Greg

              [This message has been edited by Gregery D Engle (edited October 18, 2001).]
              -Greg
              [email protected]
              MCP,MCSA,MCSE,MCSD

              Comment


              • #8
                Based on your application description, maybe you could create a dialog something like this:

                Code:
                 ---------------------------------------
                 Listbox with list of files to process
                 File1
                 File2
                File3     <<<< Current file highlited
                 ----------------------------------------
                
                 Label  "Now Processing File3"
                
                 Progressbar "percentage of total files downloaded"
                   or 
                 Label  "Processing file # 3 of 22 total files"
                
                 Progressbar "percentage of current file completed"
                As each file is being worked on, you can SELECT it in the Listbox so it is highlighted; and reset the two progress controls.

                That said, "I freely admit and acknowledge I am reall pretty crummy on user interface design."

                MCM


                Michael Mattias
                Tal Systems Inc. (retired)
                Racine WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Michael,

                  I would love to be able to do your method, but client says Nope.
                  has to look like Napster.

                  I'm sure if I can figure out how to use Edwin's example like
                  this:

                  DrawProgress hWnd&, Percentage&, x, y, xx, yy, style&

                  I'll be set.

                  ------------------
                  -Greg
                  -Greg
                  [email protected]
                  MCP,MCSA,MCSE,MCSD

                  Comment


                  • #10
                    Gregery,

                    I would like to build it all for you but... time!

                    maybe this weekend?



                    ------------------
                    http://www.hellobasic.com
                    hellobasic

                    Comment


                    • #11
                      Edwin,

                      Thanks for the nice offer, I'm sure if I get pointed in the
                      right direction I could do it. In anycase, my email address
                      is [email protected] if you want to work on this with me.



                      ------------------
                      -Greg
                      -Greg
                      [email protected]
                      MCP,MCSA,MCSE,MCSD

                      Comment


                      • #12
                        I'm stuck here.

                        I thought about what Edwin was saying and I think what I need to
                        do is BltBlt the DC of the ProgressBar to the DC of the ListView
                        control, at the cordinates of the Second Column. Am I right?

                        In any case, I can't get the picture to show up at all. Do I have
                        to use %WM_PRINT?

                        here is what I have so far

                        Code:
                        #COMPILE EXE
                        #INCLUDE "win32api.inc"
                        #INCLUDE "commctrl.inc"
                        #RESOURCE "c:\pbdll60\samples\tray\tray.pbr"
                        
                        %LISTVIEW1 = 100
                        %PROGRESSBAR1 = 101
                        %MNU_LOAD_DOWNLOADLIST = 500
                        %MNU_OPTIONS = 501
                        %MNU_EXIT = 502
                        
                        
                        SUB LV_AddItem(hListView&, sTitle$, lMask&, lStateMask&, lPos&)
                           LOCAL azItemText AS ASCIIZ * %MAX_PATH
                           LOCAL lvITEM AS LV_ITEM
                           azItemText = sTitle$
                           lvITEM.iImage = 0
                           lvITEM.iItem = ListView_GetItemCount(hListView&)
                           lvITEM.mask = %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM
                           lvITEM.stateMask =  lStateMask&
                           lvITEM.pszText = VARPTR(azItemText)
                           lStatus& = ListView_InsertItem (hListView&, lvITEM)
                        END SUB
                        
                        SUB LV_CreateColumn(hListView&, sTitle$, lMask&, lWidth&, lPos&)
                            LOCAL azTitle AS ASCIIZ * 25
                            LOCAL Column AS LV_COLUMN
                        
                            azTitle = sTitle$
                            Column.mask = lMask&
                            Column.fmt = %LVCFMT_LEFT
                            Column.cx = lWidth&
                            Column.pszText = VARPTR(azTitle)
                            ListView_InsertColumn hListView&, lPos&, Column
                        END SUB
                        
                        FUNCTION LVW_GetSelected(hListView&) AS LONG
                            ListCount& = ListView_GetItemCount(hListView&)
                            FOR a& = 0 TO ListCount&
                                r& = ListView_GetItemState(hListView&,a&,%LVIS_FOCUSED)
                                IF r& = %LVIS_FOCUSED THEN
                                    FUNCTION = a&
                                    EXIT FUNCTION
                                END IF
                            NEXT
                        END FUNCTION
                        
                        SUB DrawProgress(hListView&,hProgressBar&, Percentage&, x&, y&, xx&, yy&, style&)
                            LOCAL tmpRect AS RECT
                            LOCAL pt AS POINTAPI
                        
                            tmpRect.nLeft = 0
                            lPos& = LVW_GetSelected(hListView&)
                        
                            woot& = SendMessage(hListView&, %LVM_GETITEMRECT, lPos&, VARPTR(tmpRect))
                        
                            BitBlt GetDC(hListView&), 0, tmpRect.nTop + 1, 2, tmpRect.nBottom - tmpRect.nTop, GetDC(hProgressBar&), 0, 0, %SRCCOPY
                        END SUB
                        
                        FUNCTION WndProc (BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, _
                                          BYVAL wParam AS LONG, BYVAL lParam AS LONG) EXPORT AS LONG
                            LOCAL rect AS rect
                            LOCAL LV_LpLvNm AS NM_LISTVIEW PTR
                            STATIC hListView&
                            STATIC hProgressBar&
                        
                            SELECT CASE wMsg
                                CASE %WM_NOTIFY
                                     SELECT CASE LOWRD(wParam)
                                         CASE %LISTVIEW1
                                            LV_LPLVNM = lParam
                                            SELECT CASE @LV_LPLVNM.HDR.CODE
                                                CASE %NM_CLICK
                                                     DrawProgress hListView&, hProgressBar&, 0, 0, 0, 0, 0, 0
                                                CASE %NM_RCLICK
                                                    'debug_print "Right Mouse"
                                                CASE %LVN_COLUMNCLICK
                                                    'debug_print "Column Click"
                                            END SELECT
                                     END SELECT
                                CASE %WM_CREATE
                                    GETCLIENTRECT hWnd, rect
                                    
                                    hProgressBar& = CREATEWINDOW ( "msctls_progress32", _
                                                "", _
                                                %WS_CHILD, _
                                                200, _
                                                300, _
                                                100, _
                                                10, _
                                                hWnd, _
                                                %PROGRESSBAR1, _
                                                GETMODULEHANDLE(BYVAL 0&), _
                                                %Null )
                                    sendmessage hListView&, %PBM_SETPOS, 75, 0
                                                            
                        
                                    hListView& = CREATEWINDOW ( "SysListView32", _
                                                "", _
                                                %WS_border OR %WS_Child OR %WS_visible OR _
                                                %LVS_Report OR %LVS_SINGLESEL OR %LVS_SHOWSELALWAYS, _
                                                0, _
                                                0, _
                                                rect.nRight - 1, _
                                                rect.nBottom - 1, _
                                                hWnd, _
                                                %LISTVIEW1, _
                                                GETMODULEHANDLE(BYVAL 0&), _
                                                %Null )
                                    
                                    
                                    LV_CreateColumn hListView&, "Downloading", %LVCF_FMT OR %LVCF_WIDTH OR %LVCF_TEXT OR %LVCF_SUBITEM, 300, 0
                                    LV_CreateColumn hListView&, "Progress", %LVCF_FMT OR %LVCF_WIDTH OR %LVCF_TEXT OR %LVCF_SUBITEM, 200, 1
                                    LV_CreateColumn hListView&, "Size", %LVCF_FMT OR %LVCF_WIDTH OR %LVCF_TEXT OR %LVCF_SUBITEM, 100, 2
                        
                                    LV_AddItem hListView&, "File1", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    LV_AddItem hListView&, "File1", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    LV_AddItem hListView&, "File2", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    LV_AddItem hListView&, "File3", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    LV_AddItem hListView&, "File4", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    LV_AddItem hListView&, "File5", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    LV_AddItem hListView&, "File6", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    LV_AddItem hListView&, "File7", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                        
                                    MENU NEW BAR TO hMenu0&
                                    MENU NEW POPUP TO hMenu1&
                                    MENU ADD POPUP, hMenu0& ,"&File", hMenu1&, %MF_ENABLED
                                    MENU ADD STRING, hMenu1&, "&Load Download List",  %MNU_LOAD_DOWNLOADLIST, %MF_ENABLED
                                    MENU ADD STRING, hMenu1&, "-",  0, %MF_ENABLED
                                    MENU ADD STRING, hMenu1&, "Options",  %MNU_OPTIONS, %MF_ENABLED
                                    MENU ADD STRING, hMenu1&, "E&xit",  %MNU_EXIT, %MF_ENABLED
                                    MENU ATTACH hMenu0&, hWnd
                                CASE %WM_DESTROY
                                    POSTQUITMESSAGE 0
                            END SELECT
                        
                        FUNCTION = DEFWINDOWPROC(hWnd, wMsg, wParam, lParam)
                        END FUNCTION
                        
                        FUNCTION WINMAIN (BYVAL hInstance     AS LONG, _
                                          BYVAL hPrevInstance AS LONG, _
                                          lpCmdLine           AS ASCIIZ PTR, _
                                          BYVAL iCmdShow      AS LONG) AS LONG
                        
                          LOCAL Msg         AS tagMsg
                          LOCAL wndclass    AS WndClassEx
                          LOCAL szClassName AS ASCIIZ * 80
                          LOCAL hWnd        AS LONG
                          LOCAL CC1 AS INIT_COMMON_CONTROLSEX
                        
                          CC1.dwSize=SIZEOF(CC1)
                          CC1.dwICC=%ICC_WIN95_CLASSES
                          INITCOMMONCONTROLSEX CC1
                        
                          szClassName            = "SDK_LISTVIEW"
                          wndclass.cbSize        = SIZEOF(WndClass)
                          wndclass.style         = %CS_HREDRAW OR %CS_VREDRAW
                          wndclass.lpfnWndProc   = CODEPTR( WndProc )
                          wndclass.cbClsExtra    = 0
                          wndclass.cbWndExtra    = 0
                          wndclass.hInstance     = hInstance
                          wndclass.hIcon         = LOADICON( hInstance, "FACE1")
                          wndclass.hCursor       = LOADCURSOR( %NULL, BYVAL %IDC_ARROW )
                          wndclass.hbrBackground = GETSTOCKOBJECT( %GRAY_BRUSH )
                          wndclass.lpszMenuName  = %NULL
                          wndclass.lpszClassName = VARPTR( szClassName )
                          wndclass.hIconSm       = 0
                          REGISTERCLASSEX wndclass
                          hWnd = CREATEWINDOWEX(%WS_EX_TOPMOST, _
                                                  szClassName, _
                                                  "WebGet 1.0", _
                                                  %DS_CENTER _
                                                  OR %WS_CAPTION  _
                                                  OR %WS_SYSMENU , _
                                                  0, _
                                                  0, _
                                                  700&, _
                                                  300&, _
                                                  %NULL, _
                                                  %NULL, _
                                                  hInstance, _
                                                  BYVAL %NULL)
                        
                          SHOWWINDOW hWnd, iCmdShow
                          UPDATEWINDOW hWnd
                        
                            WHILE ISTRUE GETMESSAGE(Msg, %NULL, 0, 0)
                                TRANSLATEMESSAGE msg
                                DISPATCHMESSAGE msg
                            WEND
                            SLEEP 1
                          FUNCTION = msg.wParam
                        
                        END FUNCTION
                        ------------------
                        -Greg



                        [This message has been edited by Gregery D Engle (edited October 19, 2001).]
                        -Greg
                        [email protected]
                        MCP,MCSA,MCSE,MCSD

                        Comment


                        • #13
                          Several things: DC must be released - and why use Pogressbar at all?
                          Rewrote it a bit - no progbar, all is drawn "by hand" in DrawProgress.
                          Can be done prettier - Semen has posted some fine samples of this, with
                          different colors on text, etc, but at least it shows a way that works.

                          Note - painting does not "stick" if dialog is covered. Better to
                          sub-class the listview and make sure DrawProgress is triggered in
                          its WM_ERASEBKGND, to make it "stick" properly in all situations.
                          Code:
                          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          ' Eliminate unnecessary macros for COMMCTRL.INC
                          '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                          %NOANIMATE       = 1
                          %NOBUTTON        = 1
                          %NOCOMBO         = 1
                          %NODATETIMEPICK  = 1
                          %NODRAGLIST      = 1
                          %NOEDIT          = 1
                          %NOFLATSBAPIS    = 1
                          %NOHEADER        = 1
                          %NOHOTKEY        = 1
                          %NOIMAGELIST     = 1
                          %NOIPADDRESS     = 1
                          %NOLIST          = 1
                          '%NOLISTVIEW      = 1
                          %NOMONTHCAL      = 1
                          %NONATIVEFONTCTL = 1
                          %NOPAGESCROLLER  = 1
                          %NOPROGRESS      = 1
                          %NOREBAR         = 1
                          %NOSTATUSBAR     = 1
                          %NOTABCONTROL    = 1
                          %NOTOOLBAR       = 1
                          %NOTOOLTIPS      = 1
                          %NOTRACKBAR      = 1
                          %NOTREEVIEW      = 1
                          %NOUPDOWN        = 1
                          '------------------------------------------------------------------------------
                          #COMPILE EXE
                          #INCLUDE "WIN32API.INC"
                          #INCLUDE "COMMCTRL.INC"
                          #RESOURCE "c:\pbdll60\samples\tray\tray.pbr"
                          '------------------------------------------------------------------------------
                          %LISTVIEW1 = 100
                          %MNU_LOAD_DOWNLOADLIST = 500
                          %MNU_OPTIONS = 501
                          %MNU_EXIT = 502
                          '------------------------------------------------------------------------------
                           
                          SUB LV_AddItem(hListView&, sTitle$, lMask&, lStateMask&, lPos&)
                            LOCAL azItemText AS ASCIIZ * %MAX_PATH
                            LOCAL lvITEM AS LV_ITEM
                             azItemText = sTitle$
                             lvITEM.iImage = 0
                             lvITEM.iItem = ListView_GetItemCount(hListView&)
                             lvITEM.mask = %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM
                             lvITEM.stateMask =  lStateMask&
                             lvITEM.pszText = VARPTR(azItemText)
                             lStatus& = ListView_InsertItem (hListView&, lvITEM)
                          END SUB
                           
                          SUB LV_CreateColumn(hListView&, sTitle$, lMask&, lWidth&, lPos&)
                            LOCAL azTitle AS ASCIIZ * 25
                            LOCAL Column AS LV_COLUMN
                            azTitle = sTitle$
                            Column.mask = lMask&
                            Column.fmt = %LVCFMT_LEFT
                            Column.cx = lWidth&
                            Column.pszText = VARPTR(azTitle)
                            ListView_InsertColumn hListView&, lPos&, Column
                          END SUB
                           
                          FUNCTION LVW_GetSelected(hListView&) AS LONG
                            ListCount& = ListView_GetItemCount(hListView&)
                            FOR a& = 0 TO ListCount&
                                r& = ListView_GetItemState(hListView&,a&,%LVIS_FOCUSED)
                                IF r& = %LVIS_FOCUSED THEN
                                   FUNCTION = a&
                                   EXIT FUNCTION
                                END IF
                            NEXT
                          END FUNCTION
                           
                          SUB DrawProgress(hListView&, Percentage&)
                            LOCAL cw1 AS LONG, cw2 AS LONG, tmpRect AS RECT, zTxt AS ASCIIZ * 20
                            LOCAL hDcLV AS LONG
                           
                            hDcLv = GetDC(hListView&)
                              lPos& = LVW_GetSelected(hListView&)
                              ListView_GetItemRect hListView&, lPos&, tmpRect, %LVIR_BOUNDS 'for column height
                              cw1 = ListView_GetColumnWidth(hListView&, 0) 'width of column 1
                              cw2 = ListView_GetColumnWidth(hListView&, 1) 'width of column 2
                           
                              tmpRect.nLeft  = cw1
                              tmpRect.nRight = cw1 + cw2 * Percentage& / 100
                              FillRect hDcLv, tmpRect, GetSysColorBrush(%COLOR_3DFACE)
                           
                              tmpRect.nLeft  = tmpRect.nRight
                              tmpRect.nRight = cw1 + cw2
                              FillRect hDcLv, tmpRect, GetSysColorBrush(%COLOR_WINDOW)
                           
                              tmpRect.nLeft = cw1
                              SetBkMode hDcLv, %TRANSPARENT
                              SetTextColor hDcLv, %BLUE
                              zTxt = FORMAT$(Percentage&) + "%"
                              DrawText hDcLv, zTxt, LEN(zTxt), tmpRect, %DT_CENTER OR %DT_SINGLELINE OR %DT_VCENTER
                            ReleaseDc hListView&, hDcLv
                          END SUB
                           
                          FUNCTION WndProc (BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, _
                                            BYVAL wParam AS LONG, BYVAL lParam AS LONG) EXPORT AS LONG
                            LOCAL rect AS rect
                            LOCAL LV_LpLvNm AS NM_LISTVIEW PTR
                            STATIC hListView&
                           
                            SELECT CASE wMsg
                                CASE %WM_NOTIFY
                                     SELECT CASE LOWRD(wParam)
                                         CASE %LISTVIEW1
                                            LV_LPLVNM = lParam
                                            SELECT CASE @LV_LPLVNM.HDR.CODE
                                                CASE %NM_CLICK
                                                   STATIC I AS LONG
                                                   FOR I = 1 TO 100
                                                      DrawProgress hListView&, I
                                                      SLEEP 20
                                                   NEXT
                                                   beep
                           
                                                CASE %NM_RCLICK
                                                    'debug_print "Right Mouse"
                                                CASE %LVN_COLUMNCLICK
                                                    'debug_print "Column Click"
                                            END SELECT
                                     END SELECT
                           
                                CASE %WM_CREATE
                                    GETCLIENTRECT hWnd, rect
                           
                                    hListView& = CREATEWINDOW ( "SysListView32", _
                                                "", _
                                                %WS_border OR %WS_Child OR %WS_visible OR _
                                                %LVS_Report OR %LVS_SINGLESEL OR %LVS_SHOWSELALWAYS, _
                                                0, _
                                                0, _
                                                rect.nRight - 1, _
                                                rect.nBottom - 1, _
                                                hWnd, _
                                                %LISTVIEW1, _
                                                GETMODULEHANDLE(BYVAL 0&), _
                                                %Null )
                           
                                    LV_CreateColumn hListView&, "Downloading", %LVCF_FMT OR %LVCF_WIDTH OR %LVCF_TEXT OR %LVCF_SUBITEM, 300, 0
                                    LV_CreateColumn hListView&, "Progress", %LVCF_FMT OR %LVCF_WIDTH OR %LVCF_TEXT OR %LVCF_SUBITEM, 200, 1
                                    LV_CreateColumn hListView&, "Size", %LVCF_FMT OR %LVCF_WIDTH OR %LVCF_TEXT OR %LVCF_SUBITEM, 100, 2
                                    LV_AddItem hListView&, "File1", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    LV_AddItem hListView&, "File1", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    LV_AddItem hListView&, "File2", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    LV_AddItem hListView&, "File3", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    LV_AddItem hListView&, "File4", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    LV_AddItem hListView&, "File5", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    LV_AddItem hListView&, "File6", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    LV_AddItem hListView&, "File7", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    MENU NEW BAR TO hMenu0&
                                    MENU NEW POPUP TO hMenu1&
                                    MENU ADD POPUP, hMenu0& ,"&File", hMenu1&, %MF_ENABLED
                                    MENU ADD STRING, hMenu1&, "&Load Download List",  %MNU_LOAD_DOWNLOADLIST, %MF_ENABLED
                                    MENU ADD STRING, hMenu1&, "-",  0, %MF_ENABLED
                                    MENU ADD STRING, hMenu1&, "Options",  %MNU_OPTIONS, %MF_ENABLED
                                    MENU ADD STRING, hMenu1&, "E&xit",  %MNU_EXIT, %MF_ENABLED
                                    MENU ATTACH hMenu0&, hWnd
                           
                                CASE %WM_DESTROY
                                    POSTQUITMESSAGE 0
                           
                            END SELECT
                            FUNCTION = DEFWINDOWPROC(hWnd, wMsg, wParam, lParam)
                          END FUNCTION
                           
                          FUNCTION WINMAIN (BYVAL hInstance     AS LONG, _
                                            BYVAL hPrevInstance AS LONG, _
                                            lpCmdLine           AS ASCIIZ PTR, _
                                            BYVAL iCmdShow      AS LONG) AS LONG
                            LOCAL Msg         AS tagMsg
                            LOCAL wndclass    AS WndClassEx
                            LOCAL szClassName AS ASCIIZ * 80
                            LOCAL hWnd        AS LONG
                            LOCAL CC1 AS INIT_COMMON_CONTROLSEX
                           
                            CC1.dwSize=SIZEOF(CC1)
                            CC1.dwICC=%ICC_WIN95_CLASSES
                            INITCOMMONCONTROLSEX CC1
                           
                            szClassName            = "SDK_LISTVIEW"
                            wndclass.cbSize        = SIZEOF(WndClass)
                            wndclass.style         = %CS_HREDRAW OR %CS_VREDRAW
                            wndclass.lpfnWndProc   = CODEPTR( WndProc )
                            wndclass.cbClsExtra    = 0
                            wndclass.cbWndExtra    = 0
                            wndclass.hInstance     = hInstance
                            wndclass.hIcon         = LOADICON( hInstance, "FACE1")
                            wndclass.hCursor       = LOADCURSOR( %NULL, BYVAL %IDC_ARROW )
                            wndclass.hbrBackground = GETSTOCKOBJECT( %GRAY_BRUSH )
                            wndclass.lpszMenuName  = %NULL
                            wndclass.lpszClassName = VARPTR( szClassName )
                            wndclass.hIconSm       = 0
                            REGISTERCLASSEX wndclass
                            hWnd = CREATEWINDOWEX(%WS_EX_TOPMOST, _
                                                   szClassName, _
                                                   "WebGet 1.0", _
                                                   %DS_CENTER _
                                                   OR %WS_CAPTION  _
                                                   OR %WS_SYSMENU , _
                                                   0, _
                                                   0, _
                                                   700&, _
                                                   300&, _
                                                   %NULL, _
                                                   %NULL, _
                                                   hInstance, _
                                                   BYVAL %NULL)
                           
                            SHOWWINDOW hWnd, iCmdShow
                            UPDATEWINDOW hWnd
                           
                            WHILE ISTRUE GETMESSAGE(Msg, %NULL, 0, 0)
                               TRANSLATEMESSAGE msg
                               DISPATCHMESSAGE msg
                            WEND
                            SLEEP 1
                           
                            FUNCTION = msg.wParam
                          END FUNCTION
                          ------------------
                          Corrected path to resource file, plus removed garbage from DrawProgess.
                          See Edwin posted another way. Always fun to see all ways one can use..


                          [This message has been edited by Borje Hagsten (edited October 19, 2001).]

                          Comment


                          • #14
                            Darn, someone is before me!

                            I rewrote it a little to get you started.
                            You should use the wm_drawitem (ownerdraw style)

                            See the progressbar in your left side, incorrect of course but you'll notice my point..


                            Code:
                            #Compile Exe
                            #include "win32api.inc"
                            #include "commctrl.inc"
                            #Resource "c:\pbdll60\samples\tray\tray.pbr"
                             
                             
                            %LISTVIEW1 = 100
                            %PROGRESSBAR1 = 101
                            %MNU_LOAD_DOWNLOADLIST = 500
                            %MNU_OPTIONS = 501
                            %MNU_EXIT = 502
                             
                            %WM_PRINT = &H317
                             
                             
                            Sub LV_AddItem(hListView&, sTitle$, lMask&, lStateMask&, lPos&)
                               Local azItemText As Asciiz * %MAX_PATH
                               Local lvITEM As LV_ITEM
                               azItemText = sTitle$
                               lvITEM.iImage = 0
                               lvITEM.iItem = ListView_GetItemCount(hListView&)
                               lvITEM.mask = %LVCF_FMT Or %LVCF_WIDTH Or  %LVCF_TEXT Or %LVCF_SUBITEM
                               lvITEM.stateMask =  lStateMask&
                               lvITEM.pszText = VarPtr(azItemText)
                               lStatus& = ListView_InsertItem (hListView&, lvITEM)
                            End Sub
                             
                            Sub LV_CreateColumn(hListView&, sTitle$, lMask&, lWidth&, lPos&)
                                Local azTitle As Asciiz * 25
                                Local Column As LV_COLUMN
                             
                                azTitle = sTitle$
                                Column.mask = lMask&
                                Column.fmt = %LVCFMT_LEFT
                                Column.cx = lWidth&
                                Column.pszText = VarPtr(azTitle)
                                ListView_InsertColumn hListView&, lPos&, Column
                            End Sub
                             
                            Function LVW_GetSelected(hListView&) As Long
                                ListCount& = ListView_GetItemCount(hListView&)
                                For a& = 0 To ListCount&
                                    r& = ListView_GetItemState(hListView&,a&,%LVIS_FOCUSED)
                                    If r& = %LVIS_FOCUSED Then
                                        Function = a&
                                        Exit Function
                                    End If
                                Next
                            End Function
                             
                            Sub DrawProgress( hListView& , hProgressBar&, Percentage&, x&, y&, xx&, yy&, style&)
                             
                                Local tmpRect As RECT
                                Local pt As POINTAPI
                             
                                tmpRect.nLeft = 0
                                lPos& = LVW_GetSelected(hListView&)
                             
                                woot& = SendMessage(hListView&, %LVM_GETITEMRECT, lPos&, VarPtr(tmpRect))
                             
                                Dim hMemDC As Long
                             
                             
                            '    BitBlt GetDC(hListView&), 0, tmpRect.nTop + 1, 2, tmpRect.nBottom - tmpRect.nTop, hBitMap, 0, 0, %SRCCOPY
                             
                             
                             
                            End Sub
                             
                            Function WndProc (ByVal hWnd As Long, ByVal wMsg As Long, _
                                              ByVal wParam As Long, ByVal lParam As Long) Export As Long
                                Local rect As rect
                                Local LV_LpLvNm As NM_LISTVIEW Ptr
                                Static hListView&
                                Static hProgressBar&
                             
                                Select Case wMsg
                                    Case %WM_NOTIFY
                                         Select Case LoWrd(wParam)
                                             Case %LISTVIEW1
                                                LV_LPLVNM = lParam
                                                Select Case @LV_LPLVNM.HDR.CODE
                                                    Case %NM_CLICK
                                                         DrawProgress hListView&, hProgressBar&, 0, 0, 0, 0, 0, 0
                                                    Case %NM_RCLICK
                                                        'debug_print "Right Mouse"
                                                    Case %LVN_COLUMNCLICK
                                                        'debug_print "Column Click"
                                                End Select
                                         End Select
                                    Case %WM_CREATE
                                        GETCLIENTRECT hWnd, rect
                             
                                        hProgressBar& = CREATEWINDOW ( "msctls_progress32", _
                                                    "", _
                                                    %WS_CHILD, _
                                                    200, _
                                                    300, _
                                                    100, _
                                                    10, _
                                                    hWnd, _
                                                    %PROGRESSBAR1, _
                                                    GETMODULEHANDLE(ByVal 0&), _
                                                    %Null )
                                        sendmessage hListView&, %PBM_SETPOS, 75, 0
                             
                             
                                        hListView& = CREATEWINDOW ( "SysListView32", _
                                                    "", _
                                                    %WS_border Or %WS_Child Or %WS_visible Or _
                                                    %LVS_Report Or %LVS_SINGLESEL Or %LVS_SHOWSELALWAYS Or %LVS_OWNERDRAWFIXED, _
                                                    0, _
                                                    0, _
                                                    rect.nRight - 1, _
                                                    rect.nBottom - 1, _
                                                    hWnd, _
                                                    %LISTVIEW1, _
                                                    GETMODULEHANDLE(ByVal 0&), _
                                                    %Null )
                             
                             
                                        LV_CreateColumn hListView&, "Downloading", %LVCF_FMT Or %LVCF_WIDTH Or %LVCF_TEXT Or %LVCF_SUBITEM, 300, 0
                                        LV_CreateColumn hListView&, "Progress", %LVCF_FMT Or %LVCF_WIDTH Or %LVCF_TEXT Or %LVCF_SUBITEM, 200, 1
                                        LV_CreateColumn hListView&, "Size", %LVCF_FMT Or %LVCF_WIDTH Or %LVCF_TEXT Or %LVCF_SUBITEM, 100, 2
                             
                                        LV_AddItem hListView&, "File1", %LVCF_FMT Or %LVCF_WIDTH Or  %LVCF_TEXT Or %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                        LV_AddItem hListView&, "File1", %LVCF_FMT Or %LVCF_WIDTH Or  %LVCF_TEXT Or %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                        LV_AddItem hListView&, "File2", %LVCF_FMT Or %LVCF_WIDTH Or  %LVCF_TEXT Or %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                        LV_AddItem hListView&, "File3", %LVCF_FMT Or %LVCF_WIDTH Or  %LVCF_TEXT Or %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                        LV_AddItem hListView&, "File4", %LVCF_FMT Or %LVCF_WIDTH Or  %LVCF_TEXT Or %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                        LV_AddItem hListView&, "File5", %LVCF_FMT Or %LVCF_WIDTH Or  %LVCF_TEXT Or %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                        LV_AddItem hListView&, "File6", %LVCF_FMT Or %LVCF_WIDTH Or  %LVCF_TEXT Or %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                        LV_AddItem hListView&, "File7", %LVCF_FMT Or %LVCF_WIDTH Or  %LVCF_TEXT Or %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                             
                                        Menu New Bar To hMenu0&
                                        Menu New Popup To hMenu1&
                                        Menu Add Popup, hMenu0& ,"&File", hMenu1&, %MF_ENABLED
                                        Menu Add String, hMenu1&, "&Load Download List",  %MNU_LOAD_DOWNLOADLIST, %MF_ENABLED
                                        Menu Add String, hMenu1&, "-",  0, %MF_ENABLED
                                        Menu Add String, hMenu1&, "Options",  %MNU_OPTIONS, %MF_ENABLED
                                        Menu Add String, hMenu1&, "E&xit",  %MNU_EXIT, %MF_ENABLED
                                        Menu Attach hMenu0&, hWnd
                             
                             
                            '================================================
                             
                             
                             
                                    Case %WM_DRAWITEM
                             
                             
                                Dim hDC As Long
                                Dim hBitmapDC As Long
                                Dim hBitMap As Long
                                Dim hOldBitMap As Long
                                 Dim pDIS As DRAWITEMSTRUCT Ptr
                             pDIS =lParam
                             
                                hDC = GetDC( %HWND_DESKTOP )
                                hBitmapDC = CreateCompatibleDC( hDC )
                                hBitMap = CreateCompatibleBitmap( hDC, 100, 100 )
                             
                                hOldBitMap  = SelectObject( hBitMapDC, hBitMap )
                             
                                SendMessage hProgressBar&, %WM_PRINT, hBitMapDC, %PRF_CLIENT Or %PRF_ERASEBKGND Or %PRF_NONCLIENT
                             
                             
                                BitBlt @pDIS.hDC _
                                    , @pDIS.rcItem.nLeft, @pDIS.rcItem.nTop, @pDIS.rcItem.nRight - @pDIS.rcItem.nLeft, @pDIS.rcItem.nBottom - @pDIS.rcItem.nTop _
                                    , hBitMapDC _
                                    , 0, 0 _
                                    , %SRCCOPY
                             
                                SelectObject hBitMapDC, hOldBitmap
                                DeleteObject hBitmap
                                DeleteDC hBitMapDC
                             
                             
                                ReleaseDC %HWND_DESKTOP, hDC
                             
                             
                             
                                    Case %WM_DESTROY
                                        POSTQUITMESSAGE 0
                                End Select
                             
                            Function = DEFWINDOWPROC(hWnd, wMsg, wParam, lParam)
                            End Function
                             
                            Function WinMain (ByVal hInstance     As Long, _
                                              ByVal hPrevInstance As Long, _
                                              lpCmdLine           As Asciiz Ptr, _
                                              ByVal iCmdShow      As Long) As Long
                             
                              Local Msg         As tagMsg
                              Local wndclass    As WndClassEx
                              Local szClassName As Asciiz * 80
                              Local hWnd        As Long
                              Local CC1 As INIT_COMMON_CONTROLSEX
                             
                              CC1.dwSize=SizeOf(CC1)
                              CC1.dwICC=%ICC_WIN95_CLASSES
                              INITCOMMONCONTROLSEX CC1
                             
                              szClassName            = "SDK_LISTVIEW"
                              wndclass.cbSize        = SizeOf(WndClass)
                              wndclass.style         = %CS_HREDRAW Or %CS_VREDRAW
                              wndclass.lpfnWndProc   = CodePtr( WndProc )
                              wndclass.cbClsExtra    = 0
                              wndclass.cbWndExtra    = 0
                              wndclass.hInstance     = hInstance
                              wndclass.hIcon         = LOADICON( hInstance, "FACE1")
                              wndclass.hCursor       = LOADCURSOR( %NULL, ByVal %IDC_ARROW )
                              wndclass.hbrBackground = GETSTOCKOBJECT( %GRAY_BRUSH )
                              wndclass.lpszMenuName  = %NULL
                              wndclass.lpszClassName = VarPtr( szClassName )
                              wndclass.hIconSm       = 0
                              REGISTERCLASSEX wndclass
                              hWnd = CREATEWINDOWEX(%WS_EX_TOPMOST, _
                                                      szClassName, _
                                                      "WebGet 1.0", _
                                                      %DS_CENTER _
                                                      Or %WS_CAPTION  _
                                                      Or %WS_SYSMENU , _
                                                      0, _
                                                      0, _
                                                      700&, _
                                                      300&, _
                                                      %NULL, _
                                                      %NULL, _
                                                      hInstance, _
                                                      ByVal %NULL)
                             
                              SHOWWINDOW hWnd, iCmdShow
                              UPDATEWINDOW hWnd
                             
                                While IsTrue GETMESSAGE(Msg, %NULL, 0, 0)
                                    TRANSLATEMESSAGE msg
                                    DISPATCHMESSAGE msg
                                Wend
                                Sleep 1
                              Function = msg.wParam
                             
                            End Function
                            ------------------
                            http://www.hellobasic.com
                            hellobasic

                            Comment


                            • #15
                              This is a modified version of Borje's code.

                              When you run it, and click on the listview, it will add an
                              entry and create a thread that will scroll the progressbar.

                              The problem is that when you add about 15 or 16 and you scroll up
                              and down, it doesn't repaint correctly. It repaints very slowly.

                              Code:
                              '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                              ' Eliminate unnecessary macros for COMMCTRL.INC
                              '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                              %NOANIMATE       = 1
                              %NOBUTTON        = 1
                              %NOCOMBO         = 1
                              %NODATETIMEPICK  = 1
                              %NODRAGLIST      = 1
                              %NOEDIT          = 1
                              %NOFLATSBAPIS    = 1
                              %NOHEADER        = 1
                              %NOHOTKEY        = 1
                              %NOIMAGELIST     = 1
                              %NOIPADDRESS     = 1
                              %NOLIST          = 1
                              '%NOLISTVIEW      = 1
                              %NOMONTHCAL      = 1
                              %NONATIVEFONTCTL = 1
                              %NOPAGESCROLLER  = 1
                              %NOPROGRESS      = 1
                              %NOREBAR         = 1
                              %NOSTATUSBAR     = 1
                              %NOTABCONTROL    = 1
                              %NOTOOLBAR       = 1
                              %NOTOOLTIPS      = 1
                              %NOTRACKBAR      = 1
                              %NOTREEVIEW      = 1
                              %NOUPDOWN        = 1
                              '------------------------------------------------------------------------------
                              #COMPILE EXE
                              #INCLUDE "WIN32API.INC"
                              #INCLUDE "COMMCTRL.INC"
                              #RESOURCE "c:\pbdll60\samples\tray\tray.pbr"
                              '------------------------------------------------------------------------------
                              %LISTVIEW1 = 100
                              %MNU_LOAD_DOWNLOADLIST = 500
                              %MNU_OPTIONS = 501
                              %MNU_EXIT = 502
                              GLOBAL hListView&
                              '------------------------------------------------------------------------------
                              TYPE UrlStruct
                                   sURL AS STRING * 512
                                   nProgress AS LONG
                                   nSize AS LONG
                              END TYPE
                              
                              DECLARE SUB DrawProgress(hListView&, Percentage&, lPos&)
                              GLOBAL gURL() AS UrlStruct
                              
                              
                              SUB LV_AddItem(hListView&, sTitle$, lMask&, lStateMask&, lPos&)
                                LOCAL azItemText AS ASCIIZ * %MAX_PATH
                                LOCAL lvITEM AS LV_ITEM
                                 azItemText = sTitle$
                                 lvITEM.iImage = 0
                                 lvITEM.iItem = ListView_GetItemCount(hListView&)
                                 lvITEM.mask = %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM
                                 lvITEM.stateMask =  lStateMask&
                                 lvITEM.pszText = VARPTR(azItemText)
                                 lStatus& = ListView_InsertItem (hListView&, lvITEM)
                              END SUB
                              
                              SUB LV_CreateColumn(hListView&, sTitle$, lMask&, lWidth&, lPos&)
                                LOCAL azTitle AS ASCIIZ * 25
                                LOCAL Column AS LV_COLUMN
                                azTitle = sTitle$
                                Column.mask = lMask&
                                Column.fmt = %LVCFMT_LEFT
                                Column.cx = lWidth&
                                Column.pszText = VARPTR(azTitle)
                                ListView_InsertColumn hListView&, lPos&, Column
                              END SUB
                              
                              FUNCTION LVW_GetSelected(hListView&) AS LONG
                                ListCount& = ListView_GetItemCount(hListView&)
                                FOR a& = 0 TO ListCount&
                                    r& = ListView_GetItemState(hListView&,a&,%LVIS_FOCUSED)
                                    IF r& = %LVIS_FOCUSED THEN
                                       FUNCTION = a&
                                       EXIT FUNCTION
                                    END IF
                                NEXT
                              END FUNCTION
                              
                              '------------------------------------------------------------------------------
                              
                              FUNCTION GetURL(BYVAL x AS LONG) AS LONG
                                  LOCAL I AS LONG
                                  sText$ = TRIM$(gURL(x).sURL) & " " & FORMAT$(x)
                                  LV_AddItem hListView&, BYCOPY sText$, %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                  FOR I = 1 TO 100
                                      DrawProgress hListView&, I, x
                                      SLEEP 1000
                                  NEXT
                              END FUNCTION
                              
                              SUB AddURL(URL$)
                                STATIC qID&
                                gURL(qID&).sURL = URL$
                                THREAD CREATE GetUrl(qID&) TO woot&
                                INCR qID&
                              END SUB
                              
                              
                              SUB DrawProgress(hListView&, Percentage&, lPos&)
                                LOCAL cw1 AS LONG, cw2 AS LONG, tmpRect AS RECT, zTxt AS ASCIIZ * 20
                                LOCAL hDcLV AS LONG
                              
                                hDcLv = GetDC(hListView&)
                                  'lPos& = LVW_GetSelected(hListView&)
                                  ListView_GetItemRect hListView&, lPos&, tmpRect, %LVIR_BOUNDS 'for column height
                                  cw1 = ListView_GetColumnWidth(hListView&, 0) 'width of column 1
                                  cw2 = ListView_GetColumnWidth(hListView&, 1) 'width of column 2
                              
                                  tmpRect.nLeft  = cw1
                                  tmpRect.nRight = cw1 + cw2 * Percentage& / 100
                                  FillRect hDcLv, tmpRect, GetSysColorBrush(%COLOR_3DFACE)
                              
                                  tmpRect.nLeft  = tmpRect.nRight
                                  tmpRect.nRight = cw1 + cw2
                                  FillRect hDcLv, tmpRect, GetSysColorBrush(%COLOR_WINDOW)
                              
                                  tmpRect.nLeft = cw1
                                  SetBkMode hDcLv, %TRANSPARENT
                                  SetTextColor hDcLv, %BLUE
                                  zTxt = FORMAT$(Percentage&) + "%"
                                  DrawText hDcLv, zTxt, LEN(zTxt), tmpRect, %DT_CENTER OR %DT_SINGLELINE OR %DT_VCENTER
                                ReleaseDc hListView&, hDcLv
                              END SUB
                              
                              FUNCTION WndProc (BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, _
                                                BYVAL wParam AS LONG, BYVAL lParam AS LONG) EXPORT AS LONG
                                LOCAL rect AS rect
                                LOCAL LV_LpLvNm AS NM_LISTVIEW PTR
                                'STATIC hListView&
                              
                                SELECT CASE wMsg
                                    CASE %WM_NOTIFY
                                         SELECT CASE LOWRD(wParam)
                                             CASE %LISTVIEW1
                                                LV_LPLVNM = lParam
                                                SELECT CASE @LV_LPLVNM.HDR.CODE
                                                    CASE %NM_CLICK
                                                      AddURL "Yoga!"
                                                    CASE %NM_RCLICK
                                                        'debug_print "Right Mouse"
                                                    CASE %LVN_COLUMNCLICK
                                                        'debug_print "Column Click"
                                                END SELECT
                                         END SELECT
                              
                                    CASE %WM_CREATE
                                        GETCLIENTRECT hWnd, rect
                              
                                        hListView& = CREATEWINDOW ( "SysListView32", _
                                                    "", _
                                                    %WS_border OR %WS_Child OR %WS_visible OR _
                                                    %LVS_Report OR %LVS_SINGLESEL OR %LVS_SHOWSELALWAYS, _
                                                    0, _
                                                    0, _
                                                    rect.nRight - 1, _
                                                    rect.nBottom - 50, _
                                                    hWnd, _
                                                    %LISTVIEW1, _
                                                    GETMODULEHANDLE(BYVAL 0&), _
                                                    %Null )
                              
                                        LV_CreateColumn hListView&, "Downloading", %LVCF_FMT OR %LVCF_WIDTH OR %LVCF_TEXT OR %LVCF_SUBITEM, 300, 0
                                        LV_CreateColumn hListView&, "Progress", %LVCF_FMT OR %LVCF_WIDTH OR %LVCF_TEXT OR %LVCF_SUBITEM, 200, 1
                                        LV_CreateColumn hListView&, "Size", %LVCF_FMT OR %LVCF_WIDTH OR %LVCF_TEXT OR %LVCF_SUBITEM, 100, 2
                                       
                                       ' LV_AddItem hListView&, "File1", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                       ' LV_AddItem hListView&, "File1", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                       ' LV_AddItem hListView&, "File2", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                       ' LV_AddItem hListView&, "File3", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                       ' LV_AddItem hListView&, "File4", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                       ' LV_AddItem hListView&, "File5", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                       ' LV_AddItem hListView&, "File6", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                       ' LV_AddItem hListView&, "File7", %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                        MENU NEW BAR TO hMenu0&
                                        MENU NEW POPUP TO hMenu1&
                                        MENU ADD POPUP, hMenu0& ,"&File", hMenu1&, %MF_ENABLED
                                        MENU ADD STRING, hMenu1&, "&Load Download List",  %MNU_LOAD_DOWNLOADLIST, %MF_ENABLED
                                        MENU ADD STRING, hMenu1&, "-",  0, %MF_ENABLED
                                        MENU ADD STRING, hMenu1&, "Options",  %MNU_OPTIONS, %MF_ENABLED
                                        MENU ADD STRING, hMenu1&, "E&xit",  %MNU_EXIT, %MF_ENABLED
                                        MENU ATTACH hMenu0&, hWnd
                              
                                    CASE %WM_DESTROY
                                        POSTQUITMESSAGE 0
                              
                                END SELECT
                                FUNCTION = DEFWINDOWPROC(hWnd, wMsg, wParam, lParam)
                              END FUNCTION
                              
                              FUNCTION WINMAIN (BYVAL hInstance     AS LONG, _
                                                BYVAL hPrevInstance AS LONG, _
                                                lpCmdLine           AS ASCIIZ PTR, _
                                                BYVAL iCmdShow      AS LONG) AS LONG
                                LOCAL Msg         AS tagMsg
                                LOCAL wndclass    AS WndClassEx
                                LOCAL szClassName AS ASCIIZ * 80
                                LOCAL hWnd        AS LONG
                                LOCAL CC1 AS INIT_COMMON_CONTROLSEX
                                REDIM gURL(0 TO 10000) AS UrlStruct
                              
                                CC1.dwSize=SIZEOF(CC1)
                                CC1.dwICC=%ICC_WIN95_CLASSES
                                INITCOMMONCONTROLSEX CC1
                              
                                szClassName            = "SDK_LISTVIEW"
                                wndclass.cbSize        = SIZEOF(WndClass)
                                wndclass.style         = %CS_HREDRAW OR %CS_VREDRAW
                                wndclass.lpfnWndProc   = CODEPTR( WndProc )
                                wndclass.cbClsExtra    = 0
                                wndclass.cbWndExtra    = 0
                                wndclass.hInstance     = hInstance
                                wndclass.hIcon         = LOADICON( hInstance, "FACE1")
                                wndclass.hCursor       = LOADCURSOR( %NULL, BYVAL %IDC_ARROW )
                                wndclass.hbrBackground = GETSTOCKOBJECT( %GRAY_BRUSH )
                                wndclass.lpszMenuName  = %NULL
                                wndclass.lpszClassName = VARPTR( szClassName )
                                wndclass.hIconSm       = 0
                                REGISTERCLASSEX wndclass
                                hWnd = CREATEWINDOWEX(%WS_EX_TOPMOST, _
                                                       szClassName, _
                                                       "WebGet 1.0", _
                                                       %DS_CENTER _
                                                       OR %WS_CAPTION  _
                                                       OR %WS_SYSMENU , _
                                                       0, _
                                                       0, _
                                                       700&, _
                                                       300&, _
                                                       %NULL, _
                                                       %NULL, _
                                                       hInstance, _
                                                       BYVAL %NULL)
                              
                                SHOWWINDOW hWnd, iCmdShow
                                UPDATEWINDOW hWnd
                              
                                WHILE ISTRUE GETMESSAGE(Msg, %NULL, 0, 0)
                                   TRANSLATEMESSAGE msg
                                   DISPATCHMESSAGE msg
                                WEND
                                SLEEP 1
                              
                                FUNCTION = msg.wParam
                              END FUNCTION
                              ------------------
                              -Greg
                              -Greg
                              [email protected]
                              MCP,MCSA,MCSE,MCSD

                              Comment


                              • #16
                                I tried forcing a repaint of the window, and it doesn't seem to
                                work correctly. This is the modified code I used. If you click
                                about 15 times on the listview and you scroll up and down you
                                will see it starting to paint in the Column Header section.

                                Maybe if I only invalidate the Column Header section it will
                                work. I will try that.

                                Anybody have any other suggestions?

                                Code:
                                FUNCTION GetURL(BYVAL x AS LONG) AS LONG
                                    LOCAL I AS LONG
                                    sText$ = TRIM$(gURL(x).sURL) & " " & FORMAT$(x)
                                    LV_AddItem hListView&, BYCOPY sText$, %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                    FOR I = 1 TO 100
                                        DrawProgress hListView&, I, x
                                        
                                        SLEEP 1000
                                        CALL CtrlRedraw(hListView&, 1)
                                    NEXT
                                END FUNCTION
                                
                                SUB AddURL(URL$)
                                  STATIC qID&
                                  gURL(qID&).sURL = URL$
                                  THREAD CREATE GetUrl(qID&) TO woot&
                                  INCR qID&
                                END SUB
                                
                                FUNCTION CtrlRedraw( BYVAL hWnd AS LONG, BYVAL rDraw AS LONG) AS LONG
                                  CALL SendMessage(hWnd, %WM_SETREDRAW, rDraw, 0)
                                
                                  IF rDraw THEN
                                    InvalidateRect hWnd, BYVAL %NULL, 0
                                    UpdateWindow hWnd
                                  END IF
                                END FUNCTION
                                ------------------
                                -Greg
                                -Greg
                                [email protected]
                                MCP,MCSA,MCSE,MCSD

                                Comment


                                • #17
                                  I got it to stop writing outside the control boundries by doing
                                  this in DrawProgress:

                                  IF lPos& < ListView_GetTopIndex(hListView&) THEN EXIT SUB
                                  IF lPos& > ListView_GetTopIndex(hListView&) + ListView_GetCountPerPage(hListView&) THEN EXIT SUB

                                  It does however update very slowly after scrolling. Any tips to fix that?

                                  ------------------
                                  -Greg

                                  [This message has been edited by Gregery D Engle (edited October 19, 2001).]
                                  -Greg
                                  [email protected]
                                  MCP,MCSA,MCSE,MCSD

                                  Comment


                                  • #18
                                    Think best approach is by using an ownerdrawn ListView, like shown in Edwin's
                                    code and then paint all in WM_DRAWITEM. Did a quick test here and it looks good,
                                    but another problem arises - flicker. To remove flicker, one can sub-class the
                                    ListView and return TRUE in its WM_ERASEBKGND. Then all is well, drawing is smooth
                                    and sticks to screen since WM_DRAWITEM handles repaint - but now rest of control
                                    may end up not being repainted properly. Kind a like a Catch22 situation here.
                                    Don't use the listview much myself, so don't know how to solve it in prefect way.

                                    BTW, should be a THREAD CLOSE after THREAD CREATE there, and menu must be
                                    created before using GetClientRect, because client gets changed by menu.
                                    Test following, and also test by removing sub-class (rem out in WM_CREATE).
                                    Sub-classed, it looks good, but if covered by another dialog, repaint in
                                    whole listview isn't ok. Maybe you can find a good middle way..
                                    Code:
                                    ' Click in ListView to add items and see action..
                                    #Compile Exe
                                    #include "win32api.inc"
                                    #include "commctrl.inc"
                                    #Resource "c:\pbdll60\samples\tray\tray.pbr"
                                    GLOBAL pbStep AS LONG, OldLvProc AS LONG
                                    GLOBAL hListView AS LONG
                                     
                                    %LISTVIEW1 = 100
                                    %MNU_LOAD_DOWNLOADLIST = 500
                                    %MNU_OPTIONS = 501
                                    %MNU_EXIT = 502
                                    %WM_PRINT = &H317
                                     
                                    TYPE UrlStruct
                                      sURL AS STRING * 512
                                      nProgress AS LONG
                                      nSize AS LONG
                                    END TYPE
                                    GLOBAL gURL() AS UrlStruct
                                     
                                    '------------------------------------------------------------------------------
                                    Sub LV_AddItem(hListView&, sTitle$, lMask&, lStateMask&, lPos&)
                                      Local azItemText As Asciiz * %MAX_PATH
                                      Local lvITEM As LV_ITEM
                                      azItemText = sTitle$
                                      lvITEM.iImage = 0
                                      lvITEM.iItem = ListView_GetItemCount(hListView)
                                      lvITEM.mask = %LVCF_FMT Or %LVCF_WIDTH Or  %LVCF_TEXT Or %LVCF_SUBITEM
                                      lvITEM.stateMask =  lStateMask&
                                      lvITEM.pszText = VarPtr(azItemText)
                                      lStatus& = ListView_InsertItem (hListView, lvITEM)
                                    End Sub
                                    '------------------------------------------------------------------------------
                                    Sub LV_CreateColumn(hListView&, sTitle$, lMask&, lWidth&, lPos&)
                                      Local azTitle As Asciiz * 25
                                      Local Column As LV_COLUMN
                                     
                                      azTitle = sTitle$
                                      Column.mask = lMask&
                                      Column.fmt = %LVCFMT_LEFT
                                      Column.cx = lWidth&
                                      Column.pszText = VarPtr(azTitle)
                                      ListView_InsertColumn hListView, lPos&, Column
                                    End Sub
                                    '------------------------------------------------------------------------------
                                    Function LVW_GetSelected(hListView&) As Long
                                      ListCount& = ListView_GetItemCount(hListView)
                                      For a& = 0 To ListCount&
                                          r& = ListView_GetItemState(hListView,a&,%LVIS_FOCUSED)
                                          If r& = %LVIS_FOCUSED Then
                                              Function = a&
                                              Exit Function
                                          End If
                                      Next
                                     End Function
                                    '------------------------------------------------------------------------------
                                    FUNCTION GetURL(BYVAL x AS LONG) AS LONG
                                      LOCAL I AS LONG, zTxt AS ASCIIZ * 20
                                      sText$ = TRIM$(gURL(x).sURL) & " " & FORMAT$(x)
                                      LV_AddItem hListView, BYCOPY sText$, %LVCF_FMT OR %LVCF_WIDTH OR  %LVCF_TEXT OR %LVCF_SUBITEM, %LVIS_FOCUSED, 0
                                     
                                      pbStep = 1
                                      FOR I = 1 TO 100
                                         zTxt = FORMAT$(I)
                                         ListView_SetItemText hListView, x, 1, zTxt
                                         SLEEP 20
                                      NEXT
                                      'pbStep = 0   ' ?
                                    END FUNCTION
                                    '------------------------------------------------------------------------------
                                    SUB AddURL(URL$)
                                      STATIC qID&
                                      gURL(qID&).sURL = URL$
                                      THREAD CREATE GetUrl(qID&) TO woot&
                                      THREAD CLOSE woot& TO woot&
                                      INCR qID&
                                    END SUB
                                    '------------------------------------------------------------------------------
                                    Function WndProc (ByVal hWnd As Long, ByVal wMsg As Long, _
                                                      ByVal wParam As Long, ByVal lParam As Long) Export As Long
                                      Local rect As rect, zTxt AS ASCIIZ * 260
                                      Local LV_LpLvNm As NM_LISTVIEW Ptr
                                     
                                      Select Case wMsg
                                         Case %WM_NOTIFY
                                            Select Case LoWrd(wParam)
                                               Case %LISTVIEW1
                                                  LV_LPLVNM = lParam
                                                  Select Case @LV_LPLVNM.HDR.CODE
                                                     Case %NM_CLICK
                                                        AddURL "Yoga!"
                                     
                                                     Case %NM_RCLICK
                                                        'debug_print "Right Mouse"
                                                     Case %LVN_COLUMNCLICK
                                                        'debug_print "Column Click"
                                                  End Select
                                            End Select
                                     
                                         Case %WM_CREATE 'Note: must create menu before using GetClientRect..
                                            Menu New Bar To hMenu0&
                                            Menu New Popup To hMenu1&
                                            Menu Add Popup, hMenu0& ,"&File", hMenu1&, %MF_ENABLED
                                            Menu Add String, hMenu1&, "&Load Download List",  %MNU_LOAD_DOWNLOADLIST, %MF_ENABLED
                                            Menu Add String, hMenu1&, "-",  0, %MF_ENABLED
                                            Menu Add String, hMenu1&, "Options",  %MNU_OPTIONS, %MF_ENABLED
                                            Menu Add String, hMenu1&, "E&xit",  %MNU_EXIT, %MF_ENABLED
                                            Menu Attach hMenu0&, hWnd
                                     
                                            GETCLIENTRECT hWnd, rect
                                            hListView = CREATEWINDOW ( "SysListView32", _
                                                        "", _
                                                        %WS_border Or %WS_Child Or %WS_visible Or _
                                                        %LVS_Report Or %LVS_SINGLESEL Or %LVS_SHOWSELALWAYS Or %LVS_OWNERDRAWFIXED, _
                                                        0, _
                                                        0, _
                                                        rect.nRight - 1, _
                                                        rect.nBottom - 1, _
                                                        hWnd, _
                                                        %LISTVIEW1, _
                                                        GETMODULEHANDLE(ByVal 0&), _
                                                        %Null )
                                            OldLvProc = SetWindowLong(hListView, %GWL_WNDPROC, CODEPTR(LvSubClass))
                                     
                                            LV_CreateColumn hListView, "Downloading", %LVCF_FMT Or %LVCF_WIDTH Or %LVCF_TEXT Or %LVCF_SUBITEM, 300, 0
                                            LV_CreateColumn hListView, "Progress", %LVCF_FMT Or %LVCF_WIDTH Or %LVCF_TEXT Or %LVCF_SUBITEM, 200, 1
                                            LV_CreateColumn hListView, "Size", %LVCF_FMT Or %LVCF_WIDTH Or %LVCF_TEXT Or %LVCF_SUBITEM, 100, 2
                                           '================================================
                                     
                                         Case %WM_DRAWITEM
                                            IF wParam = %LISTVIEW1 THEN
                                               LOCAL cw1 AS LONG, cw2 AS LONG, cw3 AS LONG, tw AS LONG, rc AS RECT
                                               LOCAL lpdis AS DRAWITEMSTRUCT PTR
                                     
                                               lpdis = lParam
                                     
                                               SELECT CASE @lpdis.itemAction
                                                  CASE %ODA_DRAWENTIRE, %ODA_SELECT
                                                     'GET COORDINATES
                                                     GetClientRect hListView, rc
                                                     tw = rc.nRight                                                  'total width
                                                     ListView_GetItemRect hListView, @lpdis.itemID, rc, %LVIR_BOUNDS 'for item height
                                                     cw1 = ListView_GetColumnWidth(hListView, 0)                     'width, column 1
                                                     cw2 = ListView_GetColumnWidth(hListView, 1)                     'width, column 2
                                                     cw3 = ListView_GetColumnWidth(hListView, 2)                     'width, column 3
                                                     rc.nLeft = 0 : rc.nRight = cw1                                  'first column rect
                                     
                                                     'CLEAR BACKGROUND
                                                     IF (@lpdis.itemState AND %ODS_SELECTED) THEN
                                                        FillRect @lpdis.hDC, rc, GetSysColorBrush(%COLOR_HIGHLIGHT)
                                                        SetBkColor @lpdis.hDC, GetSysColor(%COLOR_HIGHLIGHT)
                                                        SetTextColor @lpdis.hDC, GetSysColor(%COLOR_HIGHLIGHTTEXT)
                                                     ELSE
                                                        FillRect @lpdis.hDC, rc, GetSysColorBrush(%COLOR_WINDOW)
                                                        SetBkColor @lpdis.hDC, GetSysColor(%COLOR_WINDOW)
                                                        SetTextColor @lpdis.hDC, GetSysColor(%COLOR_WINDOWTEXT)
                                                     END IF
                                     
                                                     'COLUMN 1
                                                     zTxt = ""
                                                     CALL ListView_GetItemText(hListView, @lpdis.itemID, 0, zTxt, SIZEOF(zTxt))
                                                     rc.nLeft = 2 'don't want text far out in corner
                                                     DrawText @lpdis.hDC, zTxt, LEN(zTxt), rc, %DT_LEFT OR %DT_SINGLELINE OR %DT_VCENTER
                                     
                                                     'DRAW FOCUSRECT ON FIRST COLUMN (if control has focus)
                                                     IF (@lpdis.itemState AND %ODS_SELECTED) AND GetFocus = hListView THEN 'if selected + focus
                                                        rc.nLeft = 0
                                                        CALL DrawFocusRect(@lpdis.hDC, rc) 'draw focus rectangle
                                                     END IF
                                     
                                                     'COLUMN 2 - PROGRESSBAR
                                                     zTxt = ""
                                                     CALL ListView_GetItemText(hListView, @lpdis.itemID, 1, zTxt, SIZEOF(zTxt))
                                                     IF VAL(zTxt) > 0 THEN 
                                                        rc.nLeft  = cw1
                                                        rc.nRight = cw1 + cw2 * VAL(zTxt) / 100
                                                        FillRect @lpdis.hDC, rc, GetSysColorBrush(%COLOR_3DFACE)
                                                        DrawEdge @lpdis.hDC, rc, %BDR_RAISEDINNER, %BF_RECT
                                     
                                                        rc.nLeft  = rc.nRight
                                                        rc.nRight = cw1 + cw2
                                                        FillRect @lpdis.hDC, rc, GetSysColorBrush(%COLOR_WINDOW)
                                     
                                                        rc.nLeft = cw1
                                                        SetBkMode @lpdis.hDC, %TRANSPARENT
                                                        SetTextColor @lpdis.hDC, %BLUE
                                                        zTxt = zTxt + "%"
                                                        INCR rc.nTop
                                                        DrawText @lpdis.hDC, zTxt, LEN(zTxt), rc, %DT_CENTER OR %DT_SINGLELINE OR %DT_VCENTER
                                                        DECR rc.nTop
                                                     END IF
                                     
                                                     'COLUMN 3
                                                     zTxt = ""
                                                     CALL ListView_GetItemText(hListView, @lpdis.itemID, 2, zTxt, SIZEOF(zTxt))
                                                     rc.nLeft  = rc.nRight
                                                     rc.nRight = cw1 + cw2 + cw3
                                                     FillRect @lpdis.hDC, rc, GetSysColorBrush(%COLOR_WINDOW)
                                                     IF LEN(zTxt) THEN
                                                        DrawText @lpdis.hDC, zTxt, LEN(zTxt), rc, %DT_LEFT OR %DT_SINGLELINE OR %DT_VCENTER
                                                     END IF
                                     
                                                     'COLUMN.. the rest..
                                                     rc.nLeft  = rc.nRight
                                                     rc.nRight = tw
                                                     IF rc.nLeft < rc.nRight THEN FillRect @lpdis.hDC, rc, GetSysColorBrush(%COLOR_WINDOW)
                                     
                                     
                                                     'DRAW FOCUSRECT AROUND SELECTED ITEM (if control has focus) (moved up for test..)
                                                     'IF (@lpdis.itemState AND %ODS_SELECTED) AND GetFocus = hListView THEN 'if selected + focus
                                                     '   CALL DrawFocusRect(@lpdis.hDC, @lpdis.rcItem) 'draw focus rectangle
                                                     'END IF
                                                     FUNCTION = %TRUE : EXIT FUNCTION
                                     
                                               END SELECT
                                            END IF
                                     
                                         Case %WM_DESTROY
                                            IF OldLvProc THEN SETWINDOWLONG hListView, %GWL_WNDPROC, OldLvProc
                                            POSTQUITMESSAGE 0
                                     
                                      End Select
                                     
                                      Function = DEFWINDOWPROC(hWnd, wMsg, wParam, lParam)
                                    End Function
                                    '------------------------------------------------------------------------------
                                    Function WinMain (ByVal hInstance     As Long, _
                                                      ByVal hPrevInstance As Long, _
                                                      lpCmdLine           As Asciiz Ptr, _
                                                      ByVal iCmdShow      As Long) As Long
                                     
                                      Local Msg         As tagMsg
                                      Local wndclass    As WndClassEx
                                      Local szClassName As Asciiz * 80
                                      Local hWnd        As Long
                                      Local CC1 As INIT_COMMON_CONTROLSEX
                                      REDIM gURL(10000) AS UrlStruct
                                     
                                      CC1.dwSize=SizeOf(CC1)
                                      CC1.dwICC=%ICC_WIN95_CLASSES
                                      INITCOMMONCONTROLSEX CC1
                                     
                                      szClassName            = "SDK_LISTVIEW"
                                      wndclass.cbSize        = SizeOf(WndClass)
                                      wndclass.style         = %CS_HREDRAW Or %CS_VREDRAW
                                      wndclass.lpfnWndProc   = CodePtr( WndProc )
                                      wndclass.cbClsExtra    = 0
                                      wndclass.cbWndExtra    = 0
                                      wndclass.hInstance     = hInstance
                                      wndclass.hIcon         = LOADICON( hInstance, "FACE1")
                                      wndclass.hCursor       = LOADCURSOR( %NULL, ByVal %IDC_ARROW )
                                      wndclass.hbrBackground = GETSTOCKOBJECT( %GRAY_BRUSH )
                                      wndclass.lpszMenuName  = %NULL
                                      wndclass.lpszClassName = VarPtr( szClassName )
                                      wndclass.hIconSm       = 0
                                      REGISTERCLASSEX wndclass
                                      hWnd = CREATEWINDOWEX(%WS_EX_TOPMOST, _
                                                            szClassName, _
                                                            "WebGet 1.0", _
                                                            %DS_CENTER _
                                                            Or %WS_CAPTION  _
                                                            Or %WS_SYSMENU , _
                                                            0, _
                                                            0, _
                                                            700&, _
                                                            300&, _
                                                            %NULL, _
                                                            %NULL, _
                                                            hInstance, _
                                                            ByVal %NULL)
                                     
                                      SHOWWINDOW hWnd, iCmdShow
                                      UPDATEWINDOW hWnd
                                     
                                      While IsTrue GETMESSAGE(Msg, %NULL, 0, 0)
                                         TRANSLATEMESSAGE msg
                                         DISPATCHMESSAGE msg
                                      Wend
                                      Sleep 1
                                      Function = msg.wParam
                                     
                                    End Function
                                    '------------------------------------------------------------------------------
                                    CALLBACK FUNCTION LvSubClass
                                      SELECT CASE CBMSG
                                         CASE %WM_NCPAINT 'something triggered repaint, allow it to happen
                                            pbStep = 0
                                     
                                         CASE %WM_ERASEBKGND
                                            IF pbStep THEN   'prevent repaints during progress
                                               FUNCTION = 1 : EXIT FUNCTION
                                     
                                            ELSE             'but sometimes need to ignore and repaint..
                                               pbStep = 1
                                            END IF
                                     
                                      END SELECT
                                      FUNCTION = CallWindowProc(OldLvProc, CBHNDL, CBMSG, CBWPARAM, CBLPARAM)
                                    END FUNCTION
                                    ------------------
                                    Moved pbStep (controls WM_ERASEBKGND in sub-class procedure) to GetURL..
                                    Added later: in LvSubClass, added trap in %WM_NCPAINT for enforced
                                    repaint if control is covered and needs to be redrawn. Also corrected
                                    some code in WM_DRAWITEM.




                                    [This message has been edited by Borje Hagsten (edited October 20, 2001).]

                                    Comment


                                    • #19
                                      Cute Jules!

                                      Unfortunately, preventing the WM_ERASEBKGND stops the flicker, but if the window becomes invalidated (ie, moved partially off the edge of the screen and back, then it does not get repainted...

                                      Think of it as something for you to work on over the weekend!

                                      ------------------
                                      Lance
                                      PowerBASIC Support
                                      mailto:[email protected][email protected]</A>
                                      Lance
                                      mailto:[email protected]

                                      Comment


                                      • #20
                                        Borje,

                                        You are so good! I don't mind the flickering, I tested with
                                        over 800 threads and it works good. I modified it so Column 3
                                        validated correctly.

                                        Do you know how to make it validate correctly for the rest of the ListView
                                        control after Column 3?

                                        Thanks


                                        ------------------
                                        -Greg

                                        [This message has been edited by Gregery D Engle (edited October 20, 2001).]
                                        -Greg
                                        [email protected]
                                        MCP,MCSA,MCSE,MCSD

                                        Comment

                                        Working...
                                        X