home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / games / gi / giconfig.cpp < prev    next >
C/C++ Source or Header  |  1993-11-08  |  6KB  |  200 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*   Module        : Game-Interface Configuration                           */
  4. /*                                                                          */
  5. /*   Version       : V1.00                                                  */
  6. /*                                                                          */
  7. /*   Date          : 18.04.93                                               */
  8. /*                                                                          */
  9. /*   Written       : RF                                                     */
  10. /*                                                                          */
  11. /*     Revision History :
  12.  
  13.     13.06.93    RF  Wenn InitFip Fehler gibt, wird Msg-Box angezeigt
  14.     20.06.93    RF  Insert vor das Selektierte Item, falls eines selektiert,
  15.                     sonst am Ende.
  16.     05.11.93    RF    FileDlg etwas intelligenter...
  17.                                                                             */
  18. /*--------------------------------------------------------------------------*/
  19. #define INCL_PM
  20. #include <os2.h>
  21. #pragma hdrstop
  22.  
  23. #include <dir.h>
  24. #include <mem.h>
  25. #include <string.h>
  26. #include <gi.h>
  27. #include <listbox.hpp>
  28. #include <pmthread.hpp>
  29. #include <stdlib.h>
  30.  
  31. PMWINTHREAD msgloop;
  32. LISTBOX     lb;
  33. FILEDLG     filedlg;
  34. BOOL        ignore=FALSE;
  35. BOOL        inconfig=FALSE;
  36.  
  37. extern "C"    {
  38. extern unsigned     InitFip     (FUNCINFOP);
  39. extern void         DelFip      (unsigned);
  40. extern unsigned        Save        ();
  41. }
  42.  
  43. /*--------------------------------------------------------------------------*/
  44. int GetName ()
  45.     {
  46.     HWND        hwnddlg;
  47.     FUNCINFOP   fi;
  48.     char        drive[MAXDRIVE], dir[MAXDIR];
  49.  
  50.     fnsplit (filedlg.szFullFile, drive, dir, 0, 0);
  51.     fnmerge (filedlg.szFullFile, drive, dir, "*", ".DLL");
  52.  
  53. retry:
  54.     hwnddlg = WinFileDlg (HWND_DESKTOP, HWND_DESKTOP, &filedlg);
  55.     if (hwnddlg && filedlg.lReturn == DID_OK)
  56.         {
  57.         fi = fip[numplayer] = (FUNCINFOP)malloc (sizeof (FUNCINFO));
  58.         if (!fi)
  59.             {
  60.             error = ENOMEM;
  61.             return (-1);
  62.             }
  63.         strcpy (fi->file, filedlg.szFullFile);
  64.         fi->data = NULL;
  65.         if (InitFip (fi))
  66.             {
  67.             WinMessageBox (HWND_DESKTOP, HWND_DESKTOP, ErrorShow (error), NULL, 0,
  68.                             MB_OK | MB_ICONHAND | MB_APPLMODAL);
  69.             goto retry;
  70.             }
  71.         return (numplayer++);
  72.         }
  73.     else
  74.         return (-1);
  75.     }
  76. /*--------------------------------------------------------------------------*/
  77. void Reorder (int sel)
  78.     {
  79.     int         i;
  80.  
  81.     for (i=numplayer; i>sel; i--)
  82.         fip[i] = fip[i-1];
  83.     fip[sel] = fip[numplayer];
  84.  
  85.     lb.DeleteAll ();
  86.     for (i=0; i<numplayer; i++)
  87.         {
  88.         fip[i]->name[0] = '1'+i;
  89.         fip[i]->name[1] = ' ';
  90.         lb.InsertEnd (0, fip[i]->name);
  91.         }
  92.     }
  93. /*--------------------------------------------------------------------------*/
  94. MRESULT    EXPENTRY dlgproc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  95.     {
  96.     int         i;
  97.  
  98.     switch (msg)
  99.         {
  100.         case WM_INITDLG:
  101.             inconfig=FALSE;
  102.             lb.Set (WinWindowFromID (hwnd, 102));
  103.             for (i=0; i<numplayer; i++)
  104.                     {
  105.                     fip[i]->name[0] = '1'+i;
  106.                     fip[i]->name[1] = ' ';
  107.                     lb.InsertEnd (0, fip[i]->name);
  108.                     }
  109.             return (FALSE);
  110.         case WM_COMMAND:
  111.             if (inconfig)
  112.                 break;
  113.             inconfig=TRUE;
  114.             switch (SHORT1FROMMP (mp1))
  115.                 {
  116.                 case DID_OK:
  117.                     WinDismissDlg (hwnd, TRUE);
  118.                     break;
  119.                 case DID_CANCEL:
  120.                     WinDismissDlg (hwnd, FALSE);
  121.                     break;
  122.                 case 103:   // New
  123.                     i = GetName ();
  124.                     if (i >= 0)
  125.                         {
  126.                         fip[i]->name[0] = '1'+i;
  127.                         fip[i]->name[1] = ' ';
  128.                         if (lb.Selection () == LIT_NONE)
  129.                             lb.InsertEnd (0, fip[i]->name);
  130.                         else
  131.                             Reorder (lb.Selection ());
  132.                         }
  133.                     break;
  134.                 case 104:   // Define
  135.                     i = lb.Selection ();
  136.                     if (i != LIT_NONE)
  137.                         fip[i]->func[2] ((char __far16 *)fip[i]->data);    // Config
  138.                     break;
  139.                 case 105:   // Delete
  140.                     i = lb.Selection ();
  141.                     if (i == LIT_NONE)
  142.                         break;
  143.                     DelFip (i);
  144.                     lb.DeleteAll ();
  145.                     for (i=0; i<numplayer; i++)
  146.                         {
  147.                         fip[i]->name[0] = '1'+i;
  148.                         fip[i]->name[1] = ' ';
  149.                         lb.InsertEnd (0, fip[i]->name);
  150.                         }
  151.                     break;                }
  152.             inconfig=FALSE;
  153.             break;
  154.         case WM_CONTROL:
  155.             if (SHORT1FROMMP (mp1)==102 && SHORT2FROMMP (mp1)==LN_ENTER)
  156.                 {
  157.                 if (inconfig)
  158.                     break;
  159.                 inconfig=TRUE;
  160.                 i = lb.Selection ();
  161.                 if (i != LIT_NONE)
  162.                     fip[i]->func[2] ((char __far16 *)fip[i]->data);    // Config
  163.                 ignore=TRUE;
  164.                 inconfig=FALSE;
  165.                 }
  166.             break;
  167.         case WM_CHAR:
  168.             if (ignore)
  169.                 {
  170.                 ignore=FALSE;
  171.                 return (TRUE);
  172.                 }
  173.             if (SHORT2FROMMP (mp2) == VK_ESC)
  174.                 {
  175.                 lb.SetSelection (LIT_NONE);
  176.                 return (TRUE);
  177.                 }
  178.             break;
  179.         default:
  180.             return (WinDefDlgProc (hwnd, msg, mp1, mp2));
  181.         }
  182.     return (0L);
  183.     }
  184. /*--------------------------------------------------------------------------*/
  185. int main ()
  186.     {
  187.     GIInitialize ();
  188.  
  189.     // File-Dlg vorbereiten
  190.     filedlg.cbSize = sizeof (FILEDLG);
  191.     filedlg.fl = FDS_CENTER | FDS_OPEN_DIALOG;
  192.     filedlg.pszTitle = "Name of Interface Driver";
  193.     strcpy (filedlg.szFullFile, "*.DLL");
  194.  
  195.     if (WinDlgBox (HWND_DESKTOP, HWND_DESKTOP, dlgproc, 0, 100, NULL))
  196.         Save ();
  197.  
  198.     return (NOERR);
  199.     }
  200.