Announcement

Collapse
No announcement yet.

Log Files View

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

    Log Files View

    I need to append data to a log file and to view it into a (I guess) standard Edit window with the %ES_READONLY flag set. I have the following questions:

    1) How to initialize the view of the file beginning from the bottom. Important: the file can be more than 64K.
    2) How to append and automatic scroll the data into the edit control, in such a way to see only the last rows.
    3) How to stop the automatic scroll to read an earlier section WHILE the program is adding data to the file.
    4) How to setup a common Find Window.

    May be there is an example somewhere...

    Thanks

    ------------------
    Rgds, Aldo

    #2
    I think you should try the listview control.
    You could sort it by appending line numbers or sort of
    This means, the new line will be appended correctly even what sort/view is used..



    ------------------
    hellobasic

    Comment


      #3
      I agree with LISTVIEW, but without strings.
      Code:
        #Compile Exe
        #Dim All
        #Register None
        #Include "WIN32API.INC"
      
        %ID_LIST1 = 101
      
        CallBack Function DlgProc
           Dim arr() As Static String, nEl As Static Long, mEl As Static Long, hList As Long, i As Long
           Select Case CbMsg
              Case %WM_INITDIALOG: SetTimer CbHndl, 1, 500, ByVal 0&
              Case %WM_DESTROY: KillTimer CbHndl, 1
              Case %WM_TIMER
                 Control Handle CbHndl, %ID_LIST1 To hList
                 If nEl >= mEl Then mEl = Max(1000, mEl * 2): ReDim Preserve arr(mEl - 1)
                 arr(nEl) = "Event" + Str$(nEl + 1)
                 'i = SendMessage (hList, %LB_GETCURSEL, 0, 0): If i < nEl Then Incr i
                 Incr nEl
                 SendMessage hList, %LB_ADDSTRING, nEl - 1, 0
                 SendMessage hList, %LB_SETCURSEL, i, 0
                 InvalidateRect CbHndl, ByVal 0&, 1
                 UpdateWindow hList
                  
               Case %WM_DRAWITEM
                  Local lpdis As DRAWITEMSTRUCT Ptr
                  lpdis = CbLparam
                  If @lpdis.itemID = &HFFFFFFFF Then Exit Function
                  If IsFalse(@lpdis.itemState And %ODS_SELECTED) Then
                     FillRect @lpdis.hDC, @lpdis.rcItem, GetStockObject(%WHITE_BRUSH)
                     SetBkColor @lpdis.hDC, %WHITE
                     SetTextColor @lpdis.hDC, %BLACK
                  Else
                     FillRect @lpdis.hDC, @lpdis.rcItem, GetStockObject(%BLACK_BRUSH)
                     SetBkColor @lpdis.hDC, %BLACK
                     SetTextColor @lpdis.hDC, %WHITE
                  End If
                  i = nEl - 1 - @lpdis.itemID
                  TextOut @lpdis.hDC, 0, @lpdis.rcItem.ntop, ByVal StrPtr(arr(i)), Len(arr(i))
                  Function = 1: Exit Function
            End Select
         End Function
      
        Function PbMain
           Local hDlg As Long
           Dialog New 0, "Test", , , 100, 70, %WS_CAPTION Or %WS_SYSMENU To hDlg
           Control Add ListBox, hDlg, %ID_LIST1, , 5, 5, 90, 65, _
              %WS_CHILD Or %LBS_OWNERDRAWFIXED Or _
              %WS_TABSTOP Or %LBS_DISABLENOSCROLL Or %WS_VSCROLL, %WS_EX_CLIENTEDGE
           Dialog Show Modal hDlg, Call DlgProc
        End Function
      ------------------
      E-MAIL: [email protected]

      Comment


        #4
        The line:
        Code:
        IF @lpdis.itemID = &HFFFFFFFF THEN EXIT FUNCTION
        should probably read:
        Code:
        IF @lpdis.itemID = &HFFFFFFFF??? THEN EXIT FUNCTION
        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


          #5
          I wrote a program called Winlog For WIndows 2000, and found that Listviews are THE best way to do this.
          While I haven't put the SORT method into it yet that's coming in the next release due out next month....


          Scott

          ------------------
          Scott
          Scott Turchin
          MCSE, MCP+I
          http://www.tngbbs.com
          ----------------------
          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

          Comment


            #6
            Lance --
            I noticed a problem in Borje's code (he uses -1).

            From one side, this is correct, but itemId declared as Dword.

            PB doesn't like comparasion DWORD variable (let's say d) with negative constant (c).

            Possible solutions
            1) Dim i as long; i = c and to compare d with i.
            2) To use Clng: If d = Clng(c)
            3) To write c as &H.
            Your suggestion also works, but requires three additional symbols

            Clng(-1) looks for me best.

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

            Comment


              #7
              First thought was - what code? Then I realized what you meant. Ok,
              thanks Semen - Lance. I'll make sure to use the correct way in the
              future. Confusion comes from the fact that Win32.hlp says "For an
              empty list box or combo box, this member can be -1". So, how can
              a DWORD member become -1? Interesting theory by MS..

              BTW, looking at MS sample in Win32.hlp, "Creating a Square Meal
              Dialog Box", they use: "if (lpdis->itemID == -1)"..
              ------------------


              [This message has been edited by Borje Hagsten (edited April 02, 2001).]

              Comment


                #8
                Microsoft has been known to take unfortunate liberties with the side-effects of Intel
                architecture and C design. When they refer to a DWORD value of -1, they really mean a
                bit pattern of LONG -1 stuffed into a DWORD. In PowerBASIC, use &HFFFFFFFF??? in such
                cases.

                ------------------
                Tom Hanlin
                PowerBASIC Staff

                Comment


                  #9
                  Semen, thanks for the code (it's the first time I need to write the code for a ListView).

                  I need to view a log file as-is. No need of icons, sorting, column formatting. May be a simple ListBox will work...

                  I wonder on the data-lenght of my log files. When I was a DOS programmer, I had to economize memory. Now I have two choices:

                  1- To have all my log file data loaded into memory.
                  2- To use an OwnerDraw Listbox (or anything like this) and get the data from the disk file on WM_DRAWITEM messages. Has this choice any sense nowadays?

                  ------------------
                  Rgds, Aldo

                  Comment


                    #10
                    Since a PB/DLL app can access up to 2 Gigabytes of memory for scalar variables, strings, and arrays, loading even very large files into memory is not usually a big drama unless there is not enough disk space for the swap file to grow as virtual memory usage grows.

                    Therefore, I'd be inclined to load the entire file into memory and use the ownerdrawn method... that would be a very efficient and flexible method.

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

                    Comment


                      #11
                      Aldo -
                      I automatic repeated Edwin's "ListView", but actually is used ownerdrawn listbox (see code).
                      Where to keep strings ... Depends of situation.

                      I don't fully agree with Lance. Customers can use enough old PC with 16-32 Mb RAM and most of it is already busy by Windows "kernel" programs.
                      Meanwhile, unlike "a PB/DLL app can access up to 2 Gigabytes of memory", a performance reduces dramatic, if an app requries more than physical memory's size.
                      This is so even in more or less "clever" Win2000.

                      In my opinion, if log file has size some MB, better to use fixed-length strings and to read big blocks.
                      For example, to have a buffer, let's say for 20 records per 500 bytes.
                      When listbox asks record #100 and you have not it in buffer, read records 81-100.
                      Even very old drives require less than 0.1 sec to do this.

                      [This message has been edited by Semen Matusovski (edited April 03, 2001).]

                      Comment


                        #12
                        You can use an Edit-control:
                        Code:
                        #compile exe
                        #dim all
                        #register none
                        #include "win32api.inc"
                         
                        declare callback function DlgProc
                         
                        %ID_EDIT = 100
                        %ID_BUT  = 101
                         
                        function pbmain
                         
                            local hDlg as long
                         
                            dialog new 0, "",,,110, 60, %WS_SYSMENU or %WS_MINIMIZEBOX or %DS_CENTER to hDlg
                            dialog show modal hDlg call DlgProc
                         
                        end function
                         
                        callback function DlgProc
                         
                            local i as long, s as string
                         
                            select case cbMsg
                            case %WM_INITDIALOG						
                        	control add button, cbhndl, %ID_BUT, "Test...", 2,2, 40, 14
                        	control add textbox, cbhndl, %ID_EDIT, "", 2,20, 100, 14,  %ES_MULTILINE or %ES_WANTRETURN or %ES_READONLY or %WS_VSCROLL, %WS_EX_CLIENTEDGE
                         
                            case %WM_COMMAND
                                select case lowrd(cbwParam)
                        	case %ID_BUT
                          	    for i = 1 to 25
                        		s = $CRLF + "Test: i = " + format$(i)
                        		control send cbhndl, %ID_EDIT, %EM_REPLACESEL, %TRUE, strptr(s)
                        		sleep 100
                        	    next i
                                end select
                            end select
                         
                        end function
                        Regards
                        Peter

                        ------------------
                        [email protected]
                        www.dreammodel.dk

                        Comment


                          #13
                          Guys,

                          I tried the following (PB/CC; I think it's the same in PB/DLL):
                          Code:
                          LOCAL a AS DWORD
                          LOCAL b AS LONG
                          a = &Hffffffff???
                          b = -1
                          IF a = b THEN
                            PRINT "eureka"
                          END IF
                          I got the "eureka"! But if I check
                          Code:
                          IF &Hffffffff??? = b THEN ...
                          or
                          Code:
                          IF a = -1& THEN ...
                          I don't get it. Another try:
                          Code:
                          %aa = &Hffffffff???
                          %bb = -1&
                          a = %bb
                          b = %aa
                          IF b = a THEN ...
                          I get the "eureka" again.

                          I know the memory bit pattern for both the signed and the unsigned data are identical. I think there is something not clear inside the compiler. 2 cases: OR the signs matter OR they doesn't. Old compilers (like TurboBasic) checked this situations, also at run time (of course they generated slower and longer code). I think PB should verify at least that situations can be checked at compile time. It shouldn't take good a statement like "a = %bb" or "lpdis.itemID = -1".

                          ------------------



                          [This message has been edited by Aldo Cavini (edited April 03, 2001).]
                          Rgds, Aldo

                          Comment


                            #14
                            Is this what you are trying to do?
                            http://www.tngbbs.com/ccs/winlog



                            ------------------
                            Scott
                            Scott Turchin
                            MCSE, MCP+I
                            http://www.tngbbs.com
                            ----------------------
                            True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                            Comment


                              #15
                              The bit pattern for &HFFFFFFFF& (LONG) and &HFFFFFFFF??? (DWORD) may be the same,
                              but PowerBASIC isn't C: comparing -1 to 4,294,967,295 is not guaranteed to produce
                              a match, as PB's expression evaluation may bump both values up to QUADs rather
                              than doing a bitwise evaluation the way C would.

                              If you need to compare using exactly 32 bits, use the BITS??? function.

                              ------------------
                              Tom Hanlin
                              PowerBASIC Staff

                              Comment


                                #16
                                Semen, Lance, Peter --

                                All considered, I think I'll use an ownerdraw listbox - Thanks for your help. There is one question I havn't already had an answer: Does it exist a common dialog to setup a Find query?

                                ------------------
                                Rgds, Aldo

                                Comment


                                  #17
                                  do you mean find-replace dialog ? (ctrl-f, ctrl-r in http://www.powerbasic.com/support/pb...ad.php?t=22976 )

                                  ------------------
                                  e-mail: [email protected]

                                  Comment


                                    #18
                                    Tom,

                                    I begun programming (assembler) a lot of time ago, and I am already used to think on bit patterns, data storage, etc. It is an useful information to know how PB works internally.

                                    This topic started when Borje assigned a -1 to a dword. I think it is not a problem, unless the compiler checks this kind of "mistakes". My last question was: is it possible to tell the compiler to point out that kind of invalid assignement (that ones which involve equates, and can be pointed out at compile time)? I tried the following:
                                    Code:
                                    LOCAL a AS BYTE
                                    %b = 12345
                                    a = %b
                                    PRINT a
                                    The result is 57. May be it is redundant (time and code length) to check overflows at run time - It should be very useful to check them at compile time. Note: this kind or errors are not pointed out even with the "#debug error on" statement. TurboBasic had a compiler flag to generate the code to check overflows at run time. I spared endless hours of debug thanks to it.

                                    ------------------



                                    [This message has been edited by Aldo Cavini (edited April 03, 2001).]
                                    Rgds, Aldo

                                    Comment


                                      #19
                                      Aldo,

                                      One alternate way is to use an ARRAY. Then utilize a LISTBOX to

                                      display chunks of data. I use a LIST, plus 4 BUTTONS to navigate

                                      the ARRAY...

                                      Thanks,
                                      P.

                                      ------------------

                                      Comment


                                        #20
                                        In general, the PB/Windows compilers don't treat assignments as errors. If you assign, say,
                                        -1 to a DWORD, PB assumes that you know what you want, and puts the appropriate bit pattern
                                        in the DWORD. This often provides the best match with Windows SDK behavior, as you have seen.


                                        ------------------
                                        Tom Hanlin
                                        PowerBASIC Staff

                                        Comment

                                        Working...
                                        X
                                        😀
                                        🥰
                                        🤢
                                        😎
                                        😡
                                        👍
                                        👎