Loading ...
Sorry, an error occurred while loading the content.

Re: [libertybasic] Make sure application not running twice

Expand Messages
  • Ken Lewis, Sr.
    ... From: bridgepard952 ... Check out Newsletter 102... http://babek.info/libertybasicfiles/lbnews/nl102/index.htm be sure
    Message 1 of 8 , Oct 31, 2004
    • 0 Attachment
      ----- Original Message -----
      From: "bridgepard952" <lornerussell@...>


      >
      >
      > I know there is an API call to find out if your application is
      > already running but I'll be damned if I can find it.
      >
      > Any have a reference? Or the API call?
      >
      > Thanks

      Check out Newsletter 102...

      http://babek.info/libertybasicfiles/lbnews/nl102/index.htm

      be sure to download the zip file to get the source code.
      If you need any help with this, let me know.

      Ken
    • Doyle Whisenant
      ... See CALLBACK in the (LB3.03)help file. It s already written for you. -- Doyle Whisenant http://www.freewebs.com/mekdesign/ mechanic at sonet dot net
      Message 2 of 8 , Nov 1, 2004
      • 0 Attachment
        fearworks wrote:
        >
        > Sorry - bet you thought I was someone with a solution!!
        >
        > Alas, no... but this is something I would really like to know too.
        >

        See CALLBACK in the (LB3.03)help file. It's already written for you.

        --
        Doyle Whisenant
        http://www.freewebs.com/mekdesign/
        "mechanic" at "sonet" dot "net"
      • fearworks
        I keep getting a notice saying unable to continue , and that s using LB 4.01 in WinXP Professional, both within the editor and as a tkn file executed by the
        Message 3 of 8 , Nov 1, 2004
        • 0 Attachment
          I keep getting a notice saying "unable to continue", and that's
          using LB 4.01 in WinXP Professional, both within the editor and as a
          tkn file executed by the runtime engine.

          Any ideas why this might be?

          Thanks.

          Keith.

          --- In libertybasic@yahoogroups.com, "Ken Lewis, Sr."
          <kenlewissr@s...> wrote:
          > ----- Original Message -----
          > From: "bridgepard952" <lornerussell@m...>
          >
          >
          > >
          > >
          > > I know there is an API call to find out if your application is
          > > already running but I'll be damned if I can find it.
          > >
          > > Any have a reference? Or the API call?
          > >
          > > Thanks
          >
          > Check out Newsletter 102...
          >
          > http://babek.info/libertybasicfiles/lbnews/nl102/index.htm
          >
          > be sure to download the zip file to get the source code.
          > If you need any help with this, let me know.
          >
          > Ken
        • Mike
          ... Here s my interpretation of Doyle s tip to see CALLBACK in the LB help file. It seems to be ok when run as a tkn but when run from the LB IDE, entries
          Message 4 of 8 , Nov 5, 2004
          • 0 Attachment
            --- In libertybasic@yahoogroups.com, "bridgepard952"
            <lornerussell@m...> wrote:
            >
            > I know there is an API call to find out if your application is
            > already running but I'll be damned if I can find it.
            >
            > Any have a reference? Or the API call?
            >
            > Thanks

            Here's my interpretation of Doyle's tip to see CALLBACK in the LB
            help file. It seems to be ok when run as a tkn but when run from the
            LB IDE, entries appear to remain in the Kill programs list after
            ending program execution. I don't know how to cure that....maybe
            someone else does.

            Mike.

            nomainwin
            global runningApp$, appRunning
            runExe$="notepad.exe"
            runningApp$="Notepad" 'Window title (or part of) of running
            application
            button #1.b1, "Run Notepad", [runNotepad], UL,20,20,80,20
            open "Run Once" for window as #1
            #1, "trapclose [quit]"

            wait

            [runNotepad]
            appRunning=0
            gosub [test]
            if appRunning=0 then
            run runExe$, SHOWMINIMIZED
            notice "Application started";chr$(13);runningApp$
            else
            notice "Application already running";chr$(13);runningApp$
            end if
            wait

            [quit]
            close#1
            end

            [test]
            'set the variable named address to be the memory address for
            'enumWndProc() using TYPES handle and ulong, and set
            'the return TYPE of enumWndProc() to be a boolean
            callback address, enumWndProc(handle), boolean

            'call EnumWindows, which in turn calls back into the
            'BASIC function at address.

            calldll #user32, "EnumWindows", _
            address as ulong, _
            0 as long, _
            result as boolean
            'notice result
            return

            function enumWndProc(hwnd)
            labelBuffer$ = space$(71)
            calldll #user32, "GetWindowTextA", _
            hwnd as ulong, _
            labelBuffer$ as ptr, _
            70 as long, _
            result as long
            count=count+1
            if instr(labelBuffer$,runningApp$)<>0 or count>6 then
            enumWndProc = 0 'returning 0 causes EnumWindows to return
            appRunning=1
            else
            enumWndProc = 1
            end if
            end function
          • pendl2megabit
            The same API call in a different use: ---code start test if application is running nomainwin WindowText$ = I will run only once call TestIfActive
            Message 5 of 8 , Nov 7, 2004
            • 0 Attachment
              The same API call in a different use:

              '---code start
              ' test if application is running
              nomainwin

              WindowText$ = "I will run only once"

              call TestIfActive WindowText$

              open WindowText$ for window as #main
              #main "trapclose [quit]"
              wait

              [quit]
              close #main
              end

              sub TestIfActive WindowCaption$
              calldll #user32, "GetActiveWindow", _
              handle as ulong

              while handle <> 0
              Cmd = _GW_HWNDNEXT

              calldll #user32, "GetWindow", _
              handle as ulong, _
              Cmd as ulong, _
              handle as ulong

              title$ = space$(_MAX_PATH)
              MaxCount = len(title$)

              calldll #user32, "GetWindowTextA",_
              handle as ulong,_
              title$ as ptr,_
              MaxCount as ulong,_
              result as ulong

              currentTitle$ = trim$(title$)

              if currentTitle$ = WindowCaption$ then
              calldll #user32, "BringWindowToTop", _
              handle as ulong, _
              result as boolean
              end
              end if
              scan
              wend
              end sub
              '---code end

              ---
              Stefan Pendl


              > -----Urspr√ľngliche Nachricht-----
              > Von: Mike
              >
              > Here's my interpretation of Doyle's tip to see CALLBACK in the LB
              > help file. It seems to be ok when run as a tkn but when run from the
              > LB IDE, entries appear to remain in the Kill programs list after
              > ending program execution. I don't know how to cure that....maybe
              > someone else does.
              >
              > Mike.
            • fearworks
              Thanks Stefan. THAT S exactly what I was looking for...! Keith. ... the
              Message 6 of 8 , Nov 7, 2004
              • 0 Attachment
                Thanks Stefan.

                THAT'S exactly what I was looking for...!

                Keith.

                --- In libertybasic@yahoogroups.com, "pendl2megabit"
                <pendl2megabit@y...> wrote:
                > The same API call in a different use:
                >
                > '---code start
                > ' test if application is running
                > nomainwin
                >
                > WindowText$ = "I will run only once"
                >
                > call TestIfActive WindowText$
                >
                > open WindowText$ for window as #main
                > #main "trapclose [quit]"
                > wait
                >
                > [quit]
                > close #main
                > end
                >
                > sub TestIfActive WindowCaption$
                > calldll #user32, "GetActiveWindow", _
                > handle as ulong
                >
                > while handle <> 0
                > Cmd = _GW_HWNDNEXT
                >
                > calldll #user32, "GetWindow", _
                > handle as ulong, _
                > Cmd as ulong, _
                > handle as ulong
                >
                > title$ = space$(_MAX_PATH)
                > MaxCount = len(title$)
                >
                > calldll #user32, "GetWindowTextA",_
                > handle as ulong,_
                > title$ as ptr,_
                > MaxCount as ulong,_
                > result as ulong
                >
                > currentTitle$ = trim$(title$)
                >
                > if currentTitle$ = WindowCaption$ then
                > calldll #user32, "BringWindowToTop", _
                > handle as ulong, _
                > result as boolean
                > end
                > end if
                > scan
                > wend
                > end sub
                > '---code end
                >
                > ---
                > Stefan Pendl
                >
                >
                > > -----Urspr√ľngliche Nachricht-----
                > > Von: Mike
                > >
                > > Here's my interpretation of Doyle's tip to see CALLBACK in the LB
                > > help file. It seems to be ok when run as a tkn but when run from
                the
                > > LB IDE, entries appear to remain in the Kill programs list after
                > > ending program execution. I don't know how to cure that....maybe
                > > someone else does.
                > >
                > > Mike.
              Your message has been successfully submitted and would be delivered to recipients shortly.