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

  1.  
  2. #include "pmterm.h"
  3.  
  4. /*
  5.  * pmterm.c -- main() and main window proc
  6.  */
  7.  
  8. static PFNWP pfnOld;
  9.  
  10.  
  11. extern char *format(long recnum, void *user);   // see src\thread2.c
  12.  
  13. MRESULT EXPENTRY MyWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  14. {
  15.     SCROLL *scrl = WinQueryWindowPtr(hwnd, 0);
  16.     PDATA *pdata;
  17.     USHORT c;
  18.     ULONG bw;
  19.  
  20.     switch (msg) {
  21.     case WM_CHAR:
  22.             pdata = scrl->user;
  23.             if(pdata){
  24.                 if(CHARMSG(&msg)->fs & KC_CHAR){
  25.                     c = CHARMSG(&msg)->chr;
  26.                     DosWrite(pdata->hf, &c, 1, &bw);
  27.                 }
  28.                 else if(CHARMSG(&msg)->fs & KC_VIRTUALKEY){
  29.                     if(CHARMSG(&msg)->vkey == VK_ESC){
  30.                         c = 27;
  31.                         DosWrite(pdata->hf, &c, 1, &bw);
  32.                     }
  33.                 }
  34.             }
  35.         break;
  36.         case WM_COMMAND:
  37.             switch(SHORT1FROMMP(mp1)){
  38.                 case IDMI_SETTINGS:
  39.                     Settings(scrl->user);
  40.                     break;
  41.                 case IDMI_ABOUT:
  42.                     pdata = scrl->user;
  43.                     WinDlgBox(HWND_DESKTOP, pdata->hwndClient, WinDefDlgProc, 0, DLG_ABOUT, NULL);
  44.                     break;
  45.                 case IDMI_EXIT:
  46.                     WinPostMsg(hwnd, WM_QUIT, 0, 0);
  47.                     break;
  48.             }
  49.             break;
  50.     default:
  51.             return pfnOld(hwnd, msg, mp1, mp2);
  52.     }
  53.     return 0;
  54. }
  55.  
  56. int main(int argc, char **argv)
  57. {
  58.     HAB hab;
  59.     HMQ hmq;
  60.     HWND hwndFrame;
  61.     QMSG qmsg;
  62.     FRAMECDATA fcdata;
  63.     PDATA *pdata;
  64.     HINI hini;
  65.     ULONG cb;
  66.  
  67.     if (!(hab = WinInitialize(0)))
  68.     return 1;
  69.  
  70.     if (!(hmq = WinCreateMsgQueue(hab, 0)))
  71.     return 1;
  72.  
  73.  
  74.     /* Create frame window */
  75.     fcdata.cb = sizeof(FRAMECDATA);
  76.     fcdata.flCreateFlags = FCF_SHELLPOSITION | FCF_SIZEBORDER |
  77.         FCF_TASKLIST | FCF_MINMAX | FCF_MENU | FCF_ACCELTABLE |
  78.         FCF_SYSMENU | FCF_TITLEBAR | FCF_VERTSCROLL | FCF_HORZSCROLL;
  79.  
  80.  
  81.     fcdata.hmodResources = 0;               /* Resource file not in DLL. */
  82.     fcdata.idResources   = 1;
  83.  
  84.     hwndFrame = WinCreateWindow(
  85.         HWND_DESKTOP,                   /* parent       */
  86.         WC_FRAME,                       /* class */
  87.         NULL,                           /* window text or data  */
  88.         0,
  89.         0, 0, 0, 0,                     /* Position and size       */
  90.         (HWND)0,                           /* No owner                */
  91.         HWND_TOP,                       /* On top of siblings      */
  92.         fcdata.idResources,             /* Frame window identifier */
  93.         &fcdata,                        /* Control data            */
  94.         NULL);                          /* Reserved field          */
  95.  
  96.     if (!hwndFrame)
  97.     return 1;            /* couldn't create window for some
  98.                      * reason. */
  99.  
  100.     pdata = calloc(sizeof(PDATA), 1);
  101.  
  102.     hini = PrfOpenProfile(hab, "pmterm.ini");
  103.     if(!hini){
  104.         ErrMesg(pdata, "Couldn't open ini file 'PMTERM.INI'");
  105.         exit(1);
  106.     }
  107.  
  108.     cb = sizeof(INI_STUFF);
  109.     if(!PrfQueryProfileData(hini, "pmterm", "settings", &pdata->ini, &cb) || cb != sizeof(INI_STUFF)){
  110.         strcpy(pdata->ini.DevName, "COM2");
  111.         strcpy(pdata->ini.InitString, "ATZ");
  112.         pdata->ini.bps      = 19200;
  113.         pdata->ini.parity   = 0;        // none
  114.         pdata->ini.databits = 8;        // 8
  115.         pdata->ini.stopbits = 0;        // 1
  116.         pdata->ini.CtsRts   = TRUE;
  117.         pdata->ini.XonXoff  = FALSE;
  118.         pdata->ini.ExtBuf   = TRUE;
  119.     }
  120.     PrfCloseProfile(hini);
  121.  
  122.     ClientScrollSetup(hwndFrame, MAXLINES, MAXLINELEN, format, pdata);
  123.     pdata->hab        = hab;
  124.     pdata->hwndFrame  = hwndFrame;
  125.     pdata->hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
  126.     pfnOld = WinSubclassWindow( pdata->hwndClient, MyWindowProc);
  127.     WinShowWindow(hwndFrame, TRUE);
  128.     SetupPort(pdata);
  129.  
  130.     while (WinGetMsg(hab, &qmsg, 0L, 0, 0))
  131.         WinDispatchMsg(hab, &qmsg);
  132.  
  133.     WinDestroyWindow(hwndFrame);
  134.     WinDestroyMsgQueue(hmq);
  135.     WinTerminate(hab);
  136.  
  137.     return 0;
  138. }
  139.  
  140.