home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1994 February / psl_9403.zip / psl_9403 / DOS / UT_SYSTM / CENVI2.ZIP / DOSOBJ.CMD < prev    next >
OS/2 REXX Batch file  |  1993-11-16  |  7KB  |  188 lines

  1. EXTPROC CEnvi
  2. /****************************************************************
  3.  *** DosObj - This is an example, and a template, for using   ***
  4.  ***          the WinCreateObject function to create any type ***
  5.  ***          of object.  You can easily adapt this.          ***                                       full-screen Windows session.  You may **
  6.  ****************************************************************/
  7.  
  8. #include <PMdll.lib>
  9. //#include <KeyPush.lib>
  10. #include <ClipBrd.lib>
  11. #include <Profile.lib>
  12. SetupString = ""; // initialize to contain nothing
  13.  
  14. // SET THE SESSION PROGRAM TYPE, UNCOMMENT THE FOLLOWING LINE THAT APPLIES
  15.    // Setup("PROGTYPE=FULLSCREEN"); // OS/2 full screen
  16.    // Setup("PROGTYPE=WINDOWABLEVIO");// OS/2 windowed
  17.    // Setup("PROGTYPE=VDM");        // DOS full screen
  18.    Setup("PROGTYPE=WINDOWEDVDM");   // DOS windowed
  19.    // Setup("PROGTYPE=PM");         // PM
  20.    // Setup("PROGTYPE=SEPARATEWIN");// WIN-OS2 window in separate VDM
  21.    // Setup("PROGTYPE=WIN");        // WIN-OS2 full screen
  22.    // Setup("PROGTYPE=WINDOWEDWIN");// WIN-OS2 windowed
  23.    // Setup("PROGTYPE=PROG_31_ENH");   // WIN-OS/2 full screen,
  24.                                        // NOT a separate VDM session
  25.                                        // 3.1 Enhanced
  26.    // Setup("PROGTYPE=PROG_31_ENHSEAMLESSVDM); // WIN-OS2 windowed,
  27.                                                // Separate VDM session
  28.                                                // 3.1 Enhanced
  29.    // Setup("PROGTYPE=PROG_31_ENHSEAMLESSCOMMON); // WIN-OS2 windowed
  30.                                                   // NOT a separate VDM
  31.                                                   // 3.1 Enhanced
  32.  
  33. // Windowed session options; uncomment those to apply
  34.    // Setup("MINIMIZED=YES");    // Start program minimized
  35.    Setup("MAXIMIZED=YES");    // Start program maximized
  36.    // Setup("NOAUTOCLOSE=YES");  // Leaves the window open
  37.    // Setup("NOAUTOCLOSE=NO");   // Closes the window at termination
  38.  
  39. // LOTS OF DOS (and Windows) SETTINGS; USE THOSE THAT ARE NOT THE DEFAULT
  40. // AND THAT YOU WANT TO APPLY, (there's more than listed here)
  41.    // Setup("SET DOS_DEVICE=")
  42.    // Setup("SET DOS_FCBS=2")
  43.    // Setup("SET DOS_FCBS_KEEP=2")
  44.    // Setup("SET DOS_FILES=55")
  45.    // Setup("SET DOS_HIGH=0")
  46.    // Setup("SET DOS_UMB=0")
  47.    // Setup("SET DPMI_DOS_API=ENABLED")
  48.    // Setup("SET DPMI_MEMORY_LIMIT=3")
  49.    // Setup("SET DPMI_NETWORK_BUFF_SIZE=1")
  50.    Setup("SET IDLE_SECONDS=8")
  51.    Setup("SET IDLE_SENSITIVITY=85")
  52.    // Setup("SET EMS_FRAME_LOCATION=NONE")
  53.    // Setup("SET EMS_HIGH_OS_MAP_REGION=0")
  54.    // Setup("SET EMS_LOW_OS_MAP_REGION=0")
  55.    // Setup("SET EMS_MEMORY_LIMIT=0")
  56.    // Setup("SET VIDEO_8514A_XGA_IOTRAP=0")
  57.    // Setup("SET VIDEO_SWITCH_NOTIFICATION=1")
  58.    // Setup("SET XMS_HANDLES=0")
  59.    // Setup("SET XMS_MEMORY_LIMIT=0")
  60.    // Setup("SET XMS_MINIMUM_HMA=0")
  61.  
  62. // TELL TO OPEN IMMEDIATELY (OPEN=SETTINGS would open SETTINGS folder)
  63.    Setup("OPEN=DEFAULT");
  64.  
  65. // Set up executable name, parameters, and startup directory
  66.    Setup("EXENAME=*");
  67.    Setup("PARAMETERS=/K mode 80,25");
  68.    Setup("STARTUPDIR=C:\\OS2");
  69.  
  70. // Set the title for this session
  71.    Title = "DOS Box";
  72.  
  73. // Before calling, save current font and set to the one we want: 10 x 8
  74.    GetCurrentBoxFont(SaveFontHeight,SaveFontWidth);
  75.    SetCurrentBoxFont(10,8);
  76.  
  77. // Call the API function to create an object
  78.    #define CO_FAILIFEXISTS     0
  79.    #define CO_REPLACEIFEXISTS  1
  80.    #define CO_UPDATEIFEXISTS   2
  81.    handle = WinCreateObject("WPProgram",Title,SetupString,"<WP_NOWHERE>",
  82.                             CO_FAILIFEXISTS);
  83.  
  84. // Restore window font to what it used to be
  85.    SetCurrentBoxFont(SaveFontHeight,SaveFontWidth);
  86.  
  87.    if ( handle == NULL )
  88.       printf("\a\a\aUnable to create the Windows object.\n"), exit(1);
  89.  
  90. // Get the Window handle from its title
  91.    hwnd = GetWindowHandle(Title,SwitchHandle)
  92.  
  93. // call switch.cmd CEnvi function to bring this program to the foreground
  94.    WinSwitchToProgram(SwitchHandle);
  95.  
  96. // Get Dimensions of this window and of the whole screen
  97.    #define HWND_DESKTOP 1
  98.    GetWindowPosition(HWND_DESKTOP,col,row,DesktopWidth,DesktopHeight)
  99.    GetWindowPosition(hwnd,col,row,width,height)
  100.  
  101. // Move this window to where we want it, this could be anywhere...
  102. // In this case center it against the right edge of the screen.
  103.    col = DesktopWidth - width;
  104.    row = (DesktopHeight - height) / 2;
  105. // Some screen positions don't look so good, so adjust to "good" position
  106.    #define GOOD_COL_OFFSET 8
  107.    #define GOOD_ROW_OFFSET 1
  108.    col -= (col - GOOD_COL_OFFSET/2) % GOOD_COL_OFFSET
  109.    row -= (row - GOOD_ROW_OFFSET/2) % GOOD_ROW_OFFSET
  110.    MoveWindow( hwnd, col, row );
  111.  
  112. // Send a "DIR" command to this session via the clipboard
  113.    // ClipCommand = "DIR\r";
  114.    // PutClipboardData(ClipCommand,1+strlen(ClipCommand),CF_TEXT);
  115.    // KeyStroke(VK_ALT), KeyStroke('P');
  116.  
  117. /****************** FUNCTIONS USED BY ABOVE CODE *********************/
  118.  
  119. Setup(format) // This is like printf, but adds to the end of SetupString for
  120.               // each incarnation, plus a ';' to separate fields
  121. {
  122.    va_start(va_list,format);
  123.    str = SetupString + strlen(SetupString);
  124.    vsprintf(str,format,va_list);
  125.    va_end(va_list);
  126.    strcat(SetupString,";");
  127. }
  128.  
  129. GetWindowHandle(WindowName,Switch_Handle)
  130. {
  131.    // will try a number of times, to give it time to get going
  132.    #define  RETRY_COUNT    50
  133.    #define  RETRY_DELAY    100   // milliseconds to wait between retries
  134.    for ( retry = 0; retry < RETRY_COUNT; retry++, suspend(RETRY_DELAY) ) {
  135.       // build list of all window titles
  136.       SwitchList = WinQuerySwitchList(PMInfo().hab);
  137.       for ( i = GetArraySpan(SwitchList); 0 <= i; i-- ) {
  138.          if ( 0 == WinQuerySwitchEntry(SwitchList[i],SwEntry) ) {
  139.             if ( !strcmp(WindowName,SwEntry.title)
  140.               &&  NULL != SwEntry.hwnd ) {
  141.                Switch_Handle = SwitchList[i];
  142.                return(SwEntry.hwnd);
  143.             }
  144.          }
  145.       }
  146.    }
  147.    // if made it here then window not found, so exit
  148.    exit(1);
  149. }
  150.  
  151. MoveWindow(hwnd,col,row)
  152. {
  153.    #define ORD_WIN32SETWINDOWPOS 875
  154.    #define SWP_MOVE              0x0002
  155.    #define SWP_NOADJUST          0x0040
  156.    PMDynamicLink("PMWIN",ORD_WIN32SETWINDOWPOS,BIT32,CDECL,
  157.                  hwnd,0,col,row,0,0,SWP_MOVE | SWP_NOADJUST);
  158. }
  159.  
  160. GetWindowPosition(hwnd,Col,Row,Width,Height)
  161. {
  162.    #define SWP_BLOB_SIZE 9 * 4
  163.    BLObSize(swp,SWP_BLOB_SIZE);
  164.    #define ORD_WIN32QUERYWINDOWPOS  837
  165.    if !DynamicLink("PMWIN",ORD_WIN32QUERYWINDOWPOS,BIT32,CDECL,hwnd,swp)
  166.       exit(1);
  167.    Height = BLObGet(swp,4,SWORD32);
  168.    Width = BLObGet(swp,8,SWORD32);
  169.    Row = BLObGet(swp,12,SWORD32);
  170.    Col = BLObGet(swp,16,SWORD32);
  171. }
  172.  
  173. GetCurrentBoxFont(height,width)
  174. {
  175.    BLObSize(current,2);
  176.    PrfQueryProfileData(HINI_USERPROFILE,"Shield","~Font Size...",current,2);
  177.    height = BLObGet(current,1,UWORD8);
  178.    width = BLObGet(current,0,UWORD8);
  179. }
  180.  
  181. SetCurrentBoxFont(height,width)
  182. {
  183.    BLObPut(current,0,width,UWORD8);
  184.    BLObPut(current,1,height,UWORD8);
  185.    PrfWriteProfileData(HINI_USERPROFILE,"Shield","~Font Size...",current,2);
  186. }
  187.  
  188.