home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / BKUPINI.ZIP / INIPGMS.SAV < prev    next >
Text File  |  1990-05-20  |  45KB  |  1,012 lines

  1. #define EXTERN
  2. #include "INIPGMS.h"
  3.  
  4. /************************************************************************/
  5. /*                                                                      */
  6. /* Presentation Manager Program Main Body                               */
  7. /*                                                                      */
  8. /* The following routine is the Presentation Manager program Main Body. */
  9. /* The Main Body of a PM program is concerned with associating the      */
  10. /* application with the Presentation Manager system, creating its       */
  11. /* message queue, registering and displaying its main window, servicing */
  12. /* its message queue during the time that the application is active,    */
  13. /* and disassociating the application from PM when the user is finished */
  14. /* with the application. The remaining parts of this source module that */
  15. /* are concerned with the Presentation Manager are the application's    */
  16. /* window procedures (main window procedure, child window procedures,   */
  17. /* and dialog window procedures) that process the messages associated   */
  18. /* with the application's various windows.                              */
  19. /*                                                                      */
  20. /************************************************************************/
  21.  
  22. SHORT cdecl main(argc, argv)
  23. int argc;
  24. char *argv[];
  25. {
  26.  QMSG qmsg;  // MSG structure to store your messages                 
  27.  PID  pid;   // Process identifier for adding name to switch list
  28.  TID  tid;   // Thread identifier 
  29.  
  30.  // The WinInitialize routine initializes the Presentation Manager
  31.  // facilities for use by this application and returns a handle to the
  32.  // anchor block assigned to the application by PM.
  33.  
  34.  if((hAB = WinInitialize(NULL)) == NULL)
  35.     return(FALSE);
  36.   
  37.  // The WinCreateMsgQueue call creates a message queue for this application.
  38.  
  39.  if((hMQ = WinCreateMsgQueue(hAB, 0)) == NULL)
  40.     return(FALSE);
  41.  
  42.  // The following function registers the classes of all application windows.
  43.  if(!RegisterClass())
  44.     return(FALSE);
  45.  
  46.  // The CreateWindow function creates a frame window for this application's
  47.  // top window, and set the window's size and location as appropriate.
  48.  
  49.  hWndFrame = CreateWindow((HWND)HWND_DESKTOP,
  50.           FCF_TITLEBAR     |
  51.           FCF_SYSMENU      |
  52.           FCF_MINBUTTON    |
  53.           FCF_MAXBUTTON    |
  54.           FCF_SIZEBORDER   |
  55.           FCF_MENU         |
  56.           FCF_SHELLPOSITION,
  57.           szAppName,
  58.           "OS2 INI File Management",
  59.           ID_INIPGMS,
  60.           0, 0,
  61.           0, 0,
  62.           &hWndClient,
  63.           0L, SWP_SHOW);
  64.  
  65.  if(hWndFrame == NULL)
  66.     return(FALSE);
  67.  
  68.  // The following in-line routine fills out the application's switch control
  69.  // structure with the appropriate information to add the application's name
  70.  // to the OS/2 Task Manager List, a list of the jobs currently running on
  71.  // the computer.
  72.  
  73.  WinQueryWindowProcess(hWndFrame, &pid, &tid);
  74.  pSwctl.hwnd = hWndFrame;                         // Frame window handle   
  75.  pSwctl.idProcess = pid;                          // Process identifier    
  76.  pSwctl.uchVisibility = SWL_VISIBLE;              // visibility            
  77.  pSwctl.fbJump = SWL_JUMPABLE;                    // Jump indicator
  78.  strcpy(pSwctl.szSwtitle, "OS2 INI File Management");   // Frame window title
  79.  hSwitch = WinAddSwitchEntry(&pSwctl);
  80.    
  81.  // The following is the message loop for the application.
  82.  
  83.  while(WinGetMsg(hAB, (PQMSG)&qmsg, NULL, 0, 0))
  84.        WinDispatchMsg(hAB,(PQMSG)&qmsg);
  85.  
  86.  // Perform clean up before exiting application.
  87.  // The following routine destroys the application's frame window (which
  88.  // also destroys its child windows), destroys its message queue, and
  89.  // disassociates the application from the Presentation Manager system.
  90.  
  91.  WinDestroyWindow(hWndFrame); // Destroy the frame window
  92.  WinDestroyMsgQueue(hMQ);     // Destroy this application's message clue
  93.  WinTerminate(hAB);           // Terminate this application's use of the
  94.                               // Presentation Manager resources
  95. } // end of main
  96.  
  97.  
  98. // The following Dialog box calls are generated for the dialog boxes that
  99. // have been selected as "Client Area" dialog boxes.  To use these calls,
  100. // simply copy them to the appropriate location in the application.
  101.  
  102. #if 0
  103.  
  104.    WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)DSPLGRPSMsgProc, 
  105.              NULL, IDLG_DSPLGRPS, NULL);
  106.  
  107.    WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)SAVEPGMSMsgProc, 
  108.              NULL, IDLG_SAVEPGMS, NULL);
  109.  
  110.    WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)BKUPRUNMsgProc, 
  111.              NULL, IDLG_BKUPRUN, NULL);
  112.  
  113. #endif
  114.  
  115. /************************************************************************/
  116. /*                                                                      */   
  117. /* Main Window Procedure                                                */
  118. /*                                                                      */
  119. /* This procedure provides service routines for the general PM events   */
  120. /* (messages) that PM sends to the window, as well as the user          */
  121. /* initiated events (messages) that are generated when the user selects */
  122. /* the action bar and pulldown menu controls or the corresponding       */
  123. /* keyboard accelerators.                                               */
  124. /*                                                                      */
  125. /* The SWITCH statement shown below distributes the window messages to  */
  126. /* the respective message service routines, which are set apart by the  */
  127. /* CASE statements. The window procedures must provide an appropriate   */
  128. /* service routine for its end user initiated messages, as well as the  */
  129. /* general PM messages (like the WM_CLOSE message). If a message is     */
  130. /* sent to this procedure for which there is no programmed CASE clause  */
  131. /* (i.e., no service routine), the message is defaulted to the          */
  132. /* WinDefWindowProc function, where it is disposed of by PM.            */
  133. /*                                                                      */
  134. /************************************************************************/
  135.  
  136. MRESULT EXPENTRY WndProc(hWnd, message, mp1, mp2)
  137. HWND hWnd;
  138. USHORT message;
  139. MPARAM mp1;
  140. MPARAM mp2;
  141. {                            // Beginning of message processor
  142.    HPS hPS;                  // Handle for the Presentation Space
  143.    RECTL rClient;            // Handle to rectangle formed by client area
  144.    USHORT rc;                // common return code value
  145.  
  146.    switch(message)
  147.      {
  148.       case WM_COMMAND:
  149.         // The PM messages for action bar and pulldown menu items are
  150.         // processed in this routine.
  151.   
  152.            switch(SHORT1FROMMP(mp1))
  153.             {
  154.              case IDM_FILE_OPENINIFILE:
  155.                   // Place User Code to respond to the             
  156.                   // Menu Item Named "~Open .INI file..." here.
  157.                   rc = WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)OPENINIMsgProc,
  158.                                  NULL, IDLG_OPENINI, NULL);
  159.                   break;
  160.  
  161.              case IDM_FILE_EXTRACTFROMSYSTEM:
  162.                   // Place User Code to respond to the             
  163.                   // Menu Item Named "~Extract from system..." here.
  164.                   /* Extract Function Goes Here */
  165.                   hiniSource = HINI_USERPROFILE ;
  166.                   hiniTarget = hiniUser ;
  167.                   WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)DSPLGRPSMsgProc, 
  168.                             NULL, IDLG_DSPLGRPS, NULL) ;
  169.                   break;
  170.  
  171.              case IDM_FILE_RELOADTOSYSTEM:
  172.                   // Place User Code to respond to the             
  173.                   // Menu Item Named "~Reload to System..." here.
  174.                   /*  Reload goes here  */
  175.                   hiniSource = hiniUser;
  176.                   hiniTarget = HINI_USERPROFILE;
  177.                   WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)DSPLGRPSMsgProc, 
  178.                             NULL, IDLG_DSPLGRPS, NULL) ;
  179.                   break;
  180.  
  181.              case IDM_FILE_BACKUPSYSTEMINIS:
  182.                   // Place User Code to respond to the             
  183.                   // Menu Item Named "~Backup system INIs..." here.
  184.                   rc = WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)BKSYSINIMsgProc,
  185.                                  NULL, IDLG_BKSYSINI, NULL);
  186.                   break;
  187.  
  188.              case IDM_FILE_EXIT:
  189.                   // Place User Code to respond to the             
  190.                   // Menu Item Named "E~xit" here.
  191.                   /*  Exit Code Goes Here */
  192.                   WinPostMsg(hWnd, WM_CLOSE, 0L, 0L);
  193.                   break;
  194.  
  195.  
  196.              default:
  197.                   break; // End of default case for switch(mp1)
  198.             }
  199.            break;        // End of WM_COMMAND
  200.    
  201.       case WM_CREATE:
  202.            // The WM_CREATE message is sent to a window when an application
  203.            // requests that the window be created.  The window procedure for
  204.            // the new window receives this message after the window is
  205.            // created, but before the window becomes visible.
  206.            //
  207.  
  208.            /*   Allocate Memory for Data Operations          */
  209.  
  210.            if( !DosAllocSeg( WORKAREASIZE,
  211.                              (PSEL)&SELECTOROF( pvoidWorkAreaOrigin ),
  212.                              SEG_NONSHARED))
  213.                OFFSETOF( pvoidWorkAreaOrigin ) = 0;
  214.            pvoidWorkArea  = pvoidWorkAreaOrigin ;
  215.            ulWorkAreaSize = WORKAREASIZE ;
  216.            hiniUser       = NULL ;
  217.            szUserIni[0]   = '\0' ;
  218.  
  219.            break;       // End of WM_CREATE
  220.  
  221.       case WM_MOUSEMOVE:
  222.            return(WinDefWindowProc(hWnd, message, mp1, mp2));
  223.            break;
  224.  
  225.       case WM_SIZE:     // code for sizing client area                     
  226.            break;       // End of WM_SIZE 
  227.     
  228.       case WM_PAINT:    // code for the window's client area
  229.            // Obtain a handle to a cache presentation space
  230.            hPS = WinBeginPaint(hWnd, NULL, NULL);
  231.  
  232.            // Determine the size of the client area
  233.            WinQueryWindowRect(hWnd, &rClient);
  234.  
  235.            // Fill the background with the default background color
  236.            WinFillRect(hPS, &rClient, CLR_BACKGROUND);
  237.  
  238.            // return presentation space to state before WinBeginPaint
  239.            WinEndPaint(hPS);
  240.            break;       // End of WM_PAINT
  241.  
  242.  
  243.       case WM_CLOSE:  // close the window
  244.            if(hWnd != hWndClient)
  245.              break;
  246.            if( hiniUser ) PrfCloseProfile( hiniUser ) ;
  247.            DosFreeSeg( SELECTOROF( pvoidWorkAreaOrigin ) );
  248.            WinPostMsg(hWnd, WM_QUIT, 0L, 0L);
  249.            break;       // End of WM_CLOSE
  250.      
  251.       default:
  252.            // For any message for which you don't specifically provide a
  253.            // service routine, you should return the message to PM using
  254.            // the WinDefWindowProc function.
  255.            return(WinDefWindowProc(hWnd, message, mp1, mp2));
  256.            break;  // End of default 
  257.      } 
  258.    return(0L);
  259. } // End of WndProc
  260.  
  261. /************************************************************************/
  262. /*                                                                      */
  263. /* Dialog Window Procedure                                              */
  264. /*                                                                      */
  265. /* This procedure is associated with the dialog box that is included in */
  266. /* the function name of the procedure. It provides the service routines */
  267. /* for the events (messages) that occur because the end user operates   */
  268. /* one of the dialog box's buttons, entry fields, or controls.          */
  269. /*                                                                      */
  270. /* The SWITCH statement in the function distributes the dialog box      */
  271. /* messages to the respective service routines, which are set apart by  */
  272. /* the CASE clauses. Like any other PM window, the Dialog Window        */
  273. /* procedures must provide an appropriate service routine for their end */
  274. /* user initiated messages as well as for the general PM messages (like */
  275. /* the WM_CLOSE message). If a message is sent to this procedure for    */
  276. /* which there is no programmed CASE condition (no service routine),    */
  277. /* the message is defaulted to the WinDefDlgProc function, where it is  */
  278. /* disposed of by PM.                                                   */
  279. /*                                                                      */
  280. /************************************************************************/
  281.  
  282. MRESULT EXPENTRY DSPLGRPSMsgProc(hWndDlg, message, mp1, mp2)
  283. HWND hWndDlg;
  284. USHORT message;
  285. MPARAM mp1;
  286. MPARAM mp2;
  287.  SHORT i;
  288.           
  289.  BOOL           fSuccess ;
  290.  ULONG          ulBufferMax ;
  291.  USHORT         ulNumPgmEnts, ulPgmEntCtr, sSelect ;
  292.           
  293.  switch(message)
  294.    {
  295.     case WM_INITDLG:
  296.  
  297.          WinSendDlgItemMsg (hWndDlg, DsplGrps_GrpList,
  298.                             LM_DELETEALL, NULL, NULL) ;
  299.  
  300.          ulBufferMax = ulWorkAreaSize ;
  301.          if( !hiniSource )
  302.              {
  303.              if( !WinDlgBox(HWND_DESKTOP, hWndDlg,
  304.                            (PFNWP)OPENINIMsgProc,
  305.                            NULL, IDLG_OPENINI, NULL) )
  306.                  {
  307.                  WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL),0L);
  308.                  break ;
  309.                  }
  310.              hiniSource = hiniUser ;
  311.              }
  312.          fSuccess = PrfQueryProfileData( hiniSource,
  313.                                          "PM_ProgramList000", "ProgramEntry",
  314.                                          pvoidWorkArea,
  315.                                          &ulBufferMax ) ;         
  316.          PgmEntPtr = PgmEntPtrSel = (PROGRAMENTRY *)pvoidWorkArea ;
  317.          ulPgmEntSize             = ulBufferMax +1 ;
  318.          (PBYTE)PgmEntPtrEnd      = (PBYTE)pvoidWorkArea + ulPgmEntSize ;
  319.          (PBYTE)pvoidWorkArea     = (PBYTE)PgmEntPtrEnd +1 ;
  320.          ulWorkAreaSize          -= ulPgmEntSize+1 ;
  321.          for( ulNumPgmEnts = ulBufferMax/sizeof(PROGRAMENTRY),
  322.                  ulPgmEntCtr  = 0 ;
  323.               ulPgmEntCtr < ulNumPgmEnts ;
  324.               ulPgmEntCtr++, PgmEntPtrSel++ )
  325.               {
  326.               WinSendDlgItemMsg(hWndDlg, DsplGrps_GrpList, LM_INSERTITEM,
  327.                                 MPFROM2SHORT (LIT_SORTASCENDING, 0),
  328.                                 MPFROMP (PgmEntPtrSel->szTitle)) ;
  329.               }
  330.          *(PCHAR)pvoidWorkArea = '\0' ; 
  331.  
  332.          break; // End of WM_INITDLG
  333.                            
  334.     case WM_CONTROL:
  335.          switch(SHORT1FROMMP(mp1))
  336.            {
  337.             case DsplGrps_GrpList: // List box
  338.                  sSelect = (USHORT) WinSendDlgItemMsg (hWndDlg,
  339.                                                 DsplGrps_GrpList,
  340.                                                 LM_QUERYSELECTION, 0L, 0L) ;
  341.                  WinSendDlgItemMsg(hWndDlg, DsplGrps_GrpList,
  342.                                    LM_QUERYITEMTEXT,
  343.                                    MPFROM2SHORT(sSelect, ulWorkAreaSize),
  344.                                    MPFROMP(pvoidWorkArea)) ;
  345.                  if( SHORT2FROMMP( mp1 ) == LN_ENTER )
  346.                      WinPostMsg(hWndDlg, WM_COMMAND,
  347.                                 MPFROM2SHORT(DID_OK,0), 0L);
  348.                  break;
  349.  
  350.            }
  351.          break; // End of WM_CONTROL
  352.    
  353.     case WM_COMMAND:
  354.          switch(SHORT1FROMMP(mp1))
  355.            {
  356.             case DID_OK:
  357.                  if( !strlen( (PSZ)pvoidWorkArea ) ) break ;
  358.                  for( PgmEntPtrSel = PgmEntPtr ;
  359.                       strcmp((PSZ)pvoidWorkArea, PgmEntPtrSel->szTitle) ;
  360.                       PgmEntPtrSel++ ) ;
  361.                  WinDlgBox(HWND_DESKTOP, hWndDlg, (PFNWP)SAVEPGMSMsgProc, 
  362.                            NULL, IDLG_SAVEPGMS, NULL);
  363.                  *(PCHAR)pvoidWorkArea = '\0' ; 
  364.                  break ;
  365.  
  366.                  WinDismissDlg(hWndDlg, TRUE);
  367.                  break;
  368.  
  369.             case DID_CANCEL:
  370.                  // Ignore data values entered into the dialog controls
  371.                  // and dismiss the dialog window
  372.                  WinDismissDlg(hWndDlg, FALSE);
  373.                  break;
  374.            }
  375.          break; // End of WM_COMMAND
  376.                                
  377.     case WM_CLOSE:
  378.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  379.          break; // End of WM_CLOSE 
  380.            
  381.     default:
  382.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  383.          break;
  384.    }
  385.  return FALSE;
  386. } /* End of DSPLGRPSMsgProc */
  387.  
  388.  
  389. /************************************************************************/
  390. /*                                                                      */
  391. /* Dialog Window Procedure                                              */
  392. /*                                                                      */
  393. /* This procedure is associated with the dialog box that is included in */
  394. /* the function name of the procedure. It provides the service routines */
  395. /* for the events (messages) that occur because the end user operates   */
  396. /* one of the dialog box's buttons, entry fields, or controls.          */
  397. /*                                                                      */
  398. /* The SWITCH statement in the function distributes the dialog box      */
  399. /* messages to the respective service routines, which are set apart by  */
  400. /* the CASE clauses. Like any other PM window, the Dialog Window        */
  401. /* procedures must provide an appropriate service routine for their end */
  402. /* user initiated messages as well as for the general PM messages (like */
  403. /* the WM_CLOSE message). If a message is sent to this procedure for    */
  404. /* which there is no programmed CASE condition (no service routine),    */
  405. /* the message is defaulted to the WinDefDlgProc function, where it is  */
  406. /* disposed of by PM.                                                   */
  407. /*                                                                      */
  408. /************************************************************************/
  409.  
  410. MRESULT EXPENTRY SAVEPGMSMsgProc(hWndDlg, message, mp1, mp2)
  411. HWND hWndDlg;
  412. USHORT message;
  413. MPARAM mp1;
  414. MPARAM mp2;
  415.  SHORT i;
  416.           
  417.  HPROGRAM   hprogUserGrp ;
  418.  ULONG      cchBufferMax, ulCount, ulWork, ulGrpKeyLen,
  419.             ulKeyDataSize, ulDetailsLen ;
  420.  PVOID      pvoidKeyData ;
  421.  PSZ        pszKeyName ;
  422.  USHORT     sSelect ;
  423.           
  424.  switch(message)
  425.    {
  426.     case WM_INITDLG:
  427.  
  428.          WinSendDlgItemMsg (hWndDlg, SavePgms_Titles,
  429.                             LM_DELETEALL, NULL, NULL) ;
  430.          WinSendDlgItemMsg(hWndDlg, SavePgms_GrpName, EM_SETTEXTLIMIT,
  431.                            MPFROM2SHORT (80, 0), NULL) ;
  432.          WinSendDlgItemMsg(hWndDlg, SavePgms_Txt1, EM_SETTEXTLIMIT,
  433.                            MPFROM2SHORT (80, 0), NULL) ;
  434.          WinSetDlgItemText (hWndDlg, SavePgms_GrpName, PgmEntPtrSel->szTitle) ;
  435.          if( hiniSource == HINI_USERPROFILE )
  436.              WinSetDlgItemText (hWndDlg, SavePgms_Txt1,
  437.                                 "Select Installed Programs(s) to Save") ;
  438.              else
  439.              WinSetDlgItemText (hWndDlg, SavePgms_Txt1,
  440.                                 "Select Installed Programs(s) to Restore") ;
  441.          pTitles      = (PPROGTITLE)pvoidWorkArea ;
  442.          ulTitlesSize = PrfQueryProgramTitles( hiniSource,
  443.                                                PgmEntPtrSel->hprog,
  444.                                                pTitles,
  445.                                                ulWorkAreaSize,
  446.                                                &ulCount ) ;
  447.          (PBYTE)pTitlesEnd = (PBYTE)pTitles + ulTitlesSize ;
  448.          for( ulWork  = 0 ; ulWork < ulCount ; ulWork++, pTitles++ )
  449.               {
  450.               WinSendDlgItemMsg(hWndDlg, SavePgms_Titles, LM_INSERTITEM,
  451.                                 MPFROM2SHORT (LIT_END, 0),
  452.                                 MPFROMP (pTitles->pszTitle)) ;
  453.               } 
  454.          pTitles              = (PPROGTITLE)pvoidWorkArea ;
  455.          (PBYTE)pvoidWorkArea = (PBYTE)pTitlesEnd + 1 ;
  456.          ulWorkAreaSize      -= ulTitlesSize + 1 ; 
  457.          
  458.          break; // End of WM_INITDLG
  459.                            
  460.     case WM_CONTROL:
  461.          switch(SHORT1FROMMP(mp1))
  462.            {
  463.             case SavePgms_Titles: // List box
  464.                  {
  465.                  }
  466.                  break;
  467.  
  468.            }
  469.          break; // End of WM_CONTROL
  470.    
  471.     case WM_COMMAND:
  472.          switch(SHORT1FROMMP(mp1))
  473.            {
  474.             case DID_OK:
  475.                  sSelect = (USHORT)WinSendDlgItemMsg(hWndDlg,
  476.                                         SavePgms_Titles,
  477.                                         LM_QUERYSELECTION,
  478.                                         MPFROMSHORT(LIT_FIRST),
  479.                                         0L ) ;
  480.                  if( sSelect == LIT_NONE ) break ;
  481.                  if( !hiniTarget )
  482.                      {
  483.                      if( !WinDlgBox(HWND_DESKTOP, hWndDlg,
  484.                                     (PFNWP)OPENINIMsgProc,
  485.                                     NULL, IDLG_OPENINI, NULL) ) break ;
  486.                      hiniTarget = hiniUser ;
  487.                      }
  488.                  hprogUserGrp = PrfCreateGroup( hiniTarget,
  489.                                                 PgmEntPtrSel->szTitle,
  490.                                                 SHE_VISIBLE ) ;
  491.                  ulGrpKeyLen  = ulWorkAreaSize ;
  492.                  if( PrfQueryProfileData( hiniSource,
  493.                                           PgmEntPtrSel->szTitle,
  494.                                           NULL,
  495.                                           pvoidWorkArea,
  496.                                           &ulGrpKeyLen )  )
  497.                       {
  498.                       (PBYTE)pvoidKeyData = (PBYTE)pvoidWorkArea + 
  499.                                             ulGrpKeyLen + 1 ;
  500.                       for( pszKeyName = (PSZ)pvoidWorkArea;
  501.                            strlen(pszKeyName) ;
  502.                            pszKeyName += strlen(pszKeyName)+1 )
  503.                            {
  504.                            ulKeyDataSize       = ulWorkAreaSize -
  505.                                                  (ulGrpKeyLen + 1) ;
  506.                            PrfQueryProfileData( hiniSource,
  507.                                                 PgmEntPtrSel->szTitle,
  508.                                                 pszKeyName,
  509.                                                 pvoidKeyData,
  510.                                                 &ulKeyDataSize ) ;
  511.                            PrfWriteProfileData( hiniTarget,
  512.                                                 PgmEntPtrSel->szTitle,
  513.                                                 pszKeyName,
  514.                                                 pvoidKeyData,
  515.                                                 ulKeyDataSize ) ;
  516.                            }
  517.                       }
  518.                  for( sSelect = (USHORT)WinSendDlgItemMsg(hWndDlg,
  519.                                         SavePgms_Titles,
  520.                                         LM_QUERYSELECTION,
  521.                                         MPFROMSHORT(LIT_FIRST),
  522.                                         0L ) ;
  523.                       sSelect != LIT_NONE;
  524.                       sSelect = (USHORT)WinSendDlgItemMsg(hWndDlg,
  525.                                         SavePgms_Titles,
  526.                                         LM_QUERYSELECTION,
  527.                                         MPFROMSHORT(sSelect),
  528.                                         0L ) )
  529.                       {
  530.                       ulDetailsLen = PrfQueryDefinition( hiniSource,
  531.                                         (pTitles+sSelect)->hprog,
  532.                                         (PPROGDETAILS)pvoidWorkArea,
  533.                                         ulWorkAreaSize ) ;
  534.                       PrfAddProgram( hiniTarget, (PPROGDETAILS)pvoidWorkArea,
  535.                                         hprogUserGrp ) ;
  536.                       }
  537.                       
  538.                  WinDismissDlg(hWndDlg, TRUE);
  539.                  break;
  540.  
  541.             case DID_CANCEL:
  542.                  // Ignore data values entered into the dialog controls
  543.                  // and dismiss the dialog window
  544.                  WinDismissDlg(hWndDlg, FALSE);
  545.                  break;
  546.            }
  547.          break; // End of WM_COMMAND
  548.                                
  549.     case WM_CLOSE:
  550.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  551.          break; // End of WM_CLOSE 
  552.            
  553.     default:
  554.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  555.          break;
  556.    }
  557.  return FALSE;
  558. } /* End of SAVEPGMSMsgProc */
  559.  
  560.  
  561. /************************************************************************/
  562. /*                                                                      */
  563. /* Dialog Window Procedure                                              */
  564. /*                                                                      */
  565. /* This procedure is associated with the dialog box that is included in */
  566. /* the function name of the procedure. It provides the service routines */
  567. /* for the events (messages) that occur because the end user operates   */
  568. /* one of the dialog box's buttons, entry fields, or controls.          */
  569. /*                                                                      */
  570. /* The SWITCH statement in the function distributes the dialog box      */
  571. /* messages to the respective service routines, which are set apart by  */
  572. /* the CASE clauses. Like any other PM window, the Dialog Window        */
  573. /* procedures must provide an appropriate service routine for their end */
  574. /* user initiated messages as well as for the general PM messages (like */
  575. /* the WM_CLOSE message). If a message is sent to this procedure for    */
  576. /* which there is no programmed CASE condition (no service routine),    */
  577. /* the message is defaulted to the WinDefDlgProc function, where it is  */
  578. /* disposed of by PM.                                                   */
  579. /*                                                                      */
  580. /************************************************************************/
  581.  
  582. MRESULT EXPENTRY OPENINIMsgProc(hWndDlg, message, mp1, mp2)
  583. HWND hWndDlg;
  584. USHORT message;
  585. MPARAM mp1;
  586. MPARAM mp2;
  587.  SHORT i;
  588.           
  589.  USHORT sSelect, CurDisk ;
  590.  ULONG  DriveMap ;
  591.  UCHAR  buffer[80] ;
  592.  PSZ    IniMask = "*.ini" ;
  593.           
  594.  switch(message)
  595.    {
  596.     case WM_INITDLG:
  597.          WinSendDlgItemMsg(hWndDlg, OpenIni_CWD, EM_SETTEXTLIMIT,
  598.                            MPFROM2SHORT (80, 0), NULL) ;
  599.          WinSendDlgItemMsg(hWndDlg, OpenIni_IniName, EM_SETTEXTLIMIT,
  600.                            MPFROM2SHORT (8, 0), NULL) ;
  601.          WinSetDlgItemText (hWndDlg, OpenIni_IniName, "") ;
  602.          CurDir2DlgText(  hWndDlg, OpenIni_CWD ) ;
  603.          DrvList2DlgBox(  hWndDlg, OpenIni_DriveList) ;
  604.          DirList2DlgBox(  hWndDlg, OpenIni_DirList) ;
  605.          FileList2DlgBox( hWndDlg, OpenIni_FileList, IniMask) ;
  606.          break; // End of WM_INITDLG
  607.                            
  608.     case WM_CONTROL:
  609.          switch(SHORT1FROMMP(mp1))
  610.            {
  611.             case OpenIni_IniName: // Entry field
  612.                  break;
  613.  
  614.             case OpenIni_DriveList: // List box
  615.  
  616.                  sSelect = (USHORT) WinSendDlgItemMsg (hWndDlg,
  617.                                                 OpenIni_DriveList,
  618.                                                 LM_QUERYSELECTION, 0L, 0L) ;
  619.                  WinSendDlgItemMsg(hWndDlg, OpenIni_DriveList,
  620.                                    LM_QUERYITEMTEXT,
  621.                                    MPFROM2SHORT(sSelect, sizeof buffer),
  622.                                    MPFROMP(buffer)) ;
  623.                  if( SHORT2FROMMP( mp1 ) != LN_ENTER )  break;
  624.                  DosQCurDisk( &CurDisk, &DriveMap );
  625.                  if(DosSelectDisk (buffer [1] - '@')!=0)
  626.                      DosSelectDisk ( CurDisk );
  627.                  WinPostMsg(hWndDlg, WM_INITDLG, 0L, 0L);
  628.  
  629.                  break;
  630.  
  631.             case OpenIni_DirList: // List box
  632.                  sSelect = (USHORT) WinSendDlgItemMsg (hWndDlg,
  633.                                                 OpenIni_DirList,
  634.                                                 LM_QUERYSELECTION, 0L, 0L) ;
  635.                  WinSendDlgItemMsg(hWndDlg, OpenIni_DirList,
  636.                                    LM_QUERYITEMTEXT,
  637.                                    MPFROM2SHORT(sSelect, sizeof buffer),
  638.                                    MPFROMP(buffer)) ;
  639.                  if( SHORT2FROMMP( mp1 ) != LN_ENTER )  break;
  640.                  strcpy(buffer,buffer);
  641.                  for(i=1; i<=strlen(buffer)&&buffer[i]!=']';i++)
  642.                      buffer[i-1]=buffer[i];
  643.                  buffer[i-1]=0x00;
  644.          DosChDir(buffer, 0L) ;
  645.                  WinPostMsg(hWndDlg, WM_INITDLG, 0L, 0L);
  646.                  break;
  647.  
  648.             case OpenIni_FileList: // List box
  649.                  sSelect = (USHORT) WinSendDlgItemMsg (hWndDlg,
  650.                                                 OpenIni_FileList,
  651.                                                 LM_QUERYSELECTION, 0L, 0L) ;
  652.                  if( sSelect == LIT_NONE ) break ;
  653.                  WinSendDlgItemMsg(hWndDlg, OpenIni_FileList,
  654.                                    LM_QUERYITEMTEXT,
  655.                                    MPFROM2SHORT(sSelect, sizeof buffer),
  656.                                    MPFROMP(buffer)) ;
  657.                  for(sSelect = 0; buffer[sSelect] != '.'; sSelect++ ) ;
  658.                  buffer[sSelect] = '\0' ;
  659.                  WinSetDlgItemText (hWndDlg, OpenIni_IniName, buffer) ;
  660.                  if( SHORT2FROMMP( mp1 ) != LN_ENTER )  break;
  661.                  WinPostMsg(hWndDlg, WM_COMMAND, MPFROM2SHORT(DID_OK,0L), 0L);
  662.                  break;
  663.  
  664.            }
  665.          break; // End of WM_CONTROL
  666.    
  667.     case WM_COMMAND:
  668.          switch(SHORT1FROMMP(mp1))
  669.            {
  670.             case DID_OK:
  671.                  if( !WinQueryDlgItemText(hWndDlg,
  672.                                           OpenIni_IniName,
  673.                                           ulWorkAreaSize,
  674.                                           pvoidWorkArea ) ) break ;
  675.                  if( hiniUser ) PrfCloseProfile( hiniUser ) ;
  676.                  WinQueryDlgItemText(hWndDlg, OpenIni_CWD,
  677.                                      sizeof(szUserIni), szUserIni ) ;
  678.                  strcat( szUserIni, (PSZ)pvoidWorkArea ) ;
  679.                  strcat( szUserIni, ".INI" ) ;
  680.                  hiniUser = PrfOpenProfile( hAB, szUserIni ) ;
  681.                  WinDismissDlg(hWndDlg, TRUE);
  682.                  break;
  683.  
  684.             case DID_CANCEL:
  685.                  // Ignore data values entered into the dialog controls
  686.                  // and dismiss the dialog window
  687.                  WinDismissDlg(hWndDlg, FALSE);
  688.                  break;
  689.            }
  690.          break; // End of WM_COMMAND
  691.                                
  692.     case WM_CLOSE:
  693.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  694.          break; // End of WM_CLOSE 
  695.            
  696.     default:
  697.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  698.          break;
  699.    }
  700.  return FALSE;
  701. } /* End of OPENINIMsgProc */
  702.  
  703.  
  704. /************************************************************************/
  705. /*                                                                      */
  706. /* Dialog Window Procedure                                              */
  707. /*                                                                      */
  708. /* This procedure is associated with the dialog box that is included in */
  709. /* the function name of the procedure. It provides the service routines */
  710. /* for the events (messages) that occur because the end user operates   */
  711. /* one of the dialog box's buttons, entry fields, or controls.          */
  712. /*                                                                      */
  713. /* The SWITCH statement in the function distributes the dialog box      */
  714. /* messages to the respective service routines, which are set apart by  */
  715. /* the CASE clauses. Like any other PM window, the Dialog Window        */
  716. /* procedures must provide an appropriate service routine for their end */
  717. /* user initiated messages as well as for the general PM messages (like */
  718. /* the WM_CLOSE message). If a message is sent to this procedure for    */
  719. /* which there is no programmed CASE condition (no service routine),    */
  720. /* the message is defaulted to the WinDefDlgProc function, where it is  */
  721. /* disposed of by PM.                                                   */
  722. /*                                                                      */
  723. /************************************************************************/
  724.  
  725. MRESULT EXPENTRY BKSYSINIMsgProc(hWndDlg, message, mp1, mp2)
  726. HWND hWndDlg;
  727. USHORT message;
  728. MPARAM mp1;
  729. MPARAM mp2;
  730.  SHORT i;
  731.           
  732.  VOID APIENTRY Backup_Ini() ;
  733.  USHORT sSelect, CurDisk ;
  734.  ULONG  DriveMap ;
  735.  UCHAR  buffer[MAXNAMEL+1] ;
  736.  
  737.  #define SEGSIZE 4096
  738.  #define ALLOCFLAGS 0
  739.  TID     ThreadId ;
  740.  SEL     ThreadStackSel ;
  741.  PBYTE   StackEnd ;
  742.  
  743.  switch(message)
  744.    {
  745.     case WM_INITDLG:
  746.          CurDir2DlgText(  hWndDlg, Bksysini_CWD ) ;
  747.          DrvList2DlgBox(  hWndDlg, Bksysini_DriveList) ;
  748.          DirList2DlgBox(  hWndDlg, Bksysini_DirList) ;
  749.          break; // End of WM_INITDLG
  750.                            
  751.     case WM_CONTROL:
  752.          switch(SHORT1FROMMP(mp1))
  753.            {
  754.             case Bksysini_DriveList: // List box
  755.                  sSelect = (USHORT) WinSendDlgItemMsg (hWndDlg,
  756.                                                 Bksysini_DriveList,
  757.                                                 LM_QUERYSELECTION, 0L, 0L) ;
  758.                  WinSendDlgItemMsg(hWndDlg, Bksysini_DriveList,
  759.                                    LM_QUERYITEMTEXT,
  760.                                    MPFROM2SHORT(sSelect, sizeof buffer),
  761.                                    MPFROMP(buffer)) ;
  762.                  if( SHORT2FROMMP( mp1 ) != LN_ENTER )  break;
  763.                  DosQCurDisk( &CurDisk, &DriveMap );
  764.                  if(DosSelectDisk (buffer [1] - '@')!=0)
  765.                      DosSelectDisk ( CurDisk );
  766.                  WinPostMsg(hWndDlg, WM_INITDLG, 0L, 0L);
  767.                  break;
  768.  
  769.             case Bksysini_DirList: // List box
  770.                  sSelect = (USHORT) WinSendDlgItemMsg (hWndDlg,
  771.                                                 Bksysini_DirList,
  772.                                                 LM_QUERYSELECTION, 0L, 0L) ;
  773.                  WinSendDlgItemMsg(hWndDlg, Bksysini_DirList,
  774.                                    LM_QUERYITEMTEXT,
  775.                                    MPFROM2SHORT(sSelect, sizeof buffer),
  776.                                    MPFROMP(buffer)) ;
  777.                  if( SHORT2FROMMP( mp1 ) != LN_ENTER )  break;
  778.                  strcpy(buffer,buffer);
  779.                  for(i=1; i<=strlen(buffer)&&buffer[i]!=']';i++)
  780.                      buffer[i-1]=buffer[i];
  781.                  buffer[i-1]=0x00;
  782.          DosChDir(buffer, 0L) ;
  783.                  WinPostMsg(hWndDlg, WM_INITDLG, 0L, 0L);
  784.                  break;
  785.  
  786.            }
  787.          break; // End of WM_CONTROL
  788.    
  789.     case WM_COMMAND:
  790.          switch(SHORT1FROMMP(mp1))
  791.            {
  792.             case DID_OK:
  793.                  WinQueryDlgItemText(hWndDlg, Bksysini_CWD,
  794.                                      WORKAREASIZE, pvoidWorkArea ) ;
  795.                  DosAllocSeg( SEGSIZE, &ThreadStackSel, ALLOCFLAGS ) ;
  796.                  StackEnd = MAKEP(ThreadStackSel, SEGSIZE-1) ;
  797.                  DosCreateThread((PFNTHREAD)Backup_Ini, &ThreadId, StackEnd);
  798.                  WinDlgBox(HWND_DESKTOP, hWndDlg, (PFNWP)BKUPRUNMsgProc, 
  799.                            NULL, IDLG_BKUPRUN, NULL);
  800.                  DosFreeSeg( ThreadStackSel );
  801.                  WinDismissDlg(hWndDlg, TRUE);
  802.                  break;
  803.  
  804.             case DID_CANCEL:
  805.                  // Ignore data values entered into the dialog controls
  806.                  // and dismiss the dialog window
  807.                  WinDismissDlg(hWndDlg, FALSE);
  808.                  break;
  809.            }
  810.          break; // End of WM_COMMAND
  811.                                
  812.     case WM_CLOSE:
  813.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  814.          break; // End of WM_CLOSE 
  815.            
  816.     default:
  817.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  818.          break;
  819.    }
  820.  return FALSE;
  821. } /* End of BKSYSINIMsgProc */
  822.  
  823.  
  824. /************************************************************************/
  825. /*                                                                      */
  826. /* Dialog Window Procedure                                              */
  827. /*                                                                      */
  828. /* This procedure is associated with the dialog box that is included in */
  829. /* the function name of the procedure. It provides the service routines */
  830. /* for the events (messages) that occur because the end user operates   */
  831. /* one of the dialog box's buttons, entry fields, or controls.          */
  832. /*                                                                      */
  833. /* The SWITCH statement in the function distributes the dialog box      */
  834. /* messages to the respective service routines, which are set apart by  */
  835. /* the CASE clauses. Like any other PM window, the Dialog Window        */
  836. /* procedures must provide an appropriate service routine for their end */
  837. /* user initiated messages as well as for the general PM messages (like */
  838. /* the WM_CLOSE message). If a message is sent to this procedure for    */
  839. /* which there is no programmed CASE condition (no service routine),    */
  840. /* the message is defaulted to the WinDefDlgProc function, where it is  */
  841. /* disposed of by PM.                                                   */
  842. /*                                                                      */
  843. /************************************************************************/
  844.  
  845. MRESULT EXPENTRY BKUPRUNMsgProc(hWndDlg, message, mp1, mp2)
  846. HWND hWndDlg;
  847. USHORT message;
  848. MPARAM mp1;
  849. MPARAM mp2;
  850.  SHORT i;
  851.           
  852.  #define SLEEPSHORT 5L
  853.  
  854.  switch(message)
  855.    {
  856.     case WM_INITDLG:
  857.          hwndThreadWaiter = hWndDlg ;
  858.          break; // End of WM_INITDLG
  859.                            
  860.     case WM_CONTROL:
  861.          switch(SHORT1FROMMP(mp1))
  862.            {
  863.            }
  864.          break; // End of WM_CONTROL
  865.    
  866.     case WM_COMMAND:
  867.          switch(SHORT1FROMMP(mp1))
  868.            {
  869.             case DID_OK:
  870.                  WinDismissDlg(hWndDlg, TRUE);
  871.                  break;
  872.  
  873.             case DID_CANCEL:
  874.                  // Ignore data values entered into the dialog controls
  875.                  // and dismiss the dialog window
  876.                  WinDismissDlg(hWndDlg, FALSE);
  877.                  break;
  878.             case THREAD_GONE:
  879.                  DosSleep( SLEEPSHORT ) ;
  880.                  WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  881.                  break ;
  882.            }
  883.          break; // End of WM_COMMAND
  884.                                
  885.     case WM_CLOSE:
  886.          WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
  887.          break; // End of WM_CLOSE 
  888.            
  889.     default:
  890.          return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
  891.          break;
  892.    }
  893.  return FALSE;
  894. } /* End of BKUPRUNMsgProc */
  895.  
  896.  
  897.  
  898.  
  899. /************************************************************************/
  900. /*                                                                      */
  901. /* RegisterClass Function                                               */
  902. /*                                                                      */
  903. /* The following function registers all the classes of all the windows  */
  904. /* associated with this application. The function returns TRUE if it is */
  905. /* successful, otherwise it returns FALSE.                              */
  906. /*                                                                      */
  907. /************************************************************************/
  908.  
  909. INT RegisterClass()
  910. {
  911.  INT rc;
  912.  
  913.  strcpy(szAppName, "INIPGMS");
  914.  rc = WinRegisterClass(hAB,             // Anchor block handle            
  915.                       (PCH)szAppName,   // Name of class being registered 
  916.                       (PFNWP)WndProc,   // Window procedure for class     
  917.                       CS_SIZEREDRAW , 
  918.                       NULL);            // Extra bytes to reserve         
  919.  if (rc == FALSE)
  920.    return(FALSE);
  921.  
  922.  return(TRUE);
  923. } // End of RegisterClass
  924.  
  925.  
  926.  
  927. /************************************************************************/
  928. /*                                                                      */
  929. /* CreateWindow Function                                                */
  930. /*                                                                      */
  931. /* The following function is used to create a window (the main window,  */
  932. /* a child window, an icon window, etc.) and set it's initial size and  */
  933. /* position. It returns the handle to the frame window.                 */
  934. /*                                                                      */
  935. /************************************************************************/
  936.  
  937. HWND CreateWindow(
  938.    HWND   hWndParent,  // Handle to the parent of the window to be created
  939.    ULONG  ctldata,     // Frame control flags for the window
  940.    PCH    appname,     // Class name of the window
  941.    PCH    title,       // Title of the window
  942.    USHORT ResID,       // Resource id value
  943.    INT    x,           // Initial horizontal and vertical location of origin
  944.    INT    y,
  945.    INT    cx,          // Initial width and height of the window
  946.    INT    cy, 
  947.    PHWND  hWndClient,  // Handle to the client area of the window
  948.    ULONG  lfStyle,     // Frame window style
  949.    USHORT uSizeStyle)  // User defined size and location flags
  950. {
  951.    USHORT rc;            // accepts return codes from function calls
  952.    HWND   hWndFrame;     // local handle to created window frame
  953.    USHORT SizeStyle;     // local window positioning options
  954.    CHAR   MsgBuffer[80]; // buffer for error messages
  955.       
  956.    // Create the frame window
  957.    hWndFrame = WinCreateStdWindow(hWndParent,  // parent of window
  958.                                   lfStyle,     // frame window style
  959.                                   &ctldata,    // frame flags
  960.                                   appname,     // class name
  961.                                   title,       // window title
  962.                                   0L,          // client window style
  963.                                   NULL,        // module for resources
  964.                                   ResID,       // resource id
  965.                                   (HWND FAR *)hWndClient); // client handle
  966.  
  967.    // if hWndFrame is NULL, an error occured when opening the window, notify
  968.    //     the user and exit this function
  969.    if(hWndFrame == NULL)
  970.      {
  971.       WinLoadString(hAB, NULL, IDS_ERR_WINDOW_CREATE, 80, MsgBuffer);
  972.       WinMessageBox(HWND_DESKTOP, hWndParent, MsgBuffer,
  973.                     NULL, NULL, MB_OK|MB_ICONEXCLAMATION);
  974.       return((HWND)NULL);
  975.      }
  976.  
  977.    // set up size options
  978.    SizeStyle = SWP_ACTIVATE | SWP_ZORDER | uSizeStyle;
  979.  
  980.    // if the either the intial x or y position of the window is non-zero,
  981.    //    set the window to its new position
  982.    if((x > 0) || (y > 0))
  983.      SizeStyle |= SWP_MOVE;
  984.    // if either the width or the height are non-zero, then the size of the
  985.    //     created window will be changed, set SizeStyle accordingly
  986.    if((cx > 0) || (cy > 0))
  987.      SizeStyle |= SWP_SIZE;
  988.    // set the size and position of the window and activate it
  989.    rc = WinSetWindowPos(hWndFrame, HWND_TOP, x, y, cx, cy, SizeStyle);
  990.    
  991.    // if rc is not set to TRUE then WinSetWindowPos failed, notify the user
  992.    //     and exit this function
  993.    if(!rc)
  994.      {
  995.       WinLoadString(hAB, NULL, IDS_ERR_WINDOW_POS, 80, MsgBuffer);
  996.       WinMessageBox(HWND_DESKTOP, hWndParent, MsgBuffer,
  997.                     NULL, NULL, MB_OK|MB_ICONEXCLAMATION);
  998.       return((HWND)NULL);
  999.      }
  1000.  
  1001.    // return the handle to the frame window
  1002.    return(hWndFrame);
  1003. }  // End of CreateWindow
  1004.  
  1005.  
  1006.  
  1007.