Announcement

Collapse
No announcement yet.

how to capture the text of Text Window into a clipboard

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

  • how to capture the text of Text Window into a clipboard

    Hi All, I just started to use the Text Window for debugging my programs and find that it gives very good data and values
    things like branching around the program to the various SUBs and FUNCTIONs . It can be used to display the program flows etc

    Only problem is that I can't capture the stuff on this window and save it into a clipboard and later on transfer the stuff to a text file,
    which I can check and verify.

    Currently I can only print screen to capture this text window. Any suggestion please on how to capture the stuff into a text file?

  • #2
    SImplest (?) way:
    '
    Code:
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN() AS LONG
        LOCAL lDebug AS LONG: TXT.WINDOW EXE.FULL$, 200,50,40,85 TO lDebug
        DebugPrint "This is some display text"
        DebugPrint "This is some more display text"
        DebugPrint "Yet more display text"
        DebugPrint "Last display text
    'Finalise
        TXT.COLOR = %RGB_BLUE
        TXT.PRINT
        TXT.PRINT "  ....Press any key to exit": TXT.WAITKEY$: TXT.END
    END FUNCTION
    
    FUNCTION DebugPrint(s AS WSTRING) AS LONG
       'Prints  to both the TXT WIndow and a text file.
       LOCAL ff AS LONG
       ff = FREEFILE
      OPEN "debug.txt" FOR APPEND AS #ff
      PRINT #ff, s
      CLOSE #ff
      TXT.PRINT s
    END FUNCTION
    '

    Comment


    • #3
      You can also look a TRACE in help, Also PROFILE

      TRACE NEW fname$
      TRACE ON
      TRACE PRINT string_expr
      TRACE OFF
      TRACE CLOSE

      and there is also Patrice Terrier's zTrace that work somewhat as TXT but also has the option to Trace to file. https://forum.powerbasic.com/forum/u...e-version-1-90

      Comment


      • #4
        Ditto - keep a log of what you TXT.PRINT as you go..
        '
        Code:
        #DIM ALL
        #COMPILE EXE
         
        GLOBAL gsLog AS STRING
         
        SUB TxtPrint(sText AS STRING)
          TXT.PRINT sText                 ' 1024 ~ Txt.Print text len limit
          gsLog += sText + $CRLF
        END SUB
        '------------------/
         
        FUNCTION PBMAIN()
         LOCAL hTxt  AS DWORD : TXT.WINDOW("Keys", 10, 10, 20, 40) TO hTxt
         LOCAL sTest AS STRING
         LOCAL lNum  AS LONG   : lNum = 43
          sTest = "Something"
          TxtPrint sTest
          TxtPrint "more"
          TxtPrint USING$("Numeric variable_! #", lNum)
         
          CLIPBOARD RESET : CLIPBOARD SET TEXT gsLog
          MSGBOX gsLog,,"On Clipboard"
        END FUNCTION
        '------------------/PBMain
        Last edited by Dave Biggs; 29 Jul 2022, 06:01 AM.
        Rgds, Dave

        Comment


        • #5
          Thanks All

          Comment


          • #6
            Combination of posts 2 and 4 plus automatic display of log file with your default text editor on close.
            Note use of WSTRINGs and "CHR= WIDE" to allow use of characters such as the Greek alphabet in the TXT window and the debug text file.

            Also note that TXT.PRINT allows printing of numerics. DebugPrint requires text, so you need to wrap any numbers in FORMAT$() or another conversion function


            '
            Code:
            #COMPILE EXE
            #DIM ALL
            %Unicode = 1
            #INCLUDE "win32api.inc"
            GLOBAL gwsDebug AS WSTRING
            
            FUNCTION PBMAIN() AS LONG
                LOCAL lDebug AS LONG: TXT.WINDOW EXE.FULL$, 200,50,40,85 TO lDebug
                DebugPrint "This is some display text"
                DebugPrint "This is text with Greek (Unicode) letters Alpha to Theta " & CHR$$(913,32, 914,32,915,32,916,32,917,32,918,32,919,32,920)
                DebugPrint "Yet more display text"
                DebugPrint FORMAT$(2*4)
                DebugPrint "Last display text
            'Finalise
                TXT.COLOR = %RGB_BLUE
                TXT.PRINT
                TXT.PRINT "  ....Press any key to exit": TXT.WAITKEY$: TXT.END
                ViewDebugFile
            END FUNCTION
            
            FUNCTION DebugPrint(s AS WSTRING) AS LONG
               gwsDebug &= s & $CRLF
               TXT.PRINT s
            END FUNCTION
            
            FUNCTION ViewDebugFile () AS LONG
                LOCAL ff AS LONG
                LOCAL retval , hkey AS DWORD
                LOCAL wszFileType,wszOpenCmd AS WSTRINGZ * 256
                ff = FREEFILE
                OPEN "debug.txt" FOR OUTPUT AS #ff CHR = WIDE
                PRINT #ff , gwsDebug
                CLOSE #ff
            
               'Get file type for extension
                retval = RegOpenKeyEx(%HKEY_CLASSES_ROOT,".txt",0,%key_query_value,hkey)
                retval = regqueryvalueex(hkey,"",0,%reg_sz,wszFileType,256)
                retval = regclosekey(hkey)
                'Get default open command
                retval = RegOpenKeyEx(%HKEY_CLASSES_ROOT,wszFileType & "\SHELL\Open\command" ,0,%key_query_value,hkey)
                retval = regqueryvalueex(hkey,"",0,%reg_sz,wszOpenCmd,256)
                retval = regclosekey(hkey)
                REPLACE "%1" WITH  "Debug.txt"  IN wszOpenCmd
                SHELL wszOpenCmd
            END FUNCTION
            '

            Comment


            • #7
              Also note that TXT.PRINT allows printing of numerics.
              Adjusted post#4 eg to show one way to handle numeric printing.

              Not quite so easy with the other Txt.Print method parts - [SPC(n)] [TAB(n)] [,] [;]...)
              Rgds, Dave

              Comment


              • #8
                Originally posted by Dave Biggs View Post

                Adjusted post#4 eg to show one way to handle numeric printing.

                Not quite so easy with the other Txt.Print method parts - [SPC(n)] [TAB(n)] [,] [;]...)
                Since the objective is printing data and messages for debugging, I doubt that that would be a major issue. Just make sure that the debug output is simple strings
                Actually, you could easily have two functions:
                TxtPrintS and TxtPrintN to handle strings or numeric values.

                '
                Code:
                ...
                    TxtPrintS "This is some display text"
                    TxtPrintS "This is Greek (Unicode) letters Alpha to Theta " & CHR$$(913,32, 914,32,915,32,916,32,917,32,918,32,919,32,920)
                    TxtPrintN 2*4+3/5
                    TxtPrintS "Last display text
                ...
                END FUNCTION
                
                FUNCTION TxtPrintS(s AS WSTRING) AS LONG
                   gwsDebug &= s & $CRLF
                   TXT.PRINT s
                END FUNCTION
                
                FUNCTION TxtPrintN(e AS EXT) AS LONG
                   gwsDebug &= FORMAT$(e) & $CRLF
                   TXT.PRINT e
                END FUNCTION
                .
                '

                Comment


                • #9
                  Thank you Sir Stuart, in your post# 4 there is a block of codes which I don't really understand whats' its purpose?

                  Code:
                  'Get file type for extension
                  retval = RegOpenKeyEx(%HKEY_CLASSES_ROOT,".txt",0,%key_query_value,hkey)
                  retval = regqueryvalueex(hkey,"",0,%reg_sz,wszFileType,256)
                  retval = regclosekey(hkey)
                  'Get default open command
                  retval = RegOpenKeyEx(%HKEY_CLASSES_ROOT,wszFileType & "\SHELL\Open\command" ,0,%key_query_value,hkey)
                  retval = regqueryvalueex(hkey,"",0,%reg_sz,wszOpenCmd,256)
                  retval = regclosekey(hkey)
                  REPLACE "%1" WITH "Debug.txt" IN wszOpenCmd
                  SHELL wszOpenCmd

                  Comment


                  • #10
                    Originally posted by Tim Lakinir View Post
                    Thank you Sir Stuart, in your post# 4 there is a block of codes which I don't really understand whats' its purpose?
                    It's pretty straighfroward, but good on you for actually trying to understand rather than blindly copying and pasting

                    It uses the standard API functions for getting information from the Registry.
                    Basically, you open a Registry key, read a value and then close the key.

                    In this case, it looks up how to open a .txt file


                    'Get file type for extension
                    'OPEN THE REGISTRY KEY FOR THE EXTENSION.TXT and get the handle to that entry (in hkey)
                    retval = RegOpenKeyEx(%HKEY_CLASSES_ROOT,".txt",0,%key_query_value,hkey)

                    'USE hkey TO FIND THE NAME OF THE APPLICATION USED for ".txt" FILES (the Default value for that key)
                    retval = regqueryvalueex(hkey,"",0,%reg_sz,wszFileType,256)
                    'In my case, this returns Notepad++_file in wszFileType

                    'CLOSE THE REGISTRY KEY WE JUST USED
                    retval = regclosekey(hkey)

                    'OPEN THE REGISTRY KEY FOR THE APPLICATION'S COMMAND TO OPEN A FILE (in the key "Notepad++_file\SHELL\Open\command")
                    retval = RegOpenKeyEx(%HKEY_CLASSES_ROOT,wszFileType & "\SHELL\Open\command" ,0,%key_query_value,hkey)

                    'GET THE COMMAND TO OPEN A FILE (WHICH INCLUDES A PLACEHOLDER)
                    retval = regqueryvalueex(hkey,"",0,%reg_sz,wszOpenCmd,256)
                    'In my case, thsi returns "C:\Program Files\Notepad++\notepad++.exe" "%1" in wszOpenCmd

                    'CLOSE THE REGISTRY KEY
                    retval = regclosekey(hkey)

                    'REPLACE THE PLACEHOLDER WITH THE NAME OF THE FILE
                    REPLACE "%1" WITH "Debug.txt" IN wszOpenCmd
                    'so now wszCmd contains "C:\Program Files\Notepad++\notepad++.exe" "debig.txt"

                    'PASS THE COMMAND TO OPEN THE FILE (wszCmd) TO A SHELL
                    SHELL wszOpenCmd
                    'this opened the file debug.txt in Notepad++

                    Comment


                    • #11
                      I did read the first post and it appears that the response is much simpler than suggested, straight from WIN32.HLP.
                      Code:
                      An application sends the WM_COPY message to an edit control or combo box to copy the current selection to the clipboard in CF_TEXT format.
                      
                      WM_COPY
                      wParam = 0; // not used; must be zero
                      lParam = 0; // not used; must be zero
                      Code like this.
                      Code:
                      SendMessage hEdit,WM_COPY,0,0
                      hutch at movsd dot com
                      The MASM Forum - SLL Modules and PB Libraries

                      http://www.masm32.com/board/index.php?board=69.0

                      Comment


                      • #12
                        A Text Window (TXT pseudo-object) is not an edit control or combobox. has no "current selection" and doesn't respond to a %WM_COPY message.
                        Last edited by Stuart McLachlan; 30 Jul 2022, 04:01 AM.

                        Comment


                        • #13
                          Originally posted by Stuart McLachlan View Post
                          Code:
                          FUNCTION TxtPrintN(e AS EXT) AS LONG
                          gwsDebug &= FORMAT$(e) & $CRLF
                          TXT.PRINT e
                          END FUNCTION
                          '
                          This needs to be BYVAL so that you can pass any numeric data including integral type variables
                          Code:
                          FUNCTION TxtPrintN(BYVAL e AS EXT) AS LONG
                          gwsDebug &= FORMAT$(e) & $CRLF
                          TXT.PRINT e
                          END FUNCTION
                          '

                          Comment


                          • #14
                            Thank You Stuart for your explanations, but I won't be using registry functions

                            Comment


                            • #15
                              Originally posted by Tim Lakinir View Post
                              Thank You Stuart for your explanations, but I won't be using registry functions
                              Probably a good idea.

                              Comment

                              Working...
                              X