예제 #1
0
extern VOID Add2TaskList ( HWND hwnd, PSZ Name )
{
 /***************************************************************************
  * Get the window's process ID.                                            *
  ***************************************************************************/

  PID pid ;
  WinQueryWindowProcess ( hwnd, &pid, PTID(NULL) ) ;

 /***************************************************************************
  * Add an entry to the system task list.                                   *
  ***************************************************************************/

  SWCNTRL swctl ;
  swctl.hwnd = hwnd ;
  swctl.hwndIcon = 0 ;
  swctl.hprog = 0;
  swctl.idProcess = pid ;
  swctl.idSession = 0 ;
  swctl.uchVisibility = SWL_VISIBLE ;
  swctl.fbJump = SWL_JUMPABLE ;
  strcpy ( swctl.szSwtitle, (PCHAR)Name ) ;

  WinAddSwitchEntry ( &swctl ) ;
}
예제 #2
0
파일: khserver.c 프로젝트: komh/kime
MRESULT khs_umIsExceptWindow( HWND hwnd, MPARAM mp1, MPARAM mp2 )
{
    PKHSCD      pkhscd = WinQueryWindowPtr( hwnd, 0 );
    HWND        hwndTarget = HWNDFROMMP( mp1 );
    PID         pid;
    PCHAR       modulePath;
    PCHAR       moduleName;
    ULONG       maxPathLen;
    APIRET      rc;
    BOOL        result;

    WinQueryWindowProcess( hwndTarget, &pid, NULL );

#ifdef DEBUG
    fprintf( pkhscd->fp, "PID = %x\n", pid );
#endif

    memset( pkhscd->pQTopLevel, 0, DOSQSS_BUFSIZE );

    rc = DosQuerySysState( 0x01, 0, pid, 1, pkhscd->pQTopLevel, DOSQSS_BUFSIZE );
    if( rc != 0 )
        return FALSE;

    DosQuerySysInfo( QSV_MAX_PATH_LENGTH, QSV_MAX_PATH_LENGTH, &maxPathLen, sizeof( ULONG ));

    modulePath = malloc( maxPathLen );
    DosQueryModuleName( pkhscd->pQTopLevel->procdata->hndmod, maxPathLen, modulePath );

#ifdef DEBUG
    fprintf( pkhscd->fp, "Module path = %s\n", modulePath );
#endif

    moduleName = strrchr( modulePath, '\\' );
    if( moduleName == NULL )
        moduleName = modulePath;
    else
        moduleName++;

#ifdef DEBUG
    fprintf( pkhscd->fp, "Module name = %s\n", moduleName );
#endif

    result = exceptFindName( pkhscd->exceptListBuf, moduleName );

    free( modulePath );

#ifdef DEBUG
    fprintf( pkhscd->fp, "exceptFindName() = %ld\n", result );

    fflush( pkhscd->fp );
#endif

    return MRFROMLONG( result );
}
예제 #3
0
파일: khserver.c 프로젝트: komh/kime
MRESULT khs_umCheckDBCSSupport( HWND hwnd, MPARAM mp1, MPARAM mp2 )
{
    PKHSCD      pkhscd = WinQueryWindowPtr( hwnd, 0 );
    HWND        hwndTarget = HWNDFROMMP( mp1 );
    PID         pid;
    USHORT      qcp;


    WinQueryWindowProcess( hwndTarget, &pid, NULL );
    DosGiveSharedMem( pkhscd->pCursorPos, pid, PAG_READ | PAG_WRITE );

    qcp = SHORT1FROMMR( WinSendMsg( hwndTarget, WM_QUERYCONVERTPOS,
                                   MPFROMP( pkhscd->pCursorPos ), 0 ));

    return MRFROMLONG( qcp == QCP_CONVERT );
}
예제 #4
0
static DDESTRUCT *MakeDDEObject( HWND hwnd, char *item_name,
                                 USHORT fsStatus, USHORT usFormat,
                                 void *data, int data_len )
/****************************************************************/
{
    DDESTRUCT   *dde;
    int         item_len;
    PID         pid;
    TID         tid;

    if( item_name != NULL ) {
        item_len = strlen( item_name ) + 1;
    } else {
        item_len = 1;
    }
    if( !DosAllocSharedMem( (PPVOID)&dde, NULL, sizeof( DDESTRUCT ) +
                            item_len + data_len,
                            PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_GIVEABLE ) ) {
        WinQueryWindowProcess( hwnd, &pid, &tid );
        DosGiveSharedMem( (PVOID)&dde, pid, PAG_READ | PAG_WRITE );
        dde->cbData = data_len;
        dde->fsStatus = fsStatus;
        dde->usFormat = usFormat;
        dde->offszItemName = sizeof( DDESTRUCT );
        if( (data_len != 0) && (data != NULL) ) {
            dde->offabData = (USHORT)(sizeof( DDESTRUCT ) + item_len);
        } else {
            dde->offabData = 0;
        }
        if( item_name != NULL ) {
            strcpy( (char *)DDES_PSZITEMNAME( dde ), item_name );
        } else {
            strcpy( (char *)DDES_PSZITEMNAME( dde ), "" );
        }
        if( data != NULL ) {
            memcpy( DDES_PABDATA( dde ), data, data_len );
        }
        return( dde );
    }
    return( NULL );
}
예제 #5
0
/*-----------------------------------------------
   Helper function to keep the title bar and the
   switch entry up to date.
 -----------------------------------------------*/
VOID SetSwitchEntry(HWND hwnd, PSZ szTitleBar, PSZ szFract)
{
    PID pid;
    static SWCNTRL swcntrl;
    static HSWITCH hswitch = NULL;
    HWND hwndFrame;

    hwndFrame = WinQueryWindow (hwnd, QW_PARENT, FALSE);

    if (hswitch == (HSWITCH) NULL) {  /* if first time */

        /* get our process ID for the Switch structure */
        WinQueryWindowProcess(hwndFrame, &pid, NULL);

        /* add/change switch list entry */
        swcntrl.hwnd             = hwndFrame;
        swcntrl.hwndIcon         = (HWND) NULL;
        swcntrl.hprog            = (HPROGRAM) NULL;
        swcntrl.idProcess        = pid;
        swcntrl.idSession        = 0;
        swcntrl.uchVisibility    = SWL_VISIBLE;
        swcntrl.fbJump           = SWL_JUMPABLE;
        _fstrcpy( swcntrl.szSwtitle, szTitleBar);
        strcat( swcntrl.szSwtitle, " - ");
        _fstrcat( swcntrl.szSwtitle, szFract);
        swcntrl.fReserved        = '\0';

        hswitch = WinAddSwitchEntry( &swcntrl );
    }
    else {   /* do an update */
        _fstrcpy( swcntrl.szSwtitle, szTitleBar);
        strcat( swcntrl.szSwtitle, " - ");
        _fstrcat( swcntrl.szSwtitle, szFract);

        WinChangeSwitchEntry( hswitch, &swcntrl);
    }

    /* now put it in the titlebar also */
    WinSetWindowText(hwndFrame, swcntrl.szSwtitle);

}
예제 #6
0
static PDDESTRUCT MakeDDEObject (
   HWND Destination,                    // -> Destination window
   PSZ Item,                            // -> Item name or NULL.
   USHORT Status,                       // Status flags.
   USHORT Format,                       // Data format
   PVOID Data,                          // -> Data or NULL.
   ULONG DataLen                        // Data length in bytes.
) {

   ULONG ItemLen = Item ? strlen(PCHAR(Item))+1 : 1 ;

   PDDESTRUCT pBlock ;
   if ( DosAllocSharedMem ( PPVOID(&pBlock), 0, sizeof(DDESTRUCT) + ItemLen + DataLen,
      PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_GIVEABLE ) )
      return ( 0 ) ;

   pBlock->cbData = DataLen ;
   pBlock->fsStatus = Status ;
   pBlock->usFormat = Format ;
   pBlock->offszItemName = sizeof(DDESTRUCT) ;

   if ( DataLen AND Data )
      pBlock->offabData = USHORT ( sizeof(DDESTRUCT) + ItemLen ) ;
   else
      pBlock->offabData = 0 ;

   if ( Item )
      strcpy ( PCHAR(DDES_PSZITEMNAME(pBlock)), PCHAR(Item) ) ;
   else
      strcpy ( PCHAR(DDES_PSZITEMNAME(pBlock)), "" ) ;

   if ( Data )
      memcpy ( DDES_PABDATA(pBlock), Data, size_t(DataLen) ) ;

   PID pid ; TID tid ;
   WinQueryWindowProcess ( Destination, &pid, &tid ) ;
   DosGiveSharedMem( (PVOID)pBlock, pid, PAG_READ | PAG_WRITE) ;

   return ( pBlock ) ;
}
VOID main()
{

  if ( (hab = WinInitialize( 0L )) == (HAB) NULL ){
     printf( "ToolBar Error:  WinInitialize failed \n" );
     return;
  }
  else {
     if ( (hmq = WinCreateMsgQueue( hab, 0 )) == (HMQ) NULL ){
        printf( "ToolBar Error:  WinCreateMsgQueue failed \n" );
        return;
     }
     else {

       ULONG fulCreate= FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER |
                        FCF_MINMAX | FCF_SHELLPOSITION | FCF_ICON  ;
               /*
                *  Note: no menu was specificed in create flags
                */

        WinSetPointer( HWND_DESKTOP,
                       WinQuerySysPointer(HWND_DESKTOP,SPTR_WAIT,TRUE));

        WinRegisterClass(hab, szClassName, (PFNWP)MainWindowProc, CS_SIZEREDRAW, 0);

        hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
                                       0L,
                                       (PULONG)&fulCreate,
                                       szClassName ,
                                       szMainTitle,
                                       0L,
                                       (HMODULE)NULL,
                                       ID_MAIN_WIN,
                                       &hwndClient);
        if ( hwndFrame == NULLHANDLE ) {
           ShowErrorWindow( "Error creating Main window !", TRUE );
        }
        else {
           PFNWP     pfnwpOldFrameProc ;

             /* ---------  subclass frame proc  ------------------ */
           pfnwpOldFrameProc = WinSubclassWindow( hwndFrame,
                                                  (PFNWP) NewFrameProc );
           if ( pfnwpOldFrameProc == (PFNWP)0L ){
               ShowErrorWindow( "Error subclassing frame window !", TRUE );
           }
           else {
              PID       pid ;
              SWCNTRL   swCntrl;
              HSWITCH   hSwitch ;
              LONG      lRGB;

                /* -------  store old frame proc with handle  ------- */
              WinSetWindowULong( hwndFrame,
                                 QWL_USER,
                                 (ULONG) pfnwpOldFrameProc );

                /* ------------------ load menus  ------------------- */
              hwndMenuBar = WinLoadMenu( hwndFrame,
                                         (HMODULE)NULL,
                                         MID_MENUBAR );

              hwndToolBar = WinLoadMenu( hwndFrame,
                                         (HMODULE)NULL,
                                         MID_TOOLBAR );
                /*
                 *  Note that the last menu loaded, the toolbar, is the
                 *  one that is associated with the frame as "the" menu.
                 *  this means that hwndMenuBar is the only link to the
                 *  regular action bar, so hang onto it tightly
                 */

                /* ---------- set toolbar background color ---------- */
              lRGB =  WinQuerySysColor( HWND_DESKTOP, SYSCLR_BUTTONDARK, 0L );
              WinSetPresParam( hwndToolBar,
                               PP_BACKGROUNDCOLOR,
                               4L,
                               (PVOID)lRGB );

                /* ---------  set window size and pos  -------------- */
              WinSetWindowPos( hwndFrame,
                               HWND_TOP,
                               0, 0, 370, 300, 
                               SWP_SIZE | SWP_SHOW | SWP_ACTIVATE );

               /* ----------- add program to tasklist  --------------- */
              WinQueryWindowProcess( hwndFrame, &pid, NULL );
              swCntrl.hwnd = hwndFrame ;
              swCntrl.hwndIcon = (HWND) NULL ;
              swCntrl.hprog = (HPROGRAM) NULL ;
              swCntrl.idProcess = pid ;
              swCntrl.idSession = (LONG) NULL ;
              swCntrl.uchVisibility = SWL_VISIBLE ;
              swCntrl.fbJump = SWL_JUMPABLE ;
              sprintf( swCntrl.szSwtitle, szMainTitle );
              hSwitch = WinAddSwitchEntry((PSWCNTRL)&swCntrl);


              WinSetPointer(HWND_DESKTOP,
                            WinQuerySysPointer(HWND_DESKTOP,SPTR_ARROW,TRUE));

                 /* ---------- start the main processing loop ----------- */
              while (WinGetMsg(hab, &qmsg,NULLHANDLE,0,0)){
                  WinDispatchMsg(hab, &qmsg);
              }

              WinRemoveSwitchEntry( hSwitch );
           } /* end of else ( pfnwpOldFrameProc ) */

           WinSetPointer(HWND_DESKTOP,
                         WinQuerySysPointer(HWND_DESKTOP,SPTR_ARROW,TRUE));
           WinDestroyWindow(hwndFrame);
        }  /* end of else (hwndFrame == NULLHANDLE) */

        WinSetPointer(HWND_DESKTOP,
                      WinQuerySysPointer(HWND_DESKTOP,SPTR_ARROW,TRUE));
        WinDestroyMsgQueue(hmq);
     }  /* end of else ( ...WinCreateMsgQueue() */

   WinTerminate(hab);
   }  /* end of else (...WinInitialize(NULL) */
}  /*  end of main() */
/* This Proc handles the on-the-fly data CD writing */
MRESULT EXPENTRY onTheFlyStatusDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
  char text[CCHMAXPATH*2+10];
  char title[CCHMAXPATH];
  char *textPtr;
  char *textPtr2; 
  static LONG lCDSize;
  static LONG lImageSize;
  SWCNTRL swctl;
  PID pid;

  switch (msg)
    {      
    case WM_PAINT:
      {
        if(HlpPaintFrame(hwnd, TRUE))
          return (MRESULT)0;
        break;
      }
    case WM_INITDLG:   

      WinShowWindow(WinWindowFromID(hwnd,IDPB_STATUSOK),FALSE);
      WinShowWindow(WinWindowFromID(hwnd,IDPB_SHOWLOG),FALSE);      
      WinShowWindow(WinWindowFromID(hwnd,IDPB_ABORTWRITE), TRUE);
      /* Hide percent bar which shows the write progress */
      WinShowWindow(WinWindowFromID(hwnd,IDSR_PERCENT), FALSE);

      /* Add switch entry */
      memset(&swctl,0,sizeof(swctl));
      WinQueryWindowProcess(hwnd,&pid,NULL);
      swctl.hwnd=hwnd;
      swctl.uchVisibility=SWL_VISIBLE;
      swctl.idProcess=pid;
      swctl.bProgType=PROG_DEFAULT;
      swctl.fbJump=SWL_JUMPABLE;
      WinAddSwitchEntry(&swctl);

      /* Set percent bar to 0. */
      WinSetWindowText(WinWindowFromID(hwnd,IDSR_PERCENT),"0#0%");

      /* Set dialog font to WarpSans for Warp 4 and above */
      if(cwQueryOSRelease()>=40) {
        WinSetPresParam(hwnd,
                        PP_FONTNAMESIZE,(ULONG)sizeof(DEFAULT_DIALOG_FONT),
                        DEFAULT_DIALOG_FONT );
      }

      /* Custom painting */
      setupGroupBoxControl(hwnd, IDGB_CHECKSTATUS);
      setupStaticTextControl(hwnd, IDST_ACTIONTEXT);

      /* Show dialog */
      if(!bHaveWindowPos)
        WinSetWindowPos(hwnd,HWND_TOP,0,0,0,0,SWP_ZORDER|SWP_ACTIVATE);
      else
        WinSetWindowPos(hwnd,HWND_TOP,swpWindow.x, swpWindow.y, 0, 0, SWP_MOVE|SWP_ZORDER|SWP_ACTIVATE|SWP_SHOW);

      /* Get writer device from parameter memory */
      if((textPtr=strstr(ptrLocalMem, "--device"))!=NULL) 
        if((textPtr2=strchr(textPtr, ' '))!=NULL)
          if((textPtr2=strchr(++textPtr2, ' '))!=NULL)
            *textPtr2=0;
      sprintf(text, "\"%s\"", textPtr);
      /* First query free CD space */
      if(queryFreeDVDSpace(hwnd, text)) {
        WinPostMsg(hwnd,WM_CLOSE,0,0);
        return (MRESULT) TRUE;
      };
      if(textPtr2)
        *textPtr2=' ';
      
      return (MRESULT) TRUE;
    case WM_CLOSE:
      WinShowWindow(WinWindowFromID(hwnd,IDPB_ABORTWRITE),FALSE);
      WinShowWindow(WinWindowFromID(hwnd,IDPB_STATUSOK),TRUE);
      WinShowWindow(WinWindowFromID(hwnd,IDPB_SHOWLOG),TRUE);      
      return FALSE;
    case WM_COMMAND:
      switch(SHORT1FROMMP(mp1))
        {
        case IDPB_ABORTWRITE:
          /* User pressed the ABORT button */
          DosBeep(1000,200);
          bAbort=TRUE;
          writeLog("User pressed ABORT.\n");
          WinPostMsg(hwnd,WM_CLOSE,0,0);
          break;
        case IDPB_STATUSOK:
          WinQueryWindowPos(hwnd,&swpWindow);
          WinDismissDlg(hwnd,0);
          break;
        case IDPB_SHOWLOG:
          showLogFile();
          break;
        default:
          break;
        }
    case WM_APPTERMINATENOTIFY:
      if(1) {
        switch(LONGFROMMP(mp1)) {
        case ACKEY_ONTHEFLY:
          /* Writing done. */
          WinSendMsg(WinWindowFromID(hwnd,IDLB_CHECKSTATUS),LM_DELETEITEM,MPFROMSHORT(2),0);
          if(!(LONGFROMMP(mp2))) {
            /* Tell the folder that we successfully wrote the CD  */
            /* This message will cause the folder to reset the archive bit if selected */
            sendCommand("ONTHEFLYDONE=1");
            /* Text: "CD-ROM successfully created." */
            getMessage(text, IDSTRLB_CDROMCREATIONSUCCESS, sizeof(text), RESSOURCEHANDLE, hwnd);
            DosBeep(1000,100);
            DosBeep(2000,100);
            DosBeep(3000,100);
          }
          else {
            /* There was an error while writing */
            sendCommand("ONTHEFLYDONE=0");
            DosBeep(100,200);
            /* Text: "Error while writing on the fly!" */
            getMessage(text, IDSTRLB_ONTHEFLYDVDERROR, sizeof(text), RESSOURCEHANDLE, hwnd);
          }
          writeLog(text);
          writeLog("\n");
          WinSendMsg(WinWindowFromID(hwnd,IDLB_CHECKSTATUS),LM_INSERTITEM,MPFROMSHORT(2),text);
          WinShowWindow(WinWindowFromID(hwnd,IDSR_PERCENT),FALSE);
          WinPostMsg(hwnd,WM_CLOSE,0,0);
          WinSetWindowPos(hwnd,HWND_TOP,0,0,0,0,SWP_ZORDER|SWP_ACTIVATE);
          break;
        case ACKEY_FIXATING:
          /* This msg. is sent by the helper process when cdrecord begins with fixating the disk */
          WinSendMsg(WinWindowFromID(hwnd,IDLB_CHECKSTATUS),LM_DELETEITEM,MPFROMSHORT(2),0);
          if(LONGFROMMP(mp2)==0) {
            /* Text: "Fixating... (may need some minutes)" */
            getMessage(text, IDSTRLB_FIXATING, sizeof(text), RESSOURCEHANDLE, hwnd);
          }
          else {
            /* Text: "Writing buffers to CD..." */
            getMessage(text, IDSTRLB_WRITINGBUFFERS, sizeof(text), RESSOURCEHANDLE, hwnd);
          }
          WinSendMsg(WinWindowFromID(hwnd,IDLB_CHECKSTATUS),LM_INSERTITEM,MPFROMSHORT(2),text);
          break;
        case ACKEY_MBWRITTEN:
          {
            int iPercent;

            iPercent=LONGFROMMP(mp2);

            if(lImageSize<100)/* Catch division by zero trap */
              iPercent=0;
            else
              iPercent/=(lImageSize/100);

            if(iPercent>100)
              iPercent=100;
            if(iPercent<0)
              iPercent=0;
            
            /* Update percent bar value. The helper prog sends us the actual written Mbytes. */
            sprintf(text,"%d#%d%%", iPercent, iPercent);
            WinSetWindowText(WinWindowFromID(hwnd,IDSR_PERCENT), text);  
            break;
          }
        case ACKEY_PRINTSIZE:
          {
            FILE * file;

          /* The PM wrapper requested the imagesize by invoking mkisofs with the -print-size option.
             The helper prog sends us the # of extents (each 2048bytes) with this msg */

          /* Delete previous message in listbox */
          WinSendMsg(WinWindowFromID(hwnd,IDLB_CHECKSTATUS),LM_DELETEITEM,MPFROMSHORT(1),0);
          if(LONGFROMMP(mp2)<=2097152) {
            /* Put new msg with imagesize into listbox */
            /* title: "Imagesize is %d.%0.3d.%0.3d bytes" */
            getMessage(title, IDSTRD_IMAGESIZE, sizeof(title), RESSOURCEHANDLE, hwnd);
            sprintf(text,title,
                    LONGFROMMP(mp2)*2048/1000000,(LONGFROMMP(mp2)*2048%1000000)/1000,LONGFROMMP(mp2)*2048%1000);
          }
          else {
            /* title: "Estimated imagesize is %d Mb" */
            getMessage( title, IDSTRD_IMAGESIZESTATUSLINETEXT2, sizeof(title), RESSOURCEHANDLE, hwnd);
            sprintf(text, title, LONGFROMMP(mp2)*2/1024);
          }
          writeLog(text);
          writeLog("\n");
          WinSendMsg(WinWindowFromID(hwnd,IDLB_CHECKSTATUS),LM_INSERTITEM,MPFROMSHORT(1),text);
          /* Save imagesize. We need it for the percent bar */
          lImageSize=LONGFROMMP(mp2);

          /* mkisofs can't create the image for some reason... */
          if(lImageSize==0) {
            messageBox( text, IDSTRD_CHECKSIZEERRORMULTI, sizeof(text),
                        title, IDSTRD_ONTHEFLYTITLE, sizeof(title),
                        RESSOURCEHANDLE, hwnd, MB_OK | MB_ERROR | MB_MOVEABLE);
            WinPostMsg(hwnd,WM_CLOSE,0,0);
            break;
          }
          if(LONGFROMMP(mp2) >lCDSize && lCDSize!=0) {
            /* Text: "Image is bigger than free CD space! [...]. Do you want to proceed?"
               Title: "On the fly writing"
               */
            if(MBID_NO==messageBox( text, IDSTRPM_IMAGETOBIG , sizeof(text),
                                     title, IDSTRD_ONTHEFLYTITLE, sizeof(title),
                                     RESSOURCEHANDLE, hwnd, MB_YESNO | MB_WARNING|MB_MOVEABLE)) {            
              WinPostMsg(hwnd,WM_CLOSE,0,0);
              break;
            }
          }
          /**************************************************************************************************************************************************************/

          /* Check if user pressed Abort in the meantime */
          if(bAbort)
            return FALSE;

          /* Now starting the write process */
          if(pipePtr) {
            *pipePtr='|';
            pipePtr++;
            *pipePtr=' ';
          }

          /* Copy updated command line to parameter file */
          if((file=fopen(params[4],"wb"))!=NULL) {
            fwrite(ptrLocalMem, sizeof(char), SHAREDMEM_SIZE, file);
            fclose(file); 
          }
          /* Put a message in the listbox  */
          /* Text: "Writing on the fly..." */
          getMessage(text, IDSTR_ONTHEFLYWRITING, sizeof(text), RESSOURCEHANDLE, hwnd);
          WinSendMsg(WinWindowFromID(hwnd,IDLB_CHECKSTATUS),LM_INSERTITEM,MPFROMSHORT(2),text);

          /* Hide ABORT Button in the status dialog. We do not let the user interrupt a write because this
             will damage the CD. */
          WinShowWindow(WinWindowFromID(hwnd,IDPB_ABORTWRITE),FALSE);
          /* Set percent bar value */
          WinPostMsg(WinWindowFromID(hwnd,IDSR_PERCENT),WM_UPDATEPROGRESSBAR,MPFROMLONG(0),MPFROMLONG(lImageSize));
          /* Show percent bar which shows the write progress */
          WinShowWindow(WinWindowFromID(hwnd,IDSR_PERCENT),TRUE);

          /* logfilename as a parameter */
          buildLogName(title, logName,  sizeof(title));
          //          snprintf(text, sizeof(text), "\"%s\"" ,title);
          snprintf(text, sizeof(text), "\"%s\" \"%s\"" ,params[4], title);
          /* Launch the helper program */
          /* Title: "On the fly VIO helper" */
          getMessage(title, IDSTRVIO_ONTHEFLY, sizeof(title), RESSOURCEHANDLE, hwnd);
          launchWrapper( text, chrInstallDir, hwnd, "dvdthefly.exe", title);          
          break;
          }
        case ACKEY_CDSIZE:
          {
            FILE * file;

          /* This msg is sent by the helper prog after getting the actual free space of the inserted
             CD */
      
          /* Save CD-Size */
          lCDSize=LONGFROMMP(mp2);
          /* Delete previous Message in the listbox */
          WinSendMsg(WinWindowFromID(hwnd,IDLB_CHECKSTATUS),LM_DELETEITEM,MPFROMSHORT(0),0);

          if(lCDSize==0) {
            /* There was an error. */
            /* Title: "Writing CD"
               Text: "Can't query free CD space! On some systems detection of free CD space fails 
               so you may override this message if you know what you're doing! Do you want to proceed with writing? "
               */
            writeLog("Can't query CD-size. Returned value is 0.\n");
            writeLog("\n");

            if(MBID_NO==queryFreeCDSpaceError(hwnd)) {
              WinPostMsg(hwnd, WM_CLOSE,0,0);
              return FALSE;
            }
          }
          /* Delete check size error message in listbox */
          WinSendMsg(WinWindowFromID(hwnd,IDLB_CHECKSTATUS),LM_DELETEITEM,MPFROMSHORT(0),0);

          if(LONGFROMMP(mp2)<=2097152) {
            /* Insert the CD size into the listbox to inform the user */
            /* title: "Free CD space is %d.%0.3d.%0.3d bytes" */
            getMessage(title, IDSTRLB_FREECDSPACE, sizeof(title), RESSOURCEHANDLE, hwnd);
            sprintf(text,title,
                    LONGFROMMP(mp2)*2048/1000000,(LONGFROMMP(mp2)*2048%1000000)/1000,LONGFROMMP(mp2)*2048%1000);
          }
          else
            {
              getMessage( title, IDSTR_CDSIZESTATUSLINETEXT2, sizeof(title), RESSOURCEHANDLE, hwnd);
              sprintf(text, title, LONGFROMMP(mp2)*2/1024);
            }
          WinSendMsg(WinWindowFromID(hwnd,IDLB_CHECKSTATUS),LM_INSERTITEM,MPFROMSHORT(0),text);

          /* User pressed 'Abort' */
          if(bAbort)
            return FALSE;

           /* Query image size. This is the second check prior to writing */
          /* Put a message into the listbox */
          /* Text: "Calculating image size. Please wait..." */
          getMessage(text, IDSTRD_CALCULATINGIMAGESIZE, sizeof(text), RESSOURCEHANDLE, hwnd);
          writeLog(text);
          writeLog("\n");

          WinSendMsg(WinWindowFromID(hwnd,IDLB_CHECKSTATUS),LM_INSERTITEM,MPFROMSHORT(1),text);
          
          pipePtr=strchr(ptrLocalMem,'|');
          if(pipePtr) {
            *pipePtr=0;
            pipePtr++;
            *pipePtr=0;
            pipePtr--;

          }
          textPtr=strstr(ptrLocalMem,"-o-print-size");
          if(textPtr) {
            *textPtr=' ';
            textPtr++;
            *textPtr=' ';
          }
          /* Copy updated command line to parameter file */
          if((file=fopen(params[4],"wb"))!=NULL) {
            fwrite(ptrLocalMem, sizeof(char), SHAREDMEM_SIZE, file);
            fclose(file); 
          }
          /* logfilename as a parameter */
          buildLogName(title, logName,  sizeof(title));
          snprintf(text, sizeof(text), "\"%s\" \"%s\"" ,params[4], title);
          /* Launch the helper program */
          launchWrapper( text, chrInstallDir, hwnd,"prntsize.exe", "Query image size");          
          break;
          }
        default:
          break;
        }/* switch */
      }/* if(thisPtr) */           
      return WinDefWindowProc( hwnd, msg, mp1, mp2);
    default:
      break;
    }
    return WinDefDlgProc(hwnd, msg, mp1, mp2);    
}
예제 #9
0
BOOL DDERequest(HWND hwndClient,
                PSZ pszItemString)
{
    ULONG           mem;
    PID             pid;
    TID             tid;
    PDDESTRUCT      pddeStruct;
    PSZ             pszDDEItemName;

    // get some sharable memory
    DosAllocSharedMem((PVOID)&mem,
                      NULL,
                      sizeof(DDESTRUCT) + 1000,
                      PAG_COMMIT |
                      PAG_READ |
                      PAG_WRITE |
                      OBJ_GIVEABLE);

    // get the server's ID and give it access
    // to the shared memory
    WinQueryWindowProcess(G_hServerWnd, &pid, &tid);
    DosGiveSharedMem(&mem, pid, PAG_READ | PAG_WRITE);

    /* here is definition for DDESTRUCT, for further reference:
     * typedef struct _DDESTRUCT {
     * ULONG    cbData;
     * This is the length of data that occurs after the offabData parameter. If no
     * data exists, this field should contain a zero (0).
     * USHORT   fsStatus;       /  Status of the data exchange.
     * DDE_FACK
     * Positive acknowledgement
     * DDE_FBUSY
     * Application is busy
     * DDE_FNODATA
     * No data transfer for advise
     * DDE_FACKREQ
     * Acknowledgements are requested
     * DDE_FRESPONSE
     * Response to WM_DDE_REQUEST
     * DDE_NOTPROCESSED
     * DDE message not understood
     * DDE_FAPPSTATUS
     * A 1-byte field of bits that are reserved for application-specific returns.
     * USHORT   usFormat;       /  Data format.
     * USHORT   offszItemName;  /  Offset to item name.
     * This is the offset to the item name from the start of this structure. Item
     * name is a null (0x00) terminated string. If no item name exists, there must
     * be a single null (0x00) character in this position. (That is, ItemName is
     * ALWAYS a null terminated string.)
     *
     * USHORT   offabData;      /  Offset to beginning of data.
     * This is the offset to the data, from the start of this structure. This field
     * should be calculated regardless of the presence of data. If no data exists,
     * cbData must be zero (0).
     *
     * For compatibility reasons, this data should not contain embedded pointers.
     * Offsets should be used instead.
     *
     * --  CHAR     szItemName[]    /  offset: offszItemName
     * --  BYTE     abData[]        /  offset: offabData
     * } DDESTRUCT; */

    // setup DDE data structures
    pddeStruct = (PDDESTRUCT) mem;
    pddeStruct->fsStatus = 0;   // DDE_FACKREQ;            // Status

    pddeStruct->usFormat = DDEFMT_TEXT;     // Text format

    // go past end of data structure for the item name
    pddeStruct->offszItemName = sizeof(DDESTRUCT);

    pszDDEItemName = ((BYTE*)pddeStruct) + pddeStruct->offszItemName;
    strcpy(pszDDEItemName, pszItemString);

    // go past end of data structure
    // (plus past the name) for the data
    pddeStruct->offabData = strlen(pszDDEItemName) + 1;
    // offset to BEGINNING of data
    pddeStruct->cbData = 500;
    // length of the data

    ShowMessage(__FUNCTION__ ": sending request \"%s\"",
                pszItemString);

    // post our request to the server program
    if (G_NetscapeFound = WinDdePostMsg(G_hServerWnd,
                                        hwndClient,
                                        WM_DDE_REQUEST,
                                        pddeStruct,
                                        0))
                    // WinDdePostMsg frees the shared mem!
        ShowMessage("    --> success");
    else
        ShowMessage("    --> failed");

    return G_NetscapeFound;
}
/* This Proc handles the on-the-fly data CD writing */
MRESULT EXPENTRY waveinfoStatusDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
  char text[CCHMAXPATH*2 +10];
  char title[CCHMAXPATH];
  SWCNTRL swctl;
  PID pid;
  int a;
  int rate;
  int iBitRate;
  SHORT stereo;
  LONG lSec;

  switch (msg)
    {      
    case WM_INITDLG:

      /* Add switch entry */
      memset(&swctl,0,sizeof(swctl));
      WinQueryWindowProcess(hwnd,&pid,NULL);
      swctl.hwnd=hwnd;
      swctl.uchVisibility=SWL_VISIBLE;
      swctl.idProcess=pid;
      swctl.bProgType=PROG_DEFAULT;
      swctl.fbJump=SWL_JUMPABLE;
      WinAddSwitchEntry(&swctl);

      /*      sprintf(text,"1: %s, 2: %s, 3: %s",params[1],params[2],params[3]);
              WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, text,
              params[3],
              0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
              */

      WinSendMsg(WinWindowFromID(hwnd,IDST_WAVENAME),EM_SETTEXTLIMIT,MPFROMSHORT((SHORT)CCHMAXPATH),0);
      
      if(!iMp3 || (iMp3 && iMp3Decoder==IDKEY_USEMMIOMP3)) {
        /* Query a wave */          
        switch (mmAudioHeader.mmXWAVHeader.WAVEHeader.usFormatTag)
          {
          case DATATYPE_WAVEFORM:
            getMessage(text, IDSTR_PMWAVEINFOPCM, sizeof(text), RESSOURCEHANDLE, hwnd);
            break;
          case DATATYPE_ALAW:
            getMessage(text, IDSTR_PMWAVEINFOALAW, sizeof(text), RESSOURCEHANDLE, hwnd);
            break;
          case DATATYPE_MULAW:
            getMessage(text, IDSTR_PMWAVEINFOMULAW, sizeof(text), RESSOURCEHANDLE, hwnd);
            break;
          case DATATYPE_ADPCM_AVC:
            getMessage(text, IDSTR_PMWAVEINFOADPCM, sizeof(text), RESSOURCEHANDLE, hwnd);
            break;
          default:
            getMessage(text, IDSTR_PMWAVEINFOUNKNOWN, sizeof(text), RESSOURCEHANDLE, hwnd);	
            break;
          }
        
        /* Channels */
        getMessage(title, IDSTR_PMWAVEINFOCHANNELS, sizeof(title), RESSOURCEHANDLE, hwnd);	
        sprintf(text, title, mmAudioHeader.mmXWAVHeader.WAVEHeader.usChannels);
        WinSetWindowText(WinWindowFromID(hwnd,IDST_CHANNELS),text);
        
        /* Bit per sample */
        getMessage(title, IDSTR_PMWAVEINFOBITPERSAMPLE, sizeof(title), RESSOURCEHANDLE, hwnd);	
        sprintf(text, title,mmAudioHeader.mmXWAVHeader.WAVEHeader.usBitsPerSample);
        WinSetWindowText(WinWindowFromID(hwnd,IDST_BITPERSAMPLE),text);
        
        /* Samplerate */
        getMessage(title, IDSTR_PMWAVEINFOSAMPLERATE, sizeof(title), RESSOURCEHANDLE, hwnd);	
        sprintf(text, title, mmAudioHeader.mmXWAVHeader.WAVEHeader.ulSamplesPerSec);
        WinSetWindowText(WinWindowFromID(hwnd,IDST_SAMPLERATE),text);
        
        /* Filename */
        WinSetWindowText(WinWindowFromID(hwnd,IDST_WAVENAME),params[3]);
        
        /* Playtime */
        getMessage(title, IDSTR_PMWAVEINFOPLAYTIME, sizeof(title), RESSOURCEHANDLE, hwnd);	
        sprintf(text, title, mmAudioHeader.mmXWAVHeader.XWAVHeaderInfo.ulAudioLengthInBytes/
					 mmAudioHeader.mmXWAVHeader.WAVEHeader.ulAvgBytesPerSec/60,
					 mmAudioHeader.mmXWAVHeader.XWAVHeaderInfo.ulAudioLengthInBytes/
					 mmAudioHeader.mmXWAVHeader.WAVEHeader.ulAvgBytesPerSec%60);
        WinSetWindowText(WinWindowFromID(hwnd,IDST_PLAYTIME),text);

      }
      else
        {
          /* Query info for MP3 */
          getMessage(title, IDSTR_PMMP3INFODLGTITLE, sizeof(title), RESSOURCEHANDLE, hwnd);	
          WinSetWindowText(hwnd,title);

          WinSetWindowText(WinWindowFromID(hwnd,IDST_CDBITS), "");
        
          /* Filename */
          WinSetWindowText(WinWindowFromID(hwnd,IDST_WAVENAME),params[3]);

          audioHlpStartMp3Query(params[3], hwnd);
        }
      /* Set dialog font to WarpSans for Warp 4 and above */
      if(cwQueryOSRelease()>=40) {
        WinSetPresParam(hwnd,
                        PP_FONTNAMESIZE,(ULONG)sizeof(DEFAULT_DIALOG_FONT),
                        DEFAULT_DIALOG_FONT );
      }

      if(!bHaveWindowPos)
        WinSetWindowPos(hwnd,HWND_TOP,0,0,0,0,SWP_ZORDER|SWP_ACTIVATE|SWP_SHOW);
      else
        WinSetWindowPos(hwnd,HWND_TOP,swpWindow.x, swpWindow.y, 0, 0, SWP_MOVE|SWP_ZORDER|SWP_ACTIVATE|SWP_SHOW);

      return (MRESULT) TRUE;
      /* WM_APPTERMINATENOTIFY messages are sent from the helper programs e.g. format checker. */
    case WM_APPTERMINATENOTIFY:
      switch(LONGFROMMP(mp1))
        {
        case ACKEY_MP3INFO:
          rate=SHORT2FROMMP(mp2);
          iBitRate=SHORT1FROMMP(mp2);
          iBitRate>>=2;
          stereo=SHORT1FROMMP(mp2) & 0x3;

          /* Channels */
          getMessage(title, IDSTR_PMWAVEINFOCHANNELS, sizeof(title), RESSOURCEHANDLE, hwnd);
          if(stereo)	
            sprintf(text, title, 2);
          else
            sprintf(text, title, 1);
          WinSetWindowText(WinWindowFromID(hwnd,IDST_CHANNELS),text);
          
          /* Bitrate */
          getMessage(title, IDSTR_PMMP3INFOBITRATE, sizeof(title), RESSOURCEHANDLE, hwnd);	
          sprintf(text, title, iBitRate);
          WinSetWindowText(WinWindowFromID(hwnd,IDST_BITPERSAMPLE),text);
          
          /* Samplerate */
          getMessage(title, IDSTR_PMWAVEINFOSAMPLERATE, sizeof(title), RESSOURCEHANDLE, hwnd);	
          sprintf(text, title, rate);
          WinSetWindowText(WinWindowFromID(hwnd,IDST_SAMPLERATE),text);


          break;
        case ACKEY_PLAYTIME:
          lSec=LONGFROMMP(mp2);
          lSec/=(44100*4);

          /* Playtime */
          getMessage(title, IDSTR_PMWAVEINFOPLAYTIME, sizeof(title), RESSOURCEHANDLE, hwnd);	
          sprintf(text, title, lSec/60, lSec%60);
          WinSetWindowText(WinWindowFromID(hwnd,IDST_PLAYTIME),text);

          break;
        default:
          break;
        }
      return FALSE;

    case WM_CLOSE:
      WinQueryWindowPos(hwnd,&swpWindow);
      WinDismissDlg(hwnd,0);
      return FALSE;
    case WM_COMMAND:
      switch(SHORT1FROMMP(mp1))
        {
        case IDPB_OK:
          /* User pressed the OK button */
          WinPostMsg(hwnd,WM_CLOSE,0,0);
          break;
        default:
          break;
        }
      return (MRESULT) FALSE;
    default:
      break;
    }/* switch */
  
  return WinDefDlgProc( hwnd, msg, mp1, mp2);
}
예제 #11
0
BOOL Initialize(int argc, char* argv[])
{
    ULONG    flCreate;
    PID      pid;
    TID      tid;


    debOut = fopen ("\\PIPE\\WATCHCAT", "w");

    if (debOut)
    {
	fprintf(debOut, "MakMan/2 Init\n");
	fflush(debOut);
    }

    GetScoresFromIni();

    /*
     * create all semaphores for mutual exclusion and event timing
     */

    if (
        DosCreateEventSem( NULL,  &hevTick     , DC_SEM_SHARED,    FALSE) ||
        DosCreateEventSem( NULL,  &hevSound    , DC_SEM_SHARED,    FALSE) ||
        DosCreateEventSem( NULL,  &hevTermGame , DC_SEM_SHARED,    FALSE) ||
        DosCreateEventSem( NULL,  &hevTermSound, DC_SEM_SHARED,    FALSE)
        )
        return (FALSE);  /* failed to create a semaphore */


    WinShowPointer( HWND_DESKTOP, TRUE);
    habMain = WinInitialize( 0);
    if( !habMain)
	return( FALSE);

    hmqMain = WinCreateMsgQueue( habMain,0);
    if( !hmqMain)
	return( FALSE);

    WinLoadString( habMain, 0, IDS_TITLEBAR, sizeof(szTitle), szTitle);
    WinLoadString( habMain, 0, IDS_ERRORTITLE, sizeof(szErrorTitle), szErrorTitle);

    if( !WinRegisterClass( habMain
			  , (PCH)szTitle
			  , ClientWndProc
			  , CS_SIZEREDRAW | CS_MOVENOTIFY
			  , 0 ))
	return( FALSE);

    flCreate =   (FCF_TITLEBAR | FCF_SYSMENU    | FCF_MENU       | FCF_BORDER   | FCF_ICON |
		  FCF_AUTOICON | FCF_ACCELTABLE | FCF_MINBUTTON  | FCF_SHELLPOSITION  );
    hwndFrame =
	WinCreateStdWindow(
			   HWND_DESKTOP,                       /* handle of the parent window     */
			   0,                                  /* frame-window style              */
			   &flCreate,                          /* creation flags                  */
			   szTitle,                            /* client-window class name        */
			   szTitle,                            /* address of title-bar text       */
			   WS_SYNCPAINT,                       /* client-window style             */
			   0,                                  /* handle of the resource module   */
			   IDR_MAIN,                           /* frame-window identifier         */
			   &hwndClient);                       /* address of client-window handle */

    if( !hwndFrame)
	return( FALSE);


    if (debOut)
    {
	fprintf(debOut, "Creating engine\n");
	fflush(debOut);
    }

    //
    // Instantiate the Gfx Output engine
    //
    if (argc == 2)
    {
    strlwr(argv[1]); // make lower case
	if (strcmp(argv[1], "gpi") == 0)
        GfxEng = new gpi;
    else
        if (strcmp(argv[1], "dive") == 0)
            GfxEng = new dive;
            else {
                char buf[200];
                sprintf(buf, "Usage : MakMan [gpi | dive]\n"
                             "Unknown option %s\n", argv[1]);
                WinMessageBox(HWND_DESKTOP,
                          hwndFrame,
                          (PSZ) buf,
                          (PSZ) szTitle,
                          0,
                          MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL );
                return FALSE;
            }

    }
    else
        GfxEng = new gpi;

    SndEng = new mmpm2;

    if (debOut)
    {
    fprintf(debOut, "Gfx engine : %p Snd : %p\n", GfxEng, SndEng);
    fflush(debOut);
    }

    if (!GfxEng->open())
    {
	WinMessageBox(HWND_DESKTOP,
		      hwndFrame,
		      (PSZ) "Can't initialize selected Graphics Engine",
		      (PSZ) szTitle,
		      0,
		      MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL );
	return FALSE;
    }

    if (!SndEng->open())
    {
	WinMessageBox(HWND_DESKTOP,
		      hwndFrame,
              (PSZ) "Can't initialize MMPM2 Sound Engine\nSound won't be available for this session",
		      (PSZ) szTitle,
		      0,
		      MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL );
    }


    //
    // Finish up initializing the Window
    //

    // restore the previous position on screen
    int retc = WinRestoreWindowPos(szAppName, szKeyPosition, hwndFrame);
    if (debOut)
    {
        fprintf(debOut, "Restored old pos : %i\n",retc);
        fflush(debOut);
    }


    cxWidthBorder = (LONG) WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);
    cyWidthBorder = (LONG) WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER);
    cyTitleBar    = (LONG) WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR);
    cyMenu        = (LONG) WinQuerySysValue(HWND_DESKTOP, SV_CYMENU);
    cyScreen      = (LONG) WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);


    sizlMaxClient.cx = fieldSizeX * tileWidth  + cxWidthBorder * 2;
    sizlMaxClient.cy = fieldSizeY * tileHeight + cyWidthBorder * 2 + cyTitleBar + cyMenu ;

    // And now set the window to the correct size
    WinSetWindowPos( hwndFrame, HWND_TOP, 0, 0,
		    sizlMaxClient.cx, sizlMaxClient.cy,
		    SWP_SIZE | SWP_SHOW  | SWP_ACTIVATE);


    lByteAlignX = WinQuerySysValue( HWND_DESKTOP, SV_CXBYTEALIGN);
    lByteAlignY = WinQuerySysValue( HWND_DESKTOP, SV_CYBYTEALIGN);

    // Turn on visible region notification.
    WinSetVisibleRegionNotify ( hwndClient, TRUE );

    // And invalidate the visible region
    WinPostMsg ( hwndFrame, WM_VRNENABLED, 0L, 0L );

    // Enter the program in the WPS/PM task list
    WinQueryWindowProcess( hwndFrame, &pid, &tid);
    swctl.hwnd      = hwndFrame;
    swctl.idProcess = pid;
    strcpy( swctl.szSwtitle, szTitle);
    hsw = WinAddSwitchEntry(&swctl);

    hwndMenu = WinWindowFromID( hwndFrame, FID_MENU);


    //
    // Disable unused menu entries
    //
    EnableMenu(IDM_LEVEL,           FALSE);
    EnableMenu(IDM_HELPINDEX,       FALSE);
    EnableMenu(IDM_HELPEXTENDED,    FALSE);
    EnableMenu(IDM_HELPHELPFORHELP, FALSE);

    //
    // Look for a Joystick (driver)
    //
    APIRET rc;
    ULONG action;
    GAME_PARM_STRUCT gameParms;
    ULONG dataLen;


    rc = DosOpen(GAMEPDDNAME, &hGame, &action, 0,
                 FILE_READONLY, FILE_OPEN,
                 OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, NULL);

    if (rc != 0)
        hGame = 0;
    else
    {
        // There is a driver loaded - can we talk to him?
        dataLen = sizeof(gameParms);
        // Look for any (Joy)sticks
        rc = DosDevIOCtl(hGame, IOCTL_CAT_USER, GAME_GET_PARMS, NULL, 0, NULL,
                         &gameParms, dataLen, &dataLen);
        if (rc != 0 && debOut)
        {
            fprintf(debOut, "Couldn't call IOCtl for GAME$\n");
            fflush(debOut);
        }
     }

    // ok so far?
    if (hGame == 0 || rc != 0)
       {
            if (debOut)
            {
                fprintf(debOut, "Joystick driver not found\n");
                fflush(debOut);
            }
            DosClose(hGame);
            EnableMenu(IDM_JOY_A, FALSE);
            EnableMenu(IDM_JOY_B, FALSE);
            EnableMenu(IDM_CALIBRATE, FALSE);
            hGame = 0;
       }
        else
        {
            // all ok, deregister any superfluous menu entries
            // and calibrate sticks
            if (debOut)
            {
                fprintf(debOut, "JoyStat A: %i, B:%i\n", gameParms.useA, gameParms.useB);
                fflush(debOut);
            }

           /*
            * Keep only bits defined X and Y axis, they are bit 1 and bit 2
            */
           USHORT usTmp1 = gameParms.useA & GAME_USE_BOTH_NEWMASK;
           USHORT usTmp2 = gameParms.useB & GAME_USE_BOTH_NEWMASK;

            // No Joysticks
            if (gameParms.useA == 0 && gameParms.useB == 0)
            {
                EnableMenu(IDM_JOY_A, FALSE);
                EnableMenu(IDM_CAL_A, FALSE);
                EnableMenu(IDM_JOY_B, FALSE);
                EnableMenu(IDM_CAL_B, FALSE);
            }

            // One Joystick found
            // if usTmp2 is not 0, then Joystick 1 is an extended
            // type joystick (with 3 axes) but we don't care
            if (usTmp1 == GAME_USE_BOTH_NEWMASK &&
                usTmp2 != GAME_USE_BOTH_NEWMASK  )
            {
                EnableMenu(IDM_JOY_B, FALSE);
                EnableMenu(IDM_CAL_B, FALSE);
            }

            // And now read the calibration values
            GAME_CALIB_STRUCT gameCalib;

            dataLen = sizeof(gameCalib);
            rc = DosDevIOCtl(hGame, IOCTL_CAT_USER, GAME_GET_CALIB,
                             NULL, 0, NULL,
                             &gameCalib, dataLen, &dataLen );

            joyCal[1].x = gameCalib.Ax.centre;
            joyCal[1].y = gameCalib.Ay.centre;
            joyCal[2].x = gameCalib.Bx.centre;
            joyCal[2].y = gameCalib.By.centre;

        }


    /*
     * initialise help mechanism
     */
    HelpInit();


    // Set the default values for the various options...
    GetOptionsFromIni();

    // initiate random number generator
    srand(time(NULL));


    return TRUE;



}   /* end Initialize() */
/* This Proc handles the ISO image mounting */
MRESULT EXPENTRY unmountIsoDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
  char text[CCHMAXPATH];
  char title[CCHMAXPATH];

  ULONG rc;
  SWCNTRL swctl;
  PID pid;

  switch (msg)
    {      
    case WM_INITDLG:
      {
        BOOL bDone=FALSE;
        int i;

        writeLog("Initializing dialog...\n");  
        
        /* Add switch entry */
        memset(&swctl,0,sizeof(swctl));
        WinQueryWindowProcess(hwnd,&pid,NULL);
        swctl.hwnd=hwnd;
        swctl.uchVisibility=SWL_VISIBLE;
        swctl.idProcess=pid;
        swctl.bProgType=PROG_DEFAULT;
        swctl.fbJump=SWL_JUMPABLE;
        WinAddSwitchEntry(&swctl);
        
        /*sprintf(text,"%d",params[4]);*/ 
        // sprintf(text,"params[1]: %s ",params[1]);
        /* WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, pvSharedMem,
           params[4],
           0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
           WinPostMsg(hwnd,WM_CLOSE,0,0);
           return (MRESULT) TRUE;
           */
        
        /* Get free drive letters */
        if((rc=DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap))!=NO_ERROR)
          WinPostMsg(hwnd,WM_CLOSE,0,0);

        DosError(FERR_DISABLEHARDERR);

        for(i=2;i<26;i++) {
          if(( (ulDriveMap << (31-i)) >>31)) {
            char chrDrive[3]="A:";
            BYTE fsqBuf2[sizeof(FSQBUFFER2)+3*CCHMAXPATH]={0};
            PFSQBUFFER2 pfsqBuf2=(PFSQBUFFER2) &fsqBuf2;
            ULONG ulLength;

            /* Get FS */
            chrDrive[0]='A'+i;
            ulLength=sizeof(fsqBuf2);
            if(DosQueryFSAttach(chrDrive,0L,FSAIL_QUERYNAME, (PFSQBUFFER2)&fsqBuf2, &ulLength)==NO_ERROR) {
              if(!strcmp(pfsqBuf2->szName+pfsqBuf2->cbName+1,"ISOFS")) {
                FSINFO fsInfo;

                if(DosQueryFSInfo(i+1, FSIL_VOLSER, &fsInfo,sizeof(fsInfo))==NO_ERROR)
                  sprintf(text, "%s      (%s)",chrDrive,  fsInfo.vol.szVolLabel); 
                else
                  sprintf(text, "%s      (unknown)",chrDrive); 
                WinSendMsg(WinWindowFromID(hwnd, IDLB_UNMOUNTLETTER),LM_INSERTITEM,MPFROMSHORT(LIT_END),MPFROMP(text));
              }
            }
            else
              printf("%s %s\n",chrDrive, "---"); 
          }
        }
        DosError(FERR_ENABLEHARDERR);

        /* Set dialog font to WarpSans for Warp 4 and above */
        if(cwQueryOSRelease()>=40) {
          WinSetPresParam(hwnd,
                          PP_FONTNAMESIZE,(ULONG)sizeof(DEFAULT_DIALOG_FONT),
                          DEFAULT_DIALOG_FONT );
        }
        
        if(!bHaveWindowPos)
          WinSetWindowPos(hwnd,HWND_TOP,0,0,0,0,SWP_ZORDER|SWP_ACTIVATE);
        else
          WinSetWindowPos(hwnd,HWND_TOP,swpWindow.x, swpWindow.y, 0, 0, SWP_MOVE|SWP_ZORDER|SWP_ACTIVATE|SWP_SHOW);
        
        return (MRESULT) TRUE;
      }
    case WM_CLOSE:
      WinQueryWindowPos(hwnd,&swpWindow);
      WinDismissDlg(hwnd,0);
      return FALSE;
    case WM_HELP:
      sendCommand("DISPLAYHELPPANEL=5100");      
      break;
    case WM_COMMAND:
      switch(SHORT1FROMMP(mp1))
        {
        case IDPB_UNMOUNT:
          {
            /* User pressed the Unount button */
            AEFS_DETACH detachparms={0};
            char pszDrive[3]={0};
            HOBJECT hObject;
            SHORT sSelected;
            memset(&detachparms, 0, sizeof(detachparms));

            /* Get the drive letter */
            sSelected=SHORT1FROMMR(WinSendMsg(WinWindowFromID(hwnd, IDLB_UNMOUNTLETTER),LM_QUERYSELECTION,
                                             MPFROMSHORT(LIT_FIRST),MPFROMLONG(0L)));
            if(sSelected==LIT_NONE)
              break;

            WinSendMsg(WinWindowFromID(hwnd, IDLB_UNMOUNTLETTER),LM_QUERYITEMTEXT,
                       MPFROM2SHORT(sSelected,2),MPFROMP(pszDrive));

            /* Send the attachment request to the FSD. */
            rc = DosFSAttach(
                             //                             (PSZ) "",
                             (PSZ) pszDrive,
                             (PSZ) AEFS_IFS_NAME,
                             &detachparms,
                             sizeof(detachparms),
                             FS_DETACH);
            if (rc) {
              DosBeep(100,400);             
                            
              sprintf(text, "Error while unmounting rc=%d. Make sure there're no open files on the drive.\n", rc);
              WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, text,
                             "ISO image unmount error",
                             0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
            }else {
              WinSendMsg(WinWindowFromID(hwnd, IDLB_UNMOUNTLETTER),LM_DELETEITEM,
                         MPFROMSHORT(sSelected),MPFROMLONG(0L));
              sSelected=SHORT1FROMMR(WinSendMsg(WinWindowFromID(hwnd, IDLB_UNMOUNTLETTER),LM_QUERYITEMCOUNT,
                                                MPFROMLONG(0L),MPFROMLONG(0L)));
              if(sSelected==0)
                WinEnableWindow(WinWindowFromID(hwnd,IDPB_UNMOUNT), FALSE);
            }

            break;
          }
        case IDPB_UNMOUNTCLOSE:
          WinPostMsg(hwnd,WM_CLOSE,0,0);
          break;
        default:
          break;
        }
      return (MRESULT) FALSE;
    default:
      break;
    }
  return WinDefDlgProc(hwnd, msg, mp1, mp2);    
}
/* This Proc handles the on-the-fly data CD writing */
MRESULT EXPENTRY waveinfoStatusDialogProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
  char text[CCHMAXPATH*2 +10];
  char title[CCHMAXPATH];
  SWCNTRL swctl;
  PID pid;
  int a;


  switch (msg)
    {
    case WM_PAINT:
      {
        HPS hps;
        RECTL rcl, rclSource;
        POINTL ptl;
        LONG lTemp;
        BOOL bUseCustomPainting=TRUE;
        LONG lWidthX;
        LONG lWidthY;
        LONG  lColor;
        ULONG attrFound;


        if(bUseCustomPainting) {
          //          if(allBMPs[CTRLIDX_BG].hbm) {
          if(1) {
            hps=WinBeginPaint(hwnd, NULLHANDLE, &rcl);
            rclSource.xLeft=0;
            rclSource.yBottom=0;
#if 0
            rclSource.yTop=allBMPs[CTRLIDX_BG].bmpInfoHdr.cy;
            rclSource.xRight=allBMPs[CTRLIDX_BG].bmpInfoHdr.cx;
            lTemp=rcl.xLeft/rclSource.xRight;
            ptl.x=lTemp*rclSource.xRight;
            lTemp=rcl.yBottom/rclSource.yTop;
            lTemp*=rclSource.yTop;
#endif

            //    rcl.yBottom+=4;
            rclSource=rcl;
            rcl.yTop+=4;
            WinFillRect(hps, &rclSource, CLR_RED);

            /* Border */
            lWidthX=WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);
            lWidthY=WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER);

            GpiCreateLogColorTable(hps, 0, LCOLF_RGB, 0, 0, NULL);
#if 0
        if ( (WinQueryPresParam(hwnd, PP_BACKGROUNDCOLOR, 0, &attrFound, sizeof(attrFound),
                                                &lColor, QPF_PURERGBCOLOR)) == 0 )
           lColor = WinQuerySysColor(HWND_DESKTOP, SYSCLR_DIALOGBACKGROUND, 0);
#endif

            WinQueryWindowRect(hwnd, &rcl);
            ptl.x=1;
            ptl.y=0;
            GpiMove(hps, &ptl);
            GpiSetColor(hps, CLR_BLACK);
            ptl.x=rcl.xRight-1;
            GpiLine(hps,&ptl);
            ptl.y=rcl.yTop-1;
            GpiLine(hps,&ptl);
            GpiSetColor(hps, SYSCLR_SHADOW);
            ptl.x=rcl.xLeft;
            GpiLine(hps,&ptl);
            ptl.y=0;
            GpiLine(hps,&ptl);

            rcl.yTop-=1;
            rcl.yBottom+=1;
            rcl.xLeft+=1;
            rcl.xRight-=1;

            WinDrawBorder( hps,&rcl, 1, 1, 0, 0, 0x400);
            rcl.yTop-=1;
            rcl.yBottom+=1;
            rcl.xLeft+=1;
            rcl.xRight-=1;

            /* Get active border color */
            if(WinQueryActiveWindow(HWND_DESKTOP)==hwnd) {
              if ( (WinQueryPresParam(hwnd, PP_BORDERCOLOR, 0, &attrFound, sizeof(attrFound),
                                      &lColor, QPF_PURERGBCOLOR)) == 0 )
                lColor = WinQuerySysColor(HWND_DESKTOP, SYSCLR_DIALOGBACKGROUND, 0);
            }
            else {
              /* Inactive border color */
              if ( (WinQueryPresParam(hwnd, PP_INACTIVECOLOR, 0, &attrFound, sizeof(attrFound),
                                      &lColor, QPF_PURERGBCOLOR)) == 0 )
                lColor = WinQuerySysColor(HWND_DESKTOP, SYSCLR_DIALOGBACKGROUND, 0);
            }
            /*            Get Border size */
            WinSendMsg(hwnd, WM_QUERYBORDERSIZE, MPFROMP(&ptl),0);

            WinDrawBorder(hps,&rcl, ptl.x-2, ptl.y-2, lColor, 0, 0);

#if 0
            while(ptl.x<rcl.xRight) {
              ptl.y=lTemp;
              while(ptl.y<rcl.yTop) {/* y direction */
                //DosBeep(5000,100);
                WinDrawBitmap(hps, allBMPs[CTRLIDX_BG].hbm,
                              &rclSource, 
                              (PPOINTL)&ptl,
                              0, 0,
                              DBM_IMAGEATTRS);
                ptl.y+=allBMPs[CTRLIDX_BG].bmpInfoHdr.cy;
                //DosSleep(200);
              };
              ptl.x+=allBMPs[CTRLIDX_BG].bmpInfoHdr.cx; 
            };
#endif
            WinEndPaint(hps);
            return (MRESULT)0;
          }
        }
        break;
      }

    case WM_DRAWITEM:
      switch(SHORT1FROMMP(mp1))
        {
        case SLIDERID:
          return drawSlider(hwnd, msg, mp1, mp2, SHORT1FROMMP(mp1));
        default:
          break;
        }              
      break;
    case WM_INITDLG:
      /* Add switch entry */
      memset(&swctl,0,sizeof(swctl));
      WinQueryWindowProcess(hwnd,&pid,NULL);
      swctl.hwnd=hwnd;
      swctl.uchVisibility=SWL_VISIBLE;
      swctl.idProcess=pid;
      swctl.bProgType=PROG_DEFAULT;
      swctl.fbJump=SWL_JUMPABLE;
      WinAddSwitchEntry(&swctl);

#if 0      
      WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, "",
                     "",
                     0UL, MB_OK | MB_ICONEXCLAMATION|MB_MOVEABLE );
#endif
      //      oldProc=WinSubclassWindow(WinWindowFromID(hwnd, IDST_TEXT), newProc);
      hwndNew=WinCreateWindow(hwnd, CLASS_NAME, "Title", WS_VISIBLE |WS_TABSTOP, 10,50, SLIDERID, 40, 
                              hwnd, HWND_TOP, SLIDERID, NULLHANDLE, NULLHANDLE);
      WinShowWindow(hwnd, TRUE);
      //      WinQueryWindowPos(hwndNew,&swpSl);
      return (MRESULT) TRUE;
      /* WM_APPTERMINATENOTIFY messages are sent from the helper programs e.g. format checker. */
    case WM_CLOSE:
      WinDismissDlg(hwnd,0);
      return FALSE;
    case WM_CONTROL:
      {
        switch(SHORT2FROMMP(mp1))
          {
          case SLN_SLIDERTRACK:
            {
              switch(SHORT1FROMMP(mp1))
                {
                case SLIDERID:
                  DosBeep(5000, 10);
                  break;
                default:
                  break;
                }/* switch */
              return (MRESULT) 0;
              break;
            }
          case SLN_CHANGE:
            {
              switch(SHORT1FROMMP(mp1))
                {
                case SLIDERID:
                  DosBeep(500, 100);
                  break;
                default:
                  break;
                }/* switch */
              return (MRESULT)TRUE;
            }
          default:
            break;
          }/* switch */
        break;
      }/* WM_CONTROL */
      
    case WM_COMMAND:
      switch(SHORT1FROMMP(mp1))
        {
        case DID_OK:
          /* User pressed the OK button */
          WinPostMsg(hwnd,WM_CLOSE,0,0);
          break;
        case IDPB_RIGHT:
          WinPostMsg( WinWindowFromID(hwnd, SLIDERID),
                      SLM_SETSLIDERINFO,
                      MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE),
                      MPFROMLONG( (LONG) 70 ));
          
          break;
        case IDPB_LEFT:
          WinPostMsg( WinWindowFromID(hwnd, SLIDERID),
                      SLM_SETSLIDERINFO,
                      MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE),
                      MPFROMLONG( (LONG) 20 ));
          
          break;
        case IDPB_SIZE:
          {
            SWP swp;
              RXSTRING arg[2];                       /* argument string for REXX  */
              RXSTRING rexxretval;                /* return value from REXX    */
              APIRET   rc;                        /* return code from REXX     */
              SHORT    rexxrc = 0;                /* return code from function */
              char chrThis[20];
              char chrHwnd[20];

              char    *str = "These words will be swapped"; /* text to swap   */

#if 0
              RexxRegisterFunctionExe("CWRXFunc1", (PFN)rexxFunc1);
              

              sprintf(chrThis, "%d",123);
              sprintf(chrHwnd, "%d", WinQueryWindow(hwnd,QW_PARENT));

              /* By setting the strlength of the output RXSTRING to zero, we   */
              /* force the interpreter to allocate memory and return it to us. */
              /* We could provide a buffer for the interpreter to use instead. */
              rexxretval.strlength = 0L;          /* initialize return to empty*/
              
              MAKERXSTRING(arg[0], chrHwnd, strlen(chrHwnd));/* create input argument     */
              MAKERXSTRING(arg[1], chrThis, strlen(chrThis));/* create input argument     */

              /* Here we call the interpreter.  We don't really need to use    */
              /* all the casts in this call; they just help illustrate         */
              /* the data types used.                                          */
              rc=RexxStart((LONG)      2,             /* number of arguments   */
                           (PRXSTRING)  &arg,          /* array of arguments    */
                           (PSZ)        "G:\\Projects_working\\mmclasses-0.3.0\\testfunc.cwr",/* name of REXX file     */
                           (PRXSTRING)  0,             /* No INSTORE used       */
                           (PSZ)        "CWRXX",         /* Command env. name     */
                           (LONG)       RXSUBROUTINE,  /* Code for how invoked  */
                           (PRXSYSEXIT) 0,             /* No EXITs on this call */
                           (PSHORT)     &rexxrc,       /* Rexx program output   */
                           (PRXSTRING)  &rexxretval ); /* Rexx program output   */

              sprintf(text,"rc: %d, function return code: %d, %s ", 
                      rc, (int) rexxrc, rexxretval.strptr);

              WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, text, "", 1234, MB_OK|MB_MOVEABLE);
              
              DosFreeMem(rexxretval.strptr);          /* Release storage       
                                                         given to us by REXX.  */
              
#endif

              //            WinQueryWindowPos(hwndNew,&swp);
              //    WinSetWindowPos(hwndNew, NULLHANDLE, 0, 0, swp.cx-30, swp.cy+10,SWP_SIZE);
          break;
          }
        default:
          break;
        }
      return (MRESULT) FALSE;
    default:
      break;
    }/* switch */
  
  return WinDefDlgProc( hwnd, msg, mp1, mp2);
}
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
   RECTL    clientrect;                     /* Rectangle coordinates        */
   HPS      hpsPaint;
   POINTL   pt;                            /* String screen coordinates    */
   BOOL     Invalid;
   int      Line;
   ERRORID  Err;
   HWND     Focus,Active;
   HMQ      hmqDeb;
   PID      pid,cpid;
   TID      tid,ctid;
   switch( msg )
   {
   case WM_CREATE:
      WinStartTimer(hab,hwnd,1234,500);
      break;                                /* end the application.     */
   case WM_TIMER:
      rc=DosOpen("KBD$", &hKbd, &Action, 0, FILE_NORMAL, FILE_OPEN,
                 OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE |
                 OPEN_FLAGS_FAIL_ON_ERROR, 0);
      if (rc) {
         char Buf[80];
         sprintf(Buf,"Open rc = %d",rc);
         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,
                       Buf,
                       "TRAPIT",
                        1234,
                        MB_OK);
      } /* endif */
      Dlen= sizeof(State);
      rc = DosDevIOCtl( hKbd, 4, 0x73, 0, 0, 0, &State, sizeof(State), &Dlen );
      Shift=(USHORT)State;
      DosClose(hKbd);
      Invalid=FALSE;
      if ((State&0x0500)==0x0500) {
         if (Color!=CLR_RED) {
            Color=CLR_RED;
            Invalid=TRUE;
         } /* endif */
         Focus=WinQueryFocus(HWND_DESKTOP);
         Active=WinQueryActiveWindow(HWND_DESKTOP);
         WinQueryWindowProcess(Focus,&pid,&tid);
         hmqDeb=(HMQ)WinQueryWindowULong(Focus,QWL_HMQ);
         if (hmqDeb==hmq) {
            sprintf(Buffer,"Sorry Can't unhang Myself");
         } else {
            DosKillProcess(DKP_PROCESS,pid);
         } /* endif */
      } else {
         if ((State&0x0A00)==0x0A00) {
            if (Color!=CLR_BLUE) {
               Color=CLR_BLUE;
               Invalid=TRUE;
            } /* endif */
            Focus=WinQueryFocus(HWND_DESKTOP);
            Active=WinQueryActiveWindow(HWND_DESKTOP);
            WinQueryWindowProcess(Focus,&pid,&tid);
            hmqDeb=(HMQ)WinQueryWindowULong(Focus,QWL_HMQ);
            if (hmqDeb==hmq) {
               sprintf(Buffer,"Sorry Can't trap Myself");
            } else {
               HENUM hEnum;
               CHAR Class[20];
               HWND Child;
               hEnum = WinBeginEnumWindows(HWND_OBJECT);
               while ( (Child=WinGetNextWindow(hEnum)) != 0) {
                   WinQueryWindowProcess(Child,&cpid,&ctid);
                   if (cpid==pid) {
                       Class[0]=0;
                       WinQueryClassName(Child,sizeof(Class)-1,Class);
                       if (strcmp(Class,"Killer")==0) {
                           if (WinPostMsg(Child,WM_USER+1,0,0)) {
                              DosBeep(1800,80);
                              DosBeep(600,80);
                              DosBeep(1800,80);
                           }
                       } /* endif */
                   } /* endif */
               }
               WinEndEnumWindows(hEnum);
            } /* endif */
         } else {
            if (Color!=CLR_BACKGROUND) {
               Color=CLR_BACKGROUND;
               Invalid=TRUE;
            }
         } /* endif */
      } /* endif */
      if (Invalid) {
            WinInvalidateRect( hwnd, NULL, TRUE );
      } /* endif */
      break;
   case WM_PAINT:
      hpsPaint=WinBeginPaint( hwnd,0, &clientrect );
      WinFillRect( hpsPaint, &clientrect,Color );/* Fill invalid rectangle       */
      pt.x = 10; pt.y = 190;                    /* Set the text coordinates,    */
      GpiCharStringAt( hpsPaint, &pt, (LONG)strlen(Buffer),Buffer);
      for (Line=0;Line<8;Line++ ) {
         pt.x = 10; pt.y = 170-(20*Line);   /* Set the text coordinates,    */
         GpiCharStringAt( hpsPaint, &pt, (LONG)strlen(LabelText[Line]),LabelText[Line]);
      } /* endfor */
      WinEndPaint( hpsPaint );                        /* Drawing is complete   */
      break;
    case WM_CLOSE:
      /******************************************************************/
      /* This is the place to put your termination routines             */
      /******************************************************************/
      WinPostMsg( hwnd, WM_QUIT, 0L, 0L );  /* Cause termination        */
      break;
    default:
      /******************************************************************/
      /* Everything else comes here.  This call MUST exist              */
      /* in your window procedure.                                      */
      /******************************************************************/
      return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  }
  return FALSE;
}
예제 #15
0
extern int main ( int argc, char *argv[] ) {

  /**************************************************************************
   * Register self.                                                         *
   **************************************************************************/

   Sys_RegisterThread ( ) ;

  /**************************************************************************
   * Set a default exception filter.                                        *
   **************************************************************************/

   REGISTER_EXCEPTION_HANDLER(0);

  /**************************************************************************
   * Start the main block (for constructors/destructors).                   *
   **************************************************************************/

   {

  /**************************************************************************
   * Get the initial file path for loading files from command-line.         *
   **************************************************************************/

   char InitialPath [CCHMAXPATH] ;
   _fullpath ( InitialPath, ".", sizeof(InitialPath) ) ;
   strcat ( InitialPath, "\\" ) ;

  /**************************************************************************
   * Determine the home directory.                                          *
   **************************************************************************/

   char Drive [_MAX_DRIVE+1], Dir[_MAX_DIR+1], Fname[_MAX_FNAME+1], Ext[_MAX_EXT+1] ;
   strupr ( argv[0] ) ;
   _fullpath ( HomePath, argv[0], sizeof(HomePath) ) ;
   _splitpath ( HomePath, Drive, Dir, Fname, Ext ) ;
   if ( Dir[strlen(Dir)-1] == '\\' )
      Dir[strlen(Dir)-1] = 0 ;
   strcpy ( HomePath, Drive ) ;
   strcat ( HomePath, Dir ) ;

   _chdrive ( Drive[0] - 'A' + 1 ) ;
   _chdir ( "\\" ) ;
   _chdir ( Dir ) ;

  /**************************************************************************
   * Set the C RunTime Library error message file handle.                   *
   **************************************************************************/

   #ifdef __DEBUG_ALLOC__
      Log ( "Escriba::main: Program started." ) ;
      _set_crt_msg_handle ( fileno(Logfile) ) ;
   #else
      #ifdef DEBUG
         Log ( "Escriba::main: Program started." ) ;
      #endif // DEBUG
   #endif // __DEBUG_ALLOC__

  /**************************************************************************
   * Determine if another instance of this program is present.              *
   *   If so, pass the command-line information to it.                      *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: Checking for another instance already loaded." ) ;
   #endif // DEBUG

   PublicMemory Memory ( MEMORY_NAME, sizeof(SHARED_MEMORY), TRUE ) ;
   if ( NOT Memory.QueryCreated() ) {

      // Get the main instance's window handle.  Wait up to 20 seconds if necessary.
      HWND MainWindow = ((SHARED_MEMORY*)Memory.QueryMemory())->MainWindow ;
      clock_t LastClock = clock ( ) ;
      while ( MainWindow == 0 ) {
         if ( ( ( clock() - LastClock ) / CLOCKS_PER_SEC ) > 20 ) {
            Log ( "ERROR: Unable to get previous instance window handle." ) ;
            return ( 1 ) ;
         } /* endif */
         DosSleep ( 100 ) ;
         MainWindow = ((SHARED_MEMORY*)Memory.QueryMemory())->MainWindow ;
      } /* endwhile */

      // If any command-line parameters were given . . .
      if ( argc > 1 ) {

         // Build a command-line string.
         char Parms [512] = { 0 } ;
         int ParmLength = 0 ;
         while ( --argc ) {
            strcpy ( Parms+ParmLength, *(++argv) ) ;
            ParmLength += strlen(*argv) + 1 ;
         } /* endwhile */
         Parms[++ParmLength] = 0 ;

         // Get the original process's ID.
         PID Process ;
         TID Thread ;
         if ( !WinQueryWindowProcess ( MainWindow, &Process, &Thread ) ) {
            char Message [512] ;
            Log ( "ERROR: Unable to query window process.  %s", InterpretWinError(0,Message) ) ;
            return ( 1 ) ;
         } /* endif */

         // Allocate shared memory to hold the current path.
         PVOID Memory1 ;
         APIRET Status = DosAllocSharedMem ( &Memory1, 0, strlen(InitialPath)+1, fALLOC | OBJ_GIVEABLE | OBJ_GETTABLE) ;
         if ( Status ) {
            Log ( "ERROR: Unable to allocate shared memory.  Status %d.", Status ) ;
            return ( 1 ) ;
         } /* endif */
         strcpy ( PCHAR(Memory1), InitialPath ) ;

         // Allocate shared memory to hold the command-line.
         PVOID Memory2 ;
         Status = DosAllocSharedMem ( &Memory2, 0, ParmLength, fALLOC | OBJ_GIVEABLE | OBJ_GETTABLE) ;
         if ( Status ) {
            Log ( "ERROR: Unable to allocate shared memory.  Status %d.", Status ) ;
            return ( 1 ) ;
         } /* endif */
         memcpy ( Memory2, Parms, ParmLength ) ;

         // Make both shared memory blocks available to the original process.
         Status = DosGiveSharedMem ( Memory1, Process, PAG_READ | PAG_WRITE ) ;
         DosFreeMem ( Memory1 ) ;
         if ( Status ) {
            Log ( "ERROR: Unable to give shared memory.  Status %d.", Status ) ;
            return ( 1 ) ;
         } /* endif */
         Status = DosGiveSharedMem ( Memory2, Process, PAG_READ | PAG_WRITE ) ;
         DosFreeMem ( Memory2 ) ;
         if ( Status ) {
            Log ( "ERROR: Unable to give shared memory.  Status %d.", Status ) ;
            return ( 1 ) ;
         } /* endif */

         // Pass the information to the original process.
         Sys_PostMessage ( MainWindow, WM_LOAD_FILE, MPFROMP(Memory1), MPFROMP(Memory2) ) ;

      } /* endif */

      // Bring the previous instance to the fore.
      Sys_SetActiveWindow ( MainWindow ) ;

      // We're outta here . . .
      return ( 0 ) ;

   } /* endif */

  /**************************************************************************
   * If the ISPELL environment variable isn't set, set it to the current    *
   *   directory, before we change it.  This assumes that the current       *
   *   directory is also the directory to which Escriba (and ISPELL) was    *
   *   installed.  This is true with the basic installation.                *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: Setting ISPELL environment variable." ) ;
   #endif // DEBUG

   {
      char *p = getenv ( "ISPELL" ) ;
      if ( p == 0 ) {
         static char SetString [_MAX_PATH+10] ;
         sprintf ( SetString, "ISPELL=%s", HomePath ) ;
         _putenv ( SetString ) ;
      } /* endif */
   }

  /**************************************************************************
   * Get application language module.                                       *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: Loading default language." ) ;
   #endif // DEBUG

   char DefaultLanguage [80] = { 0 } ;

   { /* startblock */
      Profile IniFile ( PSZ(PROGRAM_NAME), 0, HomePath ) ;
      if ( IniFile.QueryHandle() ) 
         IniFile.GetString ( "Language", DefaultLanguage, sizeof(DefaultLanguage) ) ;
      else
         strcpy ( DefaultLanguage, "English" ) ;
   } /* endblock */

   Library = Language_Create ( PROGRAM_NAME, REVISION, IDS_TITLE1, DefaultLanguage ) ;
   if ( Library == 0 ) {
      Process Proc ( PROGRAM_NAME, HWND_DESKTOP, 0 ) ;
      Debug ( HWND_DESKTOP, "ERROR: Unable to find language module for %s, %s, %s.", PROGRAM_NAME, REVISION, DefaultLanguage ) ;
      return ( 1 ) ;
   } /* endif */

   LibraryHandle = Library->QueryHandle() ;

  /**************************************************************************
   * Get the program title.                                                 *
   **************************************************************************/

   ResourceString Title ( Library->QueryHandle(), IDS_TITLE ) ;

  /**************************************************************************
   * Determine the default codepage.                                        *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: Determining codepage to use." ) ;
   #endif // DEBUG

   PUSHORT pCodePage = Library->QueryCodepages() ;
   while ( *pCodePage ) {
      if ( !DosSetProcessCp ( *pCodePage ) )
         break ;
      pCodePage ++ ;
   } /* endwhile */

   if ( *pCodePage == 0 ) {
      ResourceString Format ( Library->QueryHandle(), IDS_WARNING_BADCODEPAGE ) ;
      CHAR Message [200] ;
      sprintf ( Message, PCHAR(Format), *Library->QueryCodepages() ) ;
      Log ( "%s", Message ) ;
      MessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
         PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION, LibraryHandle, IDS_MESSAGE_BOX_STRINGS ) ;
      return ( 1 ) ;
   } /* endif */
 
  /**************************************************************************
   * Initialize the process with an extra-large message queue.              *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: Connecting to PM." ) ;
   #endif // DEBUG

   Process Proc ( PCHAR(Title), HWND_DESKTOP, Library->QueryHandle(), 100, *pCodePage ) ;
   if ( Proc.QueryAnchor() == 0 ) 
      return ( 1 ) ;

  /**************************************************************************
   * Register the custom control classes.                                   *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: Registering custom control classes." ) ;
   #endif // DEBUG

   RegisterControls ( Proc.QueryAnchor() ) ;

  /**************************************************************************
   * Open up debug timer.                                                   *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: Opening debug timer." ) ;
   #endif // DEBUG

   OpenTimer ( ) ;

  /**************************************************************************
   * Open the registration library, if it is present.                       *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: About to open registration file." ) ;
   #endif // DEBUG

   char *RegistrationName = PROGRAM_NAME"R" ;
   Module *pRegistration = new Module ( RegistrationName, FALSE ) ;
   if ( pRegistration->QueryHandle() == 0 )
      RegistrationName = "PLUMAR" ;
   delete pRegistration, pRegistration = 0 ;

   Module Registration = Module ( RegistrationName, FALSE ) ;

  /**************************************************************************
   * Load any extenders (except spell-check).                               *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: About to load extenders." ) ;
   #endif // DEBUG

   AddonList.Build ( DefaultLanguage ) ;

  /**************************************************************************
   * Get the country information.                                           *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: About to get country information." ) ;
   #endif // DEBUG

   GetCountryInfo ( 0, 0 ) ;

  /**************************************************************************
   * Set any language-specific globals.                                     *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: About to set language-specific globals." ) ;
   #endif // DEBUG

   ResourceString AllGraphicFiles ( LibraryHandle, IDS_ALL_GRAPHICS ) ;
   GraphicTypeList[0] = PSZ ( AllGraphicFiles ) ;

  /**************************************************************************
   * Check for command-line options and remove them from the argument list. *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: About to parse the command line." ) ;
   #endif // DEBUG

   ResourceString ResetCommand ( Library->QueryHandle(), IDS_PARMS_RESET ) ;
   BOOL Reset = FALSE ;

// ResourceString PrintCommand ( Library->QueryHandle(), IDS_PARMS_PRINT ) ;
// BOOL Print = FALSE ;

   ResourceString TrapCommand ( Library->QueryHandle(), IDS_PARMS_TRAP ) ;
   BOOL Trap = FALSE ;

   int i = 1 ;
   char **p = argv + 1 ;
   while ( i < argc ) {
      if ( **p == '-' ) {
         if ( !stricmp ( (*p)+1, PCHAR(ResetCommand) ) ) {
            Reset = TRUE ;
//       } else if ( !stricmp ( (*p)+1, PCHAR(PrintCommand) ) ) {
//          Print = TRUE ;
         } else if ( !stricmp ( (*p)+1, PCHAR(TrapCommand) ) ) {
            Trap = TRUE ;
         } else {
            Debug ( HWND_DESKTOP, "ERROR: Invalid command-line parameter '%s'.", (*p)+1 ) ;
            return ( 1 ) ;
         } /* endif */
         for ( int j=i+1; j<argc; j++ ) {
            argv[j-1] = argv[j] ;
         } /* endfor */
         argv[j] = 0 ;
         argc -- ;
         continue ;
      } /* endif */
      i ++ ;
      p ++ ;
   } /* endwhile */

  /**************************************************************************
   * Create the help instance.                                              *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: About to create the help instance." ) ;
   #endif // DEBUG

   _splitpath ( Library->QueryName(), Drive, Dir, Fname, Ext ) ;
   char HelpFileName [CCHMAXPATH] ;
   sprintf ( HelpFileName, "%s.hlp", Fname ) ;

   ResourceString HelpTitle ( Library->QueryHandle(), IDS_HELPTITLE ) ;

   Help = new HelpWindow ( Proc.QueryAnchor(), 0, ID_MAIN, PSZ(HelpFileName), PSZ(HelpTitle) ) ;

   if ( Help->QueryHandle() == 0 ) {
      ERRORID Error = Sys_GetLastError ( Proc.QueryAnchor() ) ;
      ResourceString Format ( Library->QueryHandle(), IDS_ERROR_CREATEHELP ) ;
      CHAR Message [200] ;
      sprintf ( Message, PCHAR(Format), Error ) ;
      Log ( "%s", Message ) ;
      MessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message), PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION, LibraryHandle, IDS_MESSAGE_BOX_STRINGS ) ;
   } /* endif */

  /**************************************************************************
   * Open/create the profile file.  Reset if requested.                     *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: About to open profile file." ) ;
   #endif // DEBUG

   Profile2 IniFile ( PSZ(PROGRAM_NAME), Proc.QueryAnchor(), Library->QueryHandle(),
      IDD_PROFILE_PATH, Help, Reset ) ;

   if ( IniFile.QueryHandle() == 0 ) {
      ResourceString Message ( Library->QueryHandle(), IDS_ERROR_PRFOPENPROFILE ) ;
      Log ( "%s", PSZ(Message) ) ;
      MessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message), PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION, LibraryHandle, IDS_MESSAGE_BOX_STRINGS ) ;
      CloseTimer() ;
      return ( 2 ) ;
   } /* endif */

  /**************************************************************************
   * Get profile data. Try the OS2.INI first, then try for private INI.     *
   *   If obtained from OS2.INI, erase it afterwards and resave it.         *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: About to get profile data." ) ;
   #endif // DEBUG

   INIDATA IniData ( Registration.QueryHandle() ) ;
   IniFile.GetIniData ( IniData ) ;

   if ( IniData.Language [0] == 0 ) 
      strcpy ( IniData.Language, DefaultLanguage ) ;

  /**************************************************************************
   * Activate the spell checker, if it is present.                          *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: About to open the default dictionary." ) ;
   #endif // DEBUG

   char SpellerPath [ CCHMAXPATH ] = { 0 } ;
   if ( getenv ( "ISPELL" ) ) {
      strcpy ( SpellerPath, getenv ( "ISPELL" ) ) ;
      strcat ( SpellerPath, "\\" ) ;
   } /* endif */
   strcat ( SpellerPath, "ISPELLER.DLL" ) ;
   Dictionary *Speller = new Dictionary ( SpellerPath, DefaultLanguage ) ;
   if ( Speller->QueryLibrary() == 0 ) {
      #ifdef DEBUG
         Log ( "Escriba::main: Could not find spellchecker.  Will try again through LIBPATH." ) ;
      #endif // DEBUG
      delete Speller, Speller = 0 ;
      Speller = new Dictionary ( "ISPELLER", DefaultLanguage ) ;
   } /* endif */
   if ( Speller->Available() ) {
      #ifdef DEBUG
         Log ( "Escriba::main: Adding dictionary object to extension list." ) ;
      #endif // DEBUG
      AddonList.Add ( Speller ) ;
   } else {
      #ifdef DEBUG
         Log ( "Escriba::main: Dictionary object could not be fully created." ) ;
      #endif // DEBUG
      delete Speller, Speller = 0 ;
   } /* endif */

  /**************************************************************************
   * Create the frame window.                                               *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: About to create the frame window." ) ;
   #endif // DEBUG

   FRAMECDATA FrameControlData ;
   FrameControlData.cb = sizeof(FrameControlData) ;
   FrameControlData.flCreateFlags =
      FCF_TITLEBAR | FCF_MENU | FCF_ICON | FCF_NOBYTEALIGN | FCF_ACCELTABLE | FCF_SYSMENU |
      ( Trap ? 0 : FCF_SIZEBORDER | FCF_MINMAX ) ;
   FrameControlData.hmodResources = USHORT ( Library->QueryHandle() ) ;
   FrameControlData.idResources = ID_MAIN ;

   Window Frame ( HWND_DESKTOP, WC_FRAME, PSZ(Title),
      IniData.Animate ? WS_ANIMATE : 0,
      0, 0, 0, 0, HWND_DESKTOP, HWND_TOP, ID_MAIN,
      &FrameControlData, NULL ) ;

   if ( Frame.QueryHandle() == 0 ) {
      ERRORID Error = Sys_GetLastError ( Proc.QueryAnchor() ) ;
      ResourceString Format ( Library->QueryHandle(), IDS_ERROR_CREATEFRAME ) ;
      CHAR Message [200] ;
      sprintf ( Message, PCHAR(Format), Error ) ;
      Log ( "%s", Message ) ;
      MessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message), PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION, LibraryHandle, IDS_MESSAGE_BOX_STRINGS ) ;
      CloseTimer() ;
      return ( 3 ) ;
   } /* endif */

  /**************************************************************************
   * Associate the help instance with the frame window.                     *
   **************************************************************************/

   Help->Associate ( Frame.QueryHandle() ) ;

  /**************************************************************************
   * Register the client window class.                                      *
   **************************************************************************/

   if ( !WinRegisterClass ( Proc.QueryAnchor(), PSZ(CLASS_NAME),
      MessageProcessor, CS_MOVENOTIFY, sizeof(PVOID) ) ) {
      ERRORID Error = Sys_GetLastError ( Proc.QueryAnchor() ) ;
      ResourceString Format ( Library->QueryHandle(), IDS_ERROR_WINREGISTERCLASS ) ;
      CHAR Message [200] ;
      sprintf ( Message, PCHAR(Format), CLASS_NAME, Error ) ;
      Log ( "%s", Message ) ;
      MessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
         PSZ(Title), IDD_ERROR_WINREGISTERCLASS, MB_ENTER | MB_ICONEXCLAMATION | MB_HELP, LibraryHandle, IDS_MESSAGE_BOX_STRINGS ) ;
      CloseTimer() ;
      return ( 4 ) ;
   } /* endif */

  /**************************************************************************
   * Build the presentation parameters for the main window.                 *
   **************************************************************************/

   COLOR BackColor = IniData.fMainColors[0] ? IniData.MainColors[0] :
      WinQuerySysColor ( HWND_DESKTOP, SYSCLR_APPWORKSPACE, 0 ) ;
   ULONG Ids[] = { PP_BACKGROUNDCOLOR } ;
   ULONG ByteCounts[] = { sizeof(BackColor) } ;
   PUCHAR Params[] = { PUCHAR(&BackColor) } ;

   PPRESPARAMS PresParams = BuildPresParams ( sizeof(Ids)/sizeof(Ids[0]),
     Ids, ByteCounts, Params ) ;

  /**************************************************************************
   * Create client window.  If this fails, destroy frame and return.        *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: About to create the client window." ) ;
   #endif // DEBUG

   PARMS Parms ;
   Parms.Filler = 0 ;
   Parms.Library = Library ;
   Parms.Registration = & Registration ;
   Parms.IniFile = & IniFile ;
   Parms.IniData = & IniData ;
   Parms.Speller = Speller ;
   Parms.InitialPath = InitialPath ;
   Parms.argc = argc ;
   Parms.argv = argv ;
   Parms.Trap = Trap ;

   Window Client ( Frame.QueryHandle(), PSZ(CLASS_NAME), PSZ(""), WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
      0, 0, 0, 0, Frame.QueryHandle(), HWND_BOTTOM, FID_CLIENT, &Parms, PresParams ) ;

   free ( PresParams ) ;

   if ( Client.QueryHandle() == 0 ) {
      ERRORID Error = Sys_GetLastError ( Proc.QueryAnchor() ) ;
      ResourceString Format ( Library->QueryHandle(), IDS_ERROR_CREATECLIENT ) ;
      CHAR Message [200] ;
      sprintf ( Message, PCHAR(Format), Error ) ;
      Log ( "%s", Message ) ;
      MessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
         PSZ(Title), IDD_ERROR_CREATECLIENT, MB_ENTER | MB_ICONEXCLAMATION | MB_HELP, LibraryHandle, IDS_MESSAGE_BOX_STRINGS ) ;
      CloseTimer ( ) ;
      return ( 5 ) ;
   } /* endif */

   ((SHARED_MEMORY*)Memory.QueryMemory())->MainWindow = Client.QueryHandle() ;

  /**************************************************************************
   * Wait for and process messages to the window's queue.  Terminate        *
   *   when the WM_QUIT message is received.                                *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: About to enter the main message loop." ) ;
   #endif // DEBUG

   Sys_ProcessMessages ( Proc.QueryAnchor() ) ;

  /**************************************************************************
   * Discard all that had been requested of the system.                     *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: About to close the HR Timer." ) ;
   #endif // DEBUG

   CloseTimer ( ) ;

  /**************************************************************************
   * Invoke nearly all the destructors.                                     *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: Invoking most destructors." ) ;
   #endif // DEBUG

   } /* Invoke all destructors except the global ones. */

  /**************************************************************************
   * Invoke the remaining destructors.                                      *
   **************************************************************************/

   #ifdef DEBUG
      Log ( "Escriba::main: Clearing the addon list." ) ;
   #endif // DEBUG

   AddonList.Clear ( ) ;

   #ifdef DEBUG
      Log ( "Escriba::main: Clearing the file type list." ) ;
   #endif // DEBUG

   ClearFileTypeList ( ) ;

   #ifdef DEBUG
      Log ( "Escriba::main: Clearing the graphic type list." ) ;
   #endif // DEBUG

   ClearGraphicTypeList ( ) ;

   #ifdef DEBUG
      Log ( "Escriba::main: Destroying the help instance." ) ;
   #endif // DEBUG

   if ( Help ) delete Help ;

   #ifdef DEBUG
      Log ( "Escriba::main: Destroying the language library instance." ) ;
   #endif // DEBUG

   if ( Library ) delete Library ;

  /**************************************************************************
   * Check to see if any memory remains allocated.                          *
   **************************************************************************/

   #ifdef __DEBUG_ALLOC__
      Log ( "Escriba::main: Checking the heap." ) ;
      _dump_allocated ( 64 ) ;
      Log ( "Escriba::main: Program ended." ) ;
      fclose ( Logfile ) ;
   #else
      #ifdef DEBUG
         Log ( "Escriba::main: Program ended." ) ;
      #endif // DEBUG
   #endif // __DEBUG_ALLOC__

  /**************************************************************************
   * Discard the exception filter.                                          *
   **************************************************************************/

   UNREGISTER_EXCEPTION_HANDLER(0);

  /**************************************************************************
   * Terminate the process.                                                 *
   **************************************************************************/

   return ( 0 ) ;
}
// Поток приложения вызывает WindowProc всякий раз, когда для окна есть сообщение.
// Window - окно, Message - сообщение, *_parameter - данные, которые передаются вместе с сообщением.
MRESULT EXPENTRY Installer_ClientWindowProc( HWND Window, ULONG Message, MPARAM First_parameter, MPARAM Second_parameter )
{
 switch( Message )
  {
   // Выполняем действия при создании окна.
   case WM_CREATE:
    {
     WinPostMsg( Window, MY_CREATE, 0, 0 );
    }
   return 0;

   case MY_CREATE:
    {
     // Задаем заголовок окна приложения.
     if( Installer.Code_page == RUSSIAN ) strcpy( Installer.Frame_window_title, StrConst_RU_Title );
     else strcpy( Installer.Frame_window_title, StrConst_EN_Title );

     WinSetWindowText( Installer.Frame_window, Installer.Frame_window_title );

     // Устанавливаем картинку в левом верхнем углу окна.
     WinSendMsg( Installer.Frame_window, WM_SETICON, (MPARAM) WinLoadPointer( HWND_DESKTOP, NULLHANDLE, 1 ), 0 );

     // Задаем расположение окна.
     {
      INT X_Screen = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN );
      INT Y_Screen = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN );

      INT Window_width  = X_Screen / 3; if( X_Screen < 1024 ) Window_width  *= 1.25;
      INT Window_height = Y_Screen / 3; if( X_Screen < 1024 ) Window_height *= 1.25;

      INT Window_position_X = ( X_Screen - Window_width ) / 2;
      INT Window_position_Y = ( Y_Screen - Window_height ) / 2 + ( Y_Screen - Window_height ) / 4 / 2;

      WinSetWindowPos( Installer.Frame_window, HWND_TOP, Window_position_X, Window_position_Y, Window_width, Window_height, SWP_ZORDER | SWP_MOVE | SWP_SIZE | SWP_NOADJUST );
      WinSetActiveWindow( HWND_DESKTOP, Installer.Frame_window );
     }

     // Добавляем его в список окон.
     {
      SWCNTRL Task; HSWITCH Switch_handle = NULLHANDLE;

      bzero( &Task, sizeof( SWCNTRL ) );
      Task.hwnd = Installer.Frame_window;
      Task.hwndIcon = (HPOINTER) WinSendMsg( Installer.Frame_window, WM_QUERYICON, 0, 0 );
      WinQueryWindowProcess( Installer.Frame_window, &Task.idProcess, NULL );
      strcpy( Task.szSwtitle, Installer.Frame_window_title );

      Task.uchVisibility = SWL_VISIBLE;
      Task.fbJump = SWL_JUMPABLE;

      Switch_handle = WinCreateSwitchEntry( Installer.Application, &Task );
      WinChangeSwitchEntry( Switch_handle, &Task );
     }

     // Создаем поля ввода в окне рабочей области.
     ClientWindow_CreatePage( Installer.Client_window );
    }
   return 0;

   // Передвигаем поля ввода.
   case MY_APPLY_LAYOUT:
    {
     LitApplyLayout( &Client_Window.Layout );
    }
   return 0;

   // Включаем и отключаем поля ввода.
   case MY_ENABLE_BUTTONS:
    {
     ULONG Action = (ULONG) First_parameter;

     WinEnableWindow( WinWindowFromID( WinWindowFromID( Window, Client_Window.Settings.Buttons_brick_ID ), Client_Window.Settings.Install_button_ID ), Action );
     WinEnableWindow( WinWindowFromID( WinWindowFromID( Window, Client_Window.Settings.Buttons_brick_ID ), Client_Window.Settings.Remove_button_ID ), Action );
     WinEnableWindow( WinWindowFromID( WinWindowFromID( Window, Client_Window.Settings.Buttons_brick_ID ), Client_Window.Settings.Cancel_button_ID ), Action );

     if( !Action )
      WinSendMsg( WinWindowFromID( Installer.Frame_window, FID_SYSMENU ), MM_SETITEMATTR, MPFROM2SHORT( SC_CLOSE, INCLUDE_SUBMENUS ), MPFROM2SHORT( MIA_DISABLED, MIA_DISABLED ) );
     else
      WinSendMsg( WinWindowFromID( Installer.Frame_window, FID_SYSMENU ), MM_SETITEMATTR, MPFROM2SHORT( SC_CLOSE, INCLUDE_SUBMENUS ), MPFROM2SHORT( MIA_DISABLED, 0 ) );
    }
   return 0;

   // Обрабатываем нажатия на кнопки.
   case WM_COMMAND:
    {
     ULONG WM_Control_Button_ID = SHORT1FROMMP( First_parameter );

     if( WM_Control_Button_ID == Client_Window.Settings.Install_button_ID )
      {
       StartInstallerThread( NIA_INSTALL );
      }

     if( WM_Control_Button_ID == Client_Window.Settings.Remove_button_ID )
      {
       StartInstallerThread( NIA_REMOVE );
      }

     if( WM_Control_Button_ID == Client_Window.Settings.Cancel_button_ID )
      {
       WinPostMsg( Installer.Frame_window, WM_SYSCOMMAND, (MPARAM) SC_CLOSE, 0 );
      }
    }
   return 0;

   // Закрашиваем пространство окна.
   case WM_PAINT:
    {
     RECT Rectangle = {0};
     HPS Presentation_space = WinBeginPaint( Window, 0, &Rectangle );

     if( Presentation_space )
      {
       LONG Color_table[ 256 ]; bzero( Color_table, sizeof( Color_table ) );
       GpiQueryLogColorTable( Presentation_space, 0, 0, 256, Color_table );

       LONG Color_index = ( 256 - 1 );
       WinQueryPresParam( Window, PP_BACKGROUNDCOLOR, 0, NULL, sizeof( Color_table[ Color_index ] ), &Color_table[ Color_index ], QPF_NOINHERIT );
       GpiCreateLogColorTable( Presentation_space, 0, LCOLF_CONSECRGB, 0, 256, Color_table );

       WinFillRect( Presentation_space, &Rectangle, Color_index );
       WinEndPaint( Presentation_space );
      }
    }
   return 0;

   // Сообщаем окну рамки, что содержимое окна рабочей области закрашивать не следует.
   case WM_ERASEBACKGROUND:
   return (MPARAM) 0;

   // Выполняем действия при нажатии на кнопку закрытия окна.
   case WM_CLOSE:
    {
     // Убираем окно приложения из списка окон.
     WinRemoveSwitchEntry( WinQuerySwitchHandle( Installer.Frame_window, 0 ) );

     // Передаем сообщение обработчику.
     WinDefWindowProc( Window, Message, First_parameter, Second_parameter );
    }
   return 0;
  }

 // Возврат.
 return WinDefWindowProc( Window, Message, First_parameter, Second_parameter );
}