No announcement yet.

Check for active program, to parse mdi

  • Filter
  • Time
  • Show
Clear All
new posts

  • Check for active program, to parse mdi

    Guy's (and girls) I have problem I could use a little help with.
    My program has a report generator, wich assembles the data, and
    put that into RTF format. After that, the program tracks down the
    associated program for RTF (Wordpad or Word or similar), and then
    spawns with a shell statement with the program and filename.
    Instead of intelligent behaviour that you might expect (hopes2high),
    windows every time launches a new instance of that program.
    How can I find out, if the wanted program is active, and secondly
    how do I address that particular instance to open my file ?

    Help will be very appreciated. (Your name in the tribute list)

    Thanks in advance, coz I know (believe) that the community
    will not let me down in this.

    You gotta walk and don't loop back.
    You gotta run, and don't loop back.

  • #2
    To find out if it's running: I once used the following to do a little
    hack for PBEdit. Can be used to compare and find any running app', as
    long as one knows its title. FindExecutable can give you that.
      'somewhere in code..
      EnumWindows CODEPTR(EnumWindowsProc), 0
    ' Enumerate running app's
      wTitle = STRING$(256, 0)
      GetWindowText hwnd, BYVAL STRPTR(wTitle), 256  'Get window title
      wTitle = EXTRACT$(wTitle, CHR$(0))
      IF LEN(wTitle) THEN                  'compare title to find PBedit, or whatever prog.
         IF LEFT$(wTitle, 42) = "PowerBASIC 32-bit DLL Compiler for Windows" THEN
            fhWnd = hwnd                   '<- store its handle
            FUNCTION = 0 : EXIT FUNCTION   '<- break action
         END IF
      END IF
      FUNCTION = 1                         '<- reurn a valu to keep on looking
    Don't know how to open a file this way without starting another instance
    though. Is it even possible?


    [This message has been edited by Borje Hagsten (edited July 04, 2001).]


    • #3
      You know, this was a "thinker."

      But the more I thunk about it, I figgered it must be a function of the "run" (invoked, SHELLed) program.


      Because, let's say you are using Microsoft Word as the "run" program. Is MS Word just supposed to will-nilly discard the current file to load this one? With or without asking if you want to "save?"

      (Maybe Word is a bad example: MS word always has a separate entry on the taskbar for each document; but since the documents appear on the "window" menu, it must be a single MDI application. MS Excel works the same way.)

      But I have some programs I use which don't let me load more than one copy; when I try, it just goes to the currently running copy.

      The next question is, "Why does it need to be a separate instance?" Under Win32, I can think of no good reason.

      The only thing I can think of is the "run" program creates the same output file (e.g., "output.dat") regardless of the input, in which case you would have a file conflict. In this case, get another program.


      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]


      • #4
        Question is, why shell to other program? Rich edit handles RTF and
        enables you to show result from within your own program. Could be a
        good solution, because always more impressive if a program handles
        all by itself.

        Otherwise, one way could be to get check if associated app' is running,
        get its handle and send Ctrl+N to it, to open up a new doc, copy the RTF
        report to the clipboard and paste it in by sending a Ctrl+V. Think there
        are some samples of how to do "SendKeys" in PB in source code forum.

        Or, maybe try DDE way? Recent sample in source code forum maybe could be
        converted and used for something like this..?



        • #5
          Herman, I was helped in the forum with a problem and tested
          the solution with the following code.

          Peter P Stephenson gave me my solution.

          If you re-run it with different file names it doesn't create
          a new instance of Excel, but uses the running instance.

          'The trick is TO make a html-file AND give it the xls-extension

          #COMPILE EXE
          #DIM ALL
          #REGISTER NONE
          #INCLUDE ""



          LOCAL buffer AS STRING
          LOCAL i AS LONG

          buffer = buffer + "<table border='1'>"

          buffer = buffer + "<tr>" + $CR
          buffer = buffer + " <td> </td>" + $CR
          buffer = buffer + " <td><i>The 1. col.</i></td>" + $CR
          buffer = buffer + " <td><i>The 2. col.</i></td>" + $CR
          buffer = buffer + " <td><b><i>Company</i></b></td>" + $CR
          buffer = buffer + "</tr>" + $CR

          buffer = buffer + "<tr>" + $CR
          buffer = buffer + " <td><i>The 1. row</i></td>" + $CR
          buffer = buffer + " <td>1</td>" + $CR
          buffer = buffer + " <td>2</td>" + $CR
          buffer = buffer + " <td>=" + CHR$(34) + "012" + CHR$(34) + "</td>" + $CR
          buffer = buffer + "</tr>" + $CR

          buffer = buffer + "<tr>" + $CR
          buffer = buffer + " <td><i>The 2. row</i></td>" + $CR
          buffer = buffer + " <td>3</td>" + $CR
          buffer = buffer + " <td>4</td>" + $CR
          buffer = buffer + " <td><b><i>=" + CHR$(34) + "DLM_HTML" + CHR$(34) + "</i></b></td>" + $CR
          buffer = buffer + "</tr>" + $CR

          buffer = buffer + "<tr>" + $CR
          buffer = buffer + " <td><i><b>Sum</b></i></td>" + $CR
          buffer = buffer + " <td><b>=SUM(B2:B3)</b></td>" + $CR
          buffer = buffer + " <td><b>=SUM(C2:C3)</b></td>" + $CR
          buffer = buffer + " <td><b>That's all</b></td>" + $CR
          buffer = buffer + "</tr>" + $CR

          buffer = buffer + "</table>"
          'Make successive runs - each time change the name of test2.xls
          'in the next two code lines to to see that one instance of the shelled
          'application is used

          'If you make the file extension .htm or .doc the appropriate
          'application will open

          PutFile "test2.xls", buffer

          ' ShellExecute 0, "print", "test.xls", BYVAL %NULL, BYVAL %NULL, %SW_SHOWNORMAL
          ShellExecute 0, "open", "test2.xls", BYVAL %NULL, BYVAL %NULL, %SW_SHOWNORMAL
          END FUNCTION

          FUNCTION PutFile(File AS STRING, Buffer AS STRING) AS LONG

          LOCAL hFile AS LONG

          KILL File
          ERR = 0
          hFile = FREEFILE

          OPEN File FOR BINARY AS hFile
          PUT$ hFile, Buffer
          CLOSE hFile
          FUNCTION = 1

          END FUNCTION




          • #6

            FYI, there is a PB/DLL EQUATE that is internal to PB/DLL that
            you can use instead of CHR$(34). It is $DQ.

            Clay C. Clear


            [email protected]
            [email protected]


            • #7
              Thanks Clay

              I wasn't aware of that - I didn't find a list in the documentation.

              I only picked up $CRLF and $CR from past code postings.

              Can you post the full list of string equates?




              • #8

                To my knowledge, the internal EQUATES available in PB/DLL aren't
                listed in its online Help file. I found them listed in the
                printed manual for PB/DLL that I special ordered when I ordered

                The following list are the internal EQUATES that I know of. I
                haven't completed read the printed manual, so I don't know if
                it lists any others. Most likely, it doesn't, as the list that
                I know of says that "...these are the internal EQUATES..."
                (or something like that), so I'm sure the list is
                all-inclusive. OK, here's the list:

                $NUL CHR$(0) NUL
                $BEL CHR$(7) Bell
                $BS CHR$(8) Back Space
                $TAB CHR$(9) Horizontal Tab
                $LF CHR$(10) Line Feed
                $VT CHR$(11) Vertical Tab
                $FF CHR$(12) Form Feed
                $CR CHR$(13) Carriage Return
                $CRLF CHR$(13, 10) Carriage Return & Line Feed
                $EOF CHR$(26) End Of File
                $ESC CHR$(27) Escape
                $DQ CHR$(34) Quotation Mark (double - ")

                Note that I can't verify the validity of most of these
                EQUATES; however, they should all be good, as the printed
                manual was made by PowerBASIC, Inc. itself. I've only used
                several of them in my own coding, which is why I can't verify
                them at this time.



                It might be a good idea to have your Documentation Dept. include
                these EQUATES in their next Help File update? I had no idea that
                they even existed until I was doing some reading in the printed

                Clay C. Clear


                [email protected]
                [email protected]


                • #9
                  Thanks, but they *are* already documented in the Errata postings in the FAQ forum...

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


                  • #10
                    Thanks a lot guy's I'll give it ago, maybe the trick with the
                    extension is a possibility or otherwise use the enumwindowsproc
                    function from Borje, Borje good to see your still around,
                    concidering the (still) temporarily! shut Tolken99 site.
                    Anyway people I've got as usual enough info to chew on.
                    I need this, because I haven't worked out how to show a bitmap
                    in the richedit control yet, and I needed a picture in the
                    heading !
                    Now I assemble the (converted to RTF) heading and glue the rest
                    of the document to that heading, close it with "}}" to end RTF
                    info, and open that as a .rtf file, with enumerated associated

                    You gotta walk and don't loop back.
                    You gotta run, and don't loop back.