Close a program from another program

nance

New Member
:confused:

I have an external program (=A) running (non progress). In that program I run a progress-window-program (=B) to view some parameters from program A.
Now I want to launch another program from program A that closes program B.
How ?

Thank you for answering.
:D
 
is your external program (A) a batch program, if not why not just put a "ok" button on program (B) that will end it.
 
what exactly are you trying to accomplish ?

another option would be to use sockets to communicate
between non-progress and progress apps or different progress sessions

but maybe there's no need to over complicate
where a simple solution would work, like vinod's idea ?
 
Program A is a phone-tool. It opens a screen when you answer the phone and close it when you hang up. When the person wants additional information about who is calling, then I open a progress window. The person can click ok to close it. But when you hang up, it should also close the progress window.
 
Here's a snippet which closes any window using its title:

/* Commented by KSV: Definitions of external functions */
PROCEDURE GetWindow EXTERNAL "user32":
DEF INPUT PARAM h AS LONG.
DEF INPUT PARAM d AS LONG.
DEF RETURN PARAM h2 AS LONG.
END.
PROCEDURE GetWindowTextA EXTERNAL "user32":
DEF INPUT PARAM h AS LONG.
DEF INPUT PARAM m AS MEMPTR.
DEF INPUT PARAM s AS LONG.
END.
PROCEDURE GetDesktopWindow EXTERNAL "user32":
DEF RETURN PARAM h AS LONG.
END.
PROCEDURE SendMessageA EXTERNAL "user32":
DEF INPUT PARAM h AS LONG.
DEF INPUT PARAM m AS LONG.
DEF INPUT PARAM w AS LONG.
DEF INPUT PARAM l AS LONG.
END.
/* Commented by KSV: Main block */
DEFINE VARIABLE GW_CHILD AS INTEGER INIT 5 NO-UNDO.
DEFINE VARIABLE GW_HWNDNEXT AS INTEGER INIT 2 NO-UNDO.
DEFINE VARIABLE WM_CLOSE AS INTEGER INIT 16 NO-UNDO.
DEFINE VARIABLE hPrev AS INTEGER NO-UNDO.
DEFINE VARIABLE hNext AS INTEGER NO-UNDO.
DEF VAR m AS MEMPTR.
DEFINE VARIABLE s AS CHARACTER NO-UNDO.
/* Commented by KSV: Get the desktop window handle */
RUN GetDesktopWindow(OUTPUT hPrev).
/* Commented by KSV: Get the first child */
RUN GetWindow(hPrev,GW_CHILD,OUTPUT hNext).
/* Commented by KSV: Looping for all windows */
LOOP:
DO WHILE hNext <> 0:
hPrev = hNext.
/* Commented by KSV: Get the next window handle */
RUN GetWindow(hPrev,GW_HWNDNEXT,OUTPUT hNext).
/* Commented by KSV: Read the window title */
RUN GetWindowTextA(hNext,m,256).
s = GET-STRING(m,1).
/* Commented by KSV: Compare titles of two windows, if they're the
** same, send the close signal to window */
IF s = "<Your window title>" THEN
RUN SendMessageA(hNext,WM_CLOSE,0,0).
END.
 
Bulklodd,

I'm just getting started with WIN32 API's

Any particular resources, books etc. you'd recommend
or any other words of advice on getting started ?

Thanks
 
Jurjen Dijkstra site is GREAT !
but it's mostly code snippets

I don't think it was intended to be instructional
theres not alot of explanations or resources cited AFAIK

How did you get started ?
I'm guessing it was more then learning thru examples
 
How did you get started ?

I used two main resources this one and MSDN. All examples you can find in MSDN then you take 'windows.i' from 'global-shared.com' and translate the example to the P4GL.
As I remeber there was one more useful resource - DOTR.COM but unfortunately it's not available now.
 
Nance,

I'm guessing Bulklodd's suggestion works for you ?

By the way I'm interested to know more about
the phone tool software/hardware you're using ?
 
Thank you for your program source, but I receive error 3233:

DLL procedure <procedure> using an uninitialized MEMPTR. (3233)
If a variable of MEMPTR datatype is defined as other than RETURN parameter inside a DLL internal procedure, then the DLL internal procedure expects the MEMPTR variable to be initialized (i.e. memory allocated) by the calling procedure. This error occurs if the MEMPTR variable is not a RETURN parameter and memory has not been allocated for it by the calling procedure.

How do I solve this?

The phone-tool that we are you using is PIMPhony, but I think that working with tapiserver is much better.
 
Oops I missed the following line in my snippet:
SET-SIZE(m) = 256.
You shoud place it before the line:
RUN GetDesktopWindow(OUTPUT hPrev).
 
Back
Top