home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / pmtermsr.lzh / settings.c < prev    next >
C/C++ Source or Header  |  1995-10-13  |  5KB  |  131 lines

  1.  
  2. #include "pmterm.h"
  3.  
  4. /*
  5.  * This file manages the "Settings" dialog
  6.  */
  7.  
  8. static MRESULT EXPENTRY DlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  9. {
  10.     PDATA *pdata = WinQueryWindowPtr(hwnd, QWL_USER);
  11.     switch (msg) {
  12.     case WM_INITDLG:
  13.         WinSetWindowPtr(hwnd, QWL_USER, mp2);
  14.         return 0;
  15.     case WM_COMMAND:
  16.         switch (SHORT1FROMMP(mp1)) {
  17.         case DID_OK:
  18.             WinDismissDlg(hwnd, TRUE);
  19.             return 0L;
  20.         case DID_CANCEL:
  21.             WinDismissDlg(hwnd, FALSE);
  22.             return 0L;
  23.         }
  24.         break;
  25.     }
  26.     return (WinDefDlgProc(hwnd, msg, mp1, mp2));
  27. }
  28.  
  29.  
  30.  
  31. void Settings(PDATA *pdata)
  32. {
  33.     HWND hwndDlg, h;
  34.     long maxbps;
  35.     static int rates[] = {110, 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 67200, 115200, 0};
  36.     int i;
  37.     char str[20];
  38.     USHORT id;
  39.  
  40.     hwndDlg = WinLoadDlg(HWND_DESKTOP, pdata->hwndClient, DlgProc, 0, DLG_SETTINGS, pdata);
  41.     if(!hwndDlg)
  42.     return;
  43.  
  44.     WinSetDlgItemText(hwndDlg, IDEF_INITSTRING, pdata->ini.InitString);
  45.  
  46.     h = WinWindowFromID(hwndDlg, IDEF_SPEED);
  47.     maxbps = QueryMaxRate(pdata->hf);
  48.     for(i=0; rates[i] && rates[i] <= maxbps; i++){
  49.     sprintf(str, "%d", rates[i]);
  50.     WinInsertLboxItem(h, LIT_END, str);
  51.     }
  52.     sprintf(str, "%d", pdata->ini.bps);
  53.     WinSetWindowText(h, str);
  54.  
  55.  
  56.     h = WinWindowFromID(hwndDlg, IDCB_DEVICENAME);
  57.     for(i=0; i<4; i++){
  58.     sprintf(str, "COM%d", i+1);
  59.     WinInsertLboxItem(h, LIT_END, str);
  60.     }
  61.     WinSetWindowText(h, pdata->ini.DevName);
  62.  
  63.     switch(pdata->ini.databits){
  64.     case 5: id = IDRB_5; break;
  65.     case 6: id = IDRB_6; break;
  66.     case 7: id = IDRB_7; break;
  67.     case 8: id = IDRB_8; break;
  68.        default: id = IDRB_8; break;
  69.     }
  70.     WinSendDlgItemMsg(hwndDlg, id, BM_SETCHECK, (MPARAM)TRUE, 0);
  71.  
  72.     switch(pdata->ini.stopbits){
  73.     case 0: id = IDRB_1 ; break;
  74.     case 1: id = IDRB_15; break;
  75.     case 2: id = IDRB_2 ; break;
  76.        default: id = IDRB_1; break;
  77.     }
  78.     WinSendDlgItemMsg(hwndDlg, id, BM_SETCHECK, (MPARAM)TRUE, 0);
  79.  
  80.     switch(pdata->ini.parity){
  81.     case 0: id = IDRB_NONE ; break;
  82.     case 1: id = IDR_ODD   ; break;
  83.     case 2: id = IDRB_EVEN ; break;
  84.     case 3: id = IDPB_MARK ; break;
  85.     case 4: id = IDRB_SPACE; break;
  86.        default: id = IDRB_NONE; break;
  87.     }
  88.     WinSendDlgItemMsg(hwndDlg, id, BM_SETCHECK, (MPARAM)TRUE, 0);
  89.  
  90.     if(pdata->ini.CtsRts  )  WinSendDlgItemMsg(hwndDlg, IDCHK_CTS   , BM_SETCHECK, (MPARAM)TRUE, 0);
  91.     if(pdata->ini.XonXoff )  WinSendDlgItemMsg(hwndDlg, IDCHK_XON   , BM_SETCHECK, (MPARAM)TRUE, 0);
  92.     if(pdata->ini.ExtBuf  )  WinSendDlgItemMsg(hwndDlg, IDCHK_EXTBUF, BM_SETCHECK, (MPARAM)TRUE, 0);
  93.  
  94.     if(WinProcessDlg(hwndDlg)){
  95.     WinQueryDlgItemText(hwndDlg, IDEF_INITSTRING, sizeof(pdata->ini.InitString), pdata->ini.InitString);
  96.     WinQueryDlgItemText(hwndDlg, IDCB_DEVICENAME, sizeof(pdata->ini.DevName), pdata->ini.DevName);
  97.     WinQueryDlgItemText(hwndDlg, IDEF_SPEED, sizeof(str), str);
  98.     pdata->ini.bps = atol(str);
  99.  
  100.          if(WinSendDlgItemMsg(hwndDlg, IDRB_5, BM_QUERYCHECK, 0, 0)) pdata->ini.databits = 5;
  101.     else if(WinSendDlgItemMsg(hwndDlg, IDRB_6, BM_QUERYCHECK, 0, 0)) pdata->ini.databits = 6;
  102.     else if(WinSendDlgItemMsg(hwndDlg, IDRB_7, BM_QUERYCHECK, 0, 0)) pdata->ini.databits = 7;
  103.     else pdata->ini.databits = 8;
  104.  
  105.          if(WinSendDlgItemMsg(hwndDlg, IDRB_1 , BM_QUERYCHECK, 0, 0)) pdata->ini.stopbits = 0;
  106.     else if(WinSendDlgItemMsg(hwndDlg, IDRB_15, BM_QUERYCHECK, 0, 0)) pdata->ini.stopbits = 1;
  107.     else pdata->ini.stopbits = 2;
  108.  
  109.          if(WinSendDlgItemMsg(hwndDlg, IDRB_NONE , BM_QUERYCHECK, 0, 0)) pdata->ini.parity = 0;
  110.     else if(WinSendDlgItemMsg(hwndDlg, IDR_ODD   , BM_QUERYCHECK, 0, 0)) pdata->ini.parity = 1;
  111.     else if(WinSendDlgItemMsg(hwndDlg, IDRB_EVEN , BM_QUERYCHECK, 0, 0)) pdata->ini.parity = 2;
  112.     else if(WinSendDlgItemMsg(hwndDlg, IDPB_MARK , BM_QUERYCHECK, 0, 0)) pdata->ini.parity = 3;
  113.     else pdata->ini.parity = 4;
  114.  
  115.     pdata->ini.CtsRts  =  (BOOL)WinSendDlgItemMsg(hwndDlg, IDCHK_CTS   , BM_QUERYCHECK, 0, 0);
  116.     pdata->ini.XonXoff =  (BOOL)WinSendDlgItemMsg(hwndDlg, IDCHK_XON   , BM_QUERYCHECK, 0, 0);
  117.     pdata->ini.ExtBuf  =  (BOOL)WinSendDlgItemMsg(hwndDlg, IDCHK_EXTBUF, BM_QUERYCHECK, 0, 0);
  118.         if(SetupPort(pdata)){
  119.             HINI hini;
  120.             hini = PrfOpenProfile(pdata->hab, "pmterm.ini");
  121.             if(!hini){
  122.                 ErrMesg(pdata, "Couldn't open ini file 'PMTERM.INI'");
  123.                 exit(1);
  124.             }
  125.             PrfWriteProfileData(hini, "pmterm", "settings", &pdata->ini, sizeof(INI_STUFF));
  126.             PrfCloseProfile(hini);
  127.         }
  128.     }
  129.     WinDestroyWindow(hwndDlg);
  130. }
  131.