home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / seam.zip / SEAMLESS.C next >
Text File  |  1994-05-09  |  5KB  |  178 lines

  1. /*--------------------------------------------------------------------------
  2.          FILE HEADER FOR seamless.c
  3.          HEADER LAST UPDATED :  9 May 1994
  4.  
  5.          COMPILER : Borland C++ for OS/2, version 1.0
  6.  
  7.          PURPOSE :
  8.               This is a utility program written to launch a seamless
  9.          windows application from the command prompt.  This program also
  10.          demonstrates how to launch a seamless child application from a
  11.          program.
  12.  
  13.          POSSIBLE IMPROVEMENTS :
  14.  
  15.          (1) This version assumes that WIN.COM is in \OS2\MDOS\WINOS2 on
  16.              the boot drive, so an improvement would be to allow for an
  17.              override of WIN.COM or find some other way to account for OS/2
  18.              for Windows.
  19.  
  20.          (2) This version does not apply special settings for the session.
  21.              Probably these can be altered by changing the evironment in
  22.              the PROGDETAILS structure which is passed to WinStartApp().
  23.  
  24.          (3) If anyone can figure out how to accomplish what this program
  25.              does using DosStartSession(), please upload a sample program.
  26.              DosStartSession() is much superior to the WinStartApp() API
  27.              used here in that it returns a process id.
  28.  
  29.          PARAMETER : The fully qualified name of the executable.
  30.  
  31.          RETURNS : 0 if failure, 1 if success
  32.  
  33.   --------------------------------------------------------------------------*/
  34.  
  35.  
  36. #define INCL_WIN
  37. #define INCL_DOS
  38. #include <os2.h>
  39. #include <stdio.h>
  40. #include <string.h>
  41.  
  42.  
  43. ULONG StartSeamless(HWND hwndNotify,char *pszProgram);
  44. MRESULT EXPENTRY ParentWndProc(HWND, ULONG, MPARAM, MPARAM);
  45. HAB hab;
  46. CHAR szProgram[CCHMAXPATH];
  47. ULONG ulReturnCode;
  48.  
  49. int main(int argc,char *argv[])
  50. {
  51. CHAR szClientClass[] = "Seamless";
  52. ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU   |
  53.                      FCF_SIZEBORDER    | FCF_MINMAX    |
  54.                      FCF_SHELLPOSITION | FCF_TASKLIST;
  55.  
  56. HMQ    hmq;
  57. HWND   hwndFrame, hwndClient;
  58. QMSG   qmsg;
  59.  
  60. if (argc == 1)
  61.    {
  62.    printf("Need an argument for the program to launch.\n");
  63.    return 1;
  64.    }
  65. if (strlen(szProgram) > CCHMAXPATH)
  66.    {
  67.    printf("Argument 1 is too long\n");
  68.    return 1;
  69.    }
  70. strcpy(szProgram,argv[1]);
  71. ulReturnCode = 0;
  72.  
  73. hab = WinInitialize(0);
  74. hmq = WinCreateMsgQueue(hab,0);
  75. WinRegisterClass(hab,
  76.                  szClientClass,
  77.                  (PFNWP)ParentWndProc,
  78.                  0L,
  79.                  0);
  80. hwndFrame =  WinCreateStdWindow(HWND_OBJECT,
  81.                                 WS_VISIBLE,
  82.                                 (PULONG)&flFrameFlags,
  83.                                 szClientClass,
  84.                                 NULL,
  85.                                 0L,
  86.                                 (HMODULE)NULL,
  87.                                 0,
  88.                                 (PHWND)&hwndClient);
  89.  
  90. while (WinGetMsg(hab,(PQMSG)&qmsg,(HWND)NULL,0,0))
  91.       {
  92.       WinDispatchMsg(hab,(PQMSG)&qmsg);
  93.       }
  94.  
  95. WinDestroyWindow(hwndFrame);
  96. WinDestroyMsgQueue(hmq);
  97. WinTerminate(hab);
  98. return ulReturnCode;
  99. }
  100.  
  101. MRESULT EXPENTRY ParentWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  102. {
  103.  
  104. switch (msg)
  105.      {
  106.      case WM_CREATE:
  107.           if (!StartSeamless(hwnd,szProgram))
  108.              {
  109.              ulReturnCode = 1;
  110.              WinSendMsg(hwnd,WM_CLOSE,NULL,NULL);
  111.              }
  112.           return 0;
  113.  
  114.      case WM_APPTERMINATENOTIFY:
  115.           printf("Seamless APP terminated\n");
  116.           WinSendMsg(hwnd,WM_CLOSE,NULL,NULL);
  117.           return 0;
  118.  
  119.      case WM_DESTROY:
  120.           return 0;
  121.      }
  122.  
  123. return WinDefWindowProc(hwnd,msg,mp1,mp2);
  124. }
  125.  
  126.  
  127. ULONG StartSeamless(HWND hwndNotify,char *pszProgram)
  128. {
  129. PROGDETAILS Details;
  130. HAPP happ;
  131. CHAR szParams[CCHMAXPATH+5];
  132. ULONG ulBootDrive;
  133. APIRET rc;
  134.  
  135.  
  136. Details.pszExecutable   = "c:\\os2\\mdos\\winos2\\winos2.com";
  137. rc = DosQuerySysInfo(QSV_BOOT_DRIVE,QSV_BOOT_DRIVE,&ulBootDrive,
  138.                      sizeof(ulBootDrive));
  139. if (rc != 0)
  140.    {
  141.    printf("DosQuerySysInfo returned %ld \n",rc);
  142.    return FALSE;
  143.    }
  144. *(Details.pszExecutable) = (char)(ulBootDrive-1+'A');
  145.  
  146.  
  147.  
  148. Details.Length          = sizeof(PROGDETAILS);
  149. Details.progt.progc     = PROG_SEAMLESSCOMMON;
  150. Details.progt.fbVisible = SHE_VISIBLE;
  151. Details.pszTitle        = "";
  152. Details.pszParameters   = NULL;
  153. Details.pszStartupDir   = "";
  154. Details.pszIcon         = NULL;
  155. Details.pszEnvironment  = NULL;
  156. Details.swpInitial.fl   = SWP_ACTIVATE;
  157. Details.swpInitial.cy   = 0;
  158. Details.swpInitial.cx   = 0;
  159. Details.swpInitial.y    = 0;
  160. Details.swpInitial.x    = 0;
  161. Details.swpInitial.hwndInsertBehind = HWND_TOP;
  162. Details.swpInitial.hwnd             = hwndNotify;
  163. Details.swpInitial.ulReserved1      = 0;
  164. Details.swpInitial.ulReserved2      = 0;
  165. strcpy(szParams," /K ");
  166. strcat(szParams,pszProgram);
  167. happ = WinStartApp(hwndNotify,
  168.                    &Details,
  169.                    szParams,
  170.                    NULL,
  171.                    SAF_STARTCHILDAPP);
  172. printf(" %ld %04X",happ,WinGetLastError(hab));
  173. if (happ == NULLHANDLE) return FALSE;
  174. return TRUE;
  175. }
  176.  
  177.  
  178.