|
|
Microsoft OS/2 SDK 03-01-1988
/*
* This example demonstrates some of the session manager API
*
* Created by Microsoft Corp. 1987
*/
#define INCL_DOSSESMGR
#include <os2def.h> /* defines SELECTOROF and OFFSETOF */
#include <stdio.h>
#include <ctype.h>
#include <bse.h>
#define TOTAL_COLMS 80 /* screen size in colms */
#define TOTAL_ROWS 24 /* screen size in rows */
void Menu();
void StartChild();
void KillChild();
void ExitThisProc();
extern unsigned _aenvseg;
extern unsigned _acmdln;
USHORT KidSID; /* Array of session IDs */
USHORT KidPID;
short Instance;
char spbuf[80], pbuf[128], Inputs[10];
char Title[100] = "SESSION.EXE";
main(ac,av)
int ac;
char **av;
{
int i;
char **p;
char far *progname;
/*
* Grab the full path name of this program (the one used by EXECPGM())
* for use in creating child sessions.
*/
SELECTOROF(progname) = _aenvseg; /* This is standard C runtime stuff */
OFFSETOF(progname) = _acmdln-1; /* The Path name comes just prior to */
/* AV[0] - but remember this is in a */
while(*--progname) /* different segment than the rest of */
; /* the program, thus the copy (below) */
for (i=0; *++progname; i++) /* Copy a far string to a local buffer */
pbuf[i] = *progname;
pbuf[i] = 0;
KidSID = -1;
/*
* Look for the first Numeric argument, convert it and break out.
*/
Instance = 0;
for (p = av+1; **p; p++) {
if (isdigit(**p)) {
Instance = atoi(*p);
break;
}
}
for (;;) {
Menu();
switch(getch()) {
case 's':
StartChild();
break;
case 'f':
KillChild();
break;
case 'e':
ExitThisProc();
break;
case 'm':
break;
default:
putc('\007', stdout);
}
}
}
void
Menu()
{
if( Instance)
printf("\t%s Child process # %u\n\n", Title, Instance);
else
printf("\t%s\n\n", Title);
printf("Select an option:\n\n");
printf("\ts: Start child\n");
printf("\tf: Stop child\n");
printf("\te: Exit\n");
printf("\tm: Menu\n\n");
printf("? ");
}
void
StartChild()
{
int rc;
STARTDATA SDbuf;
USHORT SessionID, ProcessID;
if (KidSID != -1) {
printf("Sorry, only one child at a time.\n");
return;
}
sprintf(spbuf, "Child Session # %u", Instance + 1 );
sprintf(Inputs, "%u", Instance + 1);
printf("Starting Child...\n");
SDbuf.cb = sizeof(SDbuf);
SDbuf.Related = 1; /* Yes */
SDbuf.FgBg = 0; /* Start in the foreground */
SDbuf.TraceOpt = 0; /* Run the child synchronously, why? I dunno */
SDbuf.PgmTitle = spbuf; /* Title in session manager box */
SDbuf.PgmName = pbuf; /* Exec path (see main) */
SDbuf.PgmInputs = Inputs; /* Any command line arguments */
SDbuf.TermQ = 0; /* No notification queue */
rc = DosStartSession(&SDbuf, &SessionID, &ProcessID);
if (rc)
printf("Failed, %d no more screens available\n", rc);
else
{
printf("Success, screen group %u, PID %u\n", SessionID, ProcessID);
KidSID = SessionID;
KidPID = ProcessID;
}
}
void
KillChild()
{
short rc;
if (KidSID == -1) {
printf("Sorry, must start session before you can stop it.\n");
return;
}
rc = DosStopSession(0, KidSID, 0l);
#ifdef DEBUG
printf("Screen ID: %d\n", KidSID);
#endif
if (rc)
printf("Stop session failed, code %d\n", rc);
KidSID = -1;
}
void
ExitThisProc()
{
printf(" Exiting, gasp cough die...\n");
exit(0);
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.