home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / setwin.zip / SETWINPM.C < prev    next >
Text File  |  1994-02-19  |  6KB  |  146 lines

  1. /*****************************************************************************
  2.     TITLE:      SetWinPM.C
  3.     AUTHOR:     Michael Thompson (Graduate Software)
  4.     CIS ID:     76500,2037
  5.     DATE:       02-19-1994
  6.     VERSION:    1.0
  7.     
  8.     Refer to SetWin.C for information about this program.
  9. *****************************************************************************/
  10.  
  11. #define INCL_DOS
  12. #define INCL_WIN
  13.  
  14. #include <os2.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17.  
  18. int main(int argc,char *argv[])
  19.     {
  20.     HAB AnchorBlock;
  21.     HMQ MessageQueue;
  22.     HWND Window;
  23.     CHAR Buffer[256];
  24.     CHAR *Action;
  25.     SWP Position;
  26.     LONG i,X,Y,CX,CY;
  27.     ULONG Delay;
  28.  
  29.     /**********************************************************
  30.         Create the anchor block and message queue.
  31.     **********************************************************/
  32.         AnchorBlock=WinInitialize(0);
  33.         MessageQueue=WinCreateMsgQueue(AnchorBlock,64);
  34.         
  35.     /**********************************************************
  36.         Display an error if the program is started without
  37.         the window handle and action parameters.
  38.     **********************************************************/
  39.         if(argc<3) {
  40.             WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,
  41.                           "This program is meant to be called by SETWIN.EXE.  "
  42.                           "Run SETWIN with no parameters for a list of options.",
  43.                           "SetWinPM Error",0,MB_CANCEL);
  44.             return 0;
  45.         }
  46.         
  47.     /**********************************************************
  48.         Get the window handle from the argument list.
  49.         Ignore requests with a NULL window handle.
  50.     **********************************************************/
  51.         sscanf(argv[1],"%p",&Window);
  52.         if(Window==NULLHANDLE)
  53.             return 0;
  54.             
  55.     /**********************************************************
  56.         Determine what actions are to be performed and then
  57.         perform them.
  58.     **********************************************************/
  59.         for(i=2;i<argc;i++) {
  60.             Action=argv[i];
  61.     
  62.             if(stricmp(Action,"MINIMIZE")==0)
  63.                 WinSetWindowPos(Window,NULLHANDLE,0,0,0,0,SWP_MINIMIZE);
  64.                 
  65.             else if(stricmp(Action,"MAXIMIZE")==0)
  66.                 WinSetWindowPos(Window,NULLHANDLE,0,0,0,0,SWP_MAXIMIZE);
  67.                 
  68.             else if(stricmp(Action,"RESTORE")==0)
  69.                 WinSetWindowPos(Window,NULLHANDLE,0,0,0,0,SWP_RESTORE);
  70.     
  71.             else if(stricmp(Action,"MOVE")==0) {
  72.                 if(argc<i+3) {
  73.                     WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,
  74.                                   "Supply horizontal and vertical positions.",
  75.                                   "SetWinPM Error",0,MB_CANCEL);
  76.                     return 0;
  77.                 }
  78.                 WinQueryWindowPos(Window,&Position);
  79.                 sscanf(argv[++i],"%d",&X);
  80.                 sscanf(argv[++i],"%d",&Y);
  81.                 WinSetWindowPos(Window,NULLHANDLE,X,Y,Position.cx,Position.cy,SWP_MOVE);
  82.             } 
  83.     
  84.             else if(stricmp(Action,"SIZE")==0) {
  85.                 if(argc<i+3) {
  86.                     WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,
  87.                                   "Supply horizontal and vertical sizes.",
  88.                                   "SetWinPM Error",0,MB_CANCEL);
  89.                     return 0;
  90.                 }
  91.                 sscanf(argv[++i],"%d",&CX);
  92.                 sscanf(argv[++i],"%d",&CY);
  93.                 WinSetWindowPos(Window,NULLHANDLE,0,0,CX,CY,SWP_SIZE);
  94.             } 
  95.     
  96.             else if(stricmp(Action,"HIDE")==0)
  97.                 WinSetWindowPos(Window,NULLHANDLE,0,0,0,0,SWP_HIDE);
  98.     
  99.             else if(stricmp(Action,"SHOW")==0)
  100.                 WinSetWindowPos(Window,NULLHANDLE,0,0,0,0,SWP_SHOW);
  101.     
  102.             else if(stricmp(Action,"FLASHON")==0)
  103.                 WinFlashWindow(Window,TRUE);
  104.     
  105.             else if(stricmp(Action,"FLASHOFF")==0)
  106.                 WinFlashWindow(Window,FALSE);
  107.  
  108.             else if(stricmp(Action,"ACTIVATE")==0)
  109.                 WinSetWindowPos(Window,NULLHANDLE,0,0,0,0,SWP_ACTIVATE);
  110.  
  111.             else if(stricmp(Action,"DEACTIVATE")==0)
  112.                 WinSetWindowPos(Window,NULLHANDLE,0,0,0,0,SWP_DEACTIVATE);
  113.  
  114.             else if(stricmp(Action,"TOP")==0)
  115.                 WinSetWindowPos(Window,HWND_TOP,0,0,0,0,SWP_ZORDER);
  116.  
  117.             else if(stricmp(Action,"BOTTOM")==0)
  118.                 WinSetWindowPos(Window,HWND_BOTTOM,0,0,0,0,SWP_ZORDER);
  119.  
  120.             else if(stricmp(Action,"SLEEP")==0) {
  121.                 if(argc<i+2) {
  122.                     WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,
  123.                                   "Supply delay in milliseconds.",
  124.                                   "SetWinPM Error",0,MB_CANCEL);
  125.                     return 0;
  126.                 }
  127.                 sscanf(argv[++i],"%u",&Delay);
  128.                 DosSleep(Delay);
  129.             }
  130.  
  131.             else {
  132.                 sprintf(Buffer,"Invalid action [%s] specified.",Action);
  133.                 WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,Buffer,"SetWinPM Error",0,MB_CANCEL);
  134.                 return 0;
  135.             }
  136.         }
  137.         
  138.     /**********************************************************
  139.         Destroy the message queue and anchor block.
  140.     **********************************************************/
  141.         WinDestroyMsgQueue(MessageQueue);
  142.         WinTerminate(AnchorBlock);
  143.         return 0;
  144.     }
  145.  
  146.