home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / WLSTART.ZIP / WLSTART.C next >
Text File  |  1991-04-22  |  2KB  |  95 lines

  1. /* Start the Workstation Lock */
  2. #define INCL_WIN
  3. #define INCL_DOS
  4. #include <os2.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7.  
  8. #define BUFFER 80
  9. #define ID_GO    101
  10.  
  11. BOOL FindandStartWL(VOID);
  12.  
  13. int main(void)
  14.  {
  15.  HAB hab;
  16.  HMQ     hmq;
  17.  
  18.  hab=WinInitialize(0);
  19.  hmq=WinCreateMsgQueue(hab,DEFAULT_QUEUE_SIZE);
  20.  
  21.  if(!FindandStartWL())
  22.       {
  23.       PSTARTDATA pstd;
  24.       PSZ pszPgm;
  25.       USHORT usSess,usID;
  26.  
  27.       pstd=(PSTARTDATA)malloc(sizeof(*pstd));
  28.       pszPgm=(PSZ)malloc(CCHMAXPATH);
  29.  
  30.       memset(pstd,0x00,sizeof(*pstd));
  31.       memset(pszPgm,0x00,CCHMAXPATH);
  32.  
  33.       DosSearchPath(DSP_ENVIRONMENT,
  34.                          "PATH",
  35.                          "wl.exe",
  36.                          pszPgm,
  37.                          CCHMAXPATH);
  38.  
  39.       pstd->Length=(USHORT)sizeof(STARTDATA);
  40.       pstd->FgBg=TRUE;
  41.       pstd->PgmName=pszPgm;
  42.       pstd->PgmInputs=NULL;
  43.       pstd->SessionType=3;
  44.       pstd->PgmControl=1;
  45.       DosStartSession(pstd,&usSess,&usID);
  46.       free(pstd);
  47.       free(pszPgm);
  48.       DosSleep(5000L);
  49.       FindandStartWL();
  50.       }
  51.  
  52.  WinDestroyMsgQueue(hmq);
  53.  WinTerminate(hab);
  54.  return 0;
  55.  }
  56.  
  57. BOOL FindandStartWL
  58. (
  59. VOID
  60. )
  61. {
  62.  HWND  hwnd;
  63.  HWND  hwndTitle;
  64.  HENUM henum;
  65.  CHAR  p[BUFFER];
  66.  BOOL  fFound;
  67.  
  68.  fFound=FALSE;
  69.  
  70.  henum=WinBeginEnumWindows(HWND_DESKTOP);
  71.  
  72.  while(hwnd=WinGetNextWindow(henum))
  73.         {
  74.         memset(p,0x00,BUFFER);
  75.         hwndTitle=WinWindowFromID(hwnd,FID_TITLEBAR);
  76.         WinQueryWindowText(hwndTitle,BUFFER,p);
  77.         if(!strcmp(p,"W L"))
  78.           {
  79.           HMQ hmqWL=(HMQ)WinQueryWindowULong(hwnd,QWL_HMQ);
  80.           if(hmqWL)
  81.               {
  82.               WinPostQueueMsg(hmqWL,
  83.                                     WM_COMMAND,
  84.                                     MPFROMSHORT(ID_GO),
  85.                                     MPFROM2SHORT(CMDSRC_OTHER,FALSE));
  86.               fFound=TRUE;
  87.               }
  88.           break;
  89.           }
  90.         }
  91.  WinEndEnumWindows(henum);
  92.  
  93.  return fFound;
  94. }
  95.