How to bring forward an already running program 
Author Message
 How to bring forward an already running program

HI

I have a requirment to launch a .exe from my CW2 program, Thats easy, but
how do I then pass focus to it if the use pushes the launch button again.

IE if I give the user a button to run the Windows Calculator on a push of
the button I want to check if the Calculator is running and if it is bring
it into focus, if not I want to execute it.

Thanks in advance

Adam Linnell
DataPro Limited (UK)



Sun, 24 Jan 1999 03:00:00 GMT  
 How to bring forward an already running program


Quote:
>HI

>I have a requirment to launch a .exe from my CW2 program, Thats easy, but
>how do I then pass focus to it if the use pushes the launch button again.

>IE if I give the user a button to run the Windows Calculator on a push of
>the button I want to check if the Calculator is running and if it is bring
>it into focus, if not I want to execute it.

>Thanks in advance

>Adam Linnell
>DataPro Limited (UK)


One way would be to find the window by looping through all the windows
and looking for Calculator as the title.  Once you found it then bring
it to the top.  I have only successfully loop through all the windows.
Haven't tried to bring one to the top.

Both of these need to use the WinAPI.  The prototypes/code for getting
all of the active window handles is listed below.  Most of this comes
from IceTips #7 (I think that's the number).

I used the API Viewer that came with CW20 to create these.

* PROTOTYPES *
--------------

  SECTION('Equates')

GW_CHILD            EQUATE(5)
GW_HWNDFIRST        EQUATE(0)
GW_HWNDLAST         EQUATE(1)
GW_HWNDNEXT         EQUATE(2)
GW_HWNDPREV         EQUATE(3)
GW_OWNER            EQUATE(4)
HANDLE              EQUATE(UNSIGNED)
HWND                EQUATE(HANDLE)
LPCSTR              EQUATE(CSTRING)
LPSTR               EQUATE(CSTRING)
BOOL                EQUATE(SIGNED)

  SECTION('Prototypes')
  MODULE('Windows.DLL')
  GetWindow(HWND,UNSIGNED),HWND,Pascal
        OMIT('***',_WIDTH32_)
  GetWindowText(HWND, *LPSTR, SIGNED),SIGNED,PASCAL,RAW
        ***
        COMPILE('***',_WIDTH32_)

GetWindowText(HWND,*LPSTR,SIGNED),SIGNED,PASCAL,RAW,NAME('GetWindowTextA')
        ***

        OMIT('***',_WIDTH32_)
  GetWindowTextLength(HWND),SIGNED,PASCAL
        ***
        COMPILE('***',_WIDTH32_)
  GetWindowTextLength(HWND),SIGNED,PASCAL,NAME('GetWindowTextLengthA')
        ***

  BringWindowToTop(HWND),BOOL,PASCAL

  END

* VARIABLE DECLARATIONS *
-------------------------
CurrWin        long
cTaskName      cstring(161)
TitleLength    long

* CODE FOR LOOPING THROUGH THE WINDOWS AND CHECKING THE TITLES *
----------------------------------------------------------------

  CurrWin = GetWindow(window{PROP:Handle}, GW_HWNDFIRST)
  loop while CurrWin <> 0
    TitleLength = GetWindowTextLength(CurrWin)
    cTaskName = all(' ', TitleLength)
    TitleLength = GetWindowText(CurrWin, cTaskName, TitleLength+1)
    if TitleLength > 0 and (cTaskName = 'Calculator') then
      break
    end
    CurrWin = GetWindow(CurrWin, GW_HWNDNEXT)
  end

  BringWindowToTop(CurrWin)

This ought to be close.  Let me know how it goes!  I will probably
actually need this sometime soon.

HTH

_________________________________

Global Electronic Marketing, Inc.
http://www.geminc.com/



Sun, 24 Jan 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Message: Program Already Running on this computer

2. How to tell if program already running

3. Check if app is already running

4. Finding out if App is already running

5. Opening a file in a Already running emacs?

6. Is Appliaction already running?

7. Check for already running runtime image

8. forwarding message from Steve Leach re Running Pop-11

9. Reminder: Bringing Programming closer to Mathematical Notation

10. Reminder: Bringing Programming closer to Mathematical Notation

11. Seminar: Bringing Programming closer to Mathematical Notation

12. OpenMP Industry Standard Brings Portability to Scalable, Shared-Memory Programming

 

 
Powered by phpBB® Forum Software