home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / SLIDCO.ZIP / SLIDDLG.C < prev    next >
C/C++ Source or Header  |  1993-02-02  |  24KB  |  807 lines

  1. #define INCL_DOS
  2. #define INCL_ERRORS
  3. #define INCL_DOSDEVIOCTL
  4. #define INCL_DOSDEVICES
  5. #define INCL_PM
  6. #include <os2.h>
  7. #include <process.h>
  8. #include <conio.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <stddef.h>
  12. #include <string.h>
  13.  
  14. #include "protype.h"
  15. #include "sliddlg.h"
  16. #include "extern.h"
  17.  
  18.  
  19.  
  20. typedef struct
  21. {
  22.    HFILE  CommHandle;
  23.    char   CommName[10];
  24. } COMMSTRUCT;
  25.  
  26. COMMSTRUCT  CommStruct[4] =   {0,"COM1",
  27.                                0,"COM2",
  28.                                0,"COM3",
  29.                                0,"COM4" };
  30.  
  31. LINECONTROL DataPacket;
  32.  
  33. CHAR PrintBuf[80];
  34.  
  35.  
  36. #define TOTALSPINVALS   11
  37. static PSZ   SpinSelectVals[] = {"1200", "1800", "2000", "2400","3600",
  38.                      "4800", "7200", "9600", "19200", "38400",
  39.                      "57600"};
  40.  
  41. #define MaximumTicks      100
  42. #define MinorTickSpacing  1
  43. #define MinorTickSize     4
  44. #define MajorTickSpacing  5 
  45. #define MajorTickSize     8
  46. #define DetentSpacing     10
  47. #define TextSpacing       10
  48.  
  49. static USHORT LastVal;
  50.  
  51. /****************************************************************************
  52.  
  53. ****************************************************************************/
  54. MRESULT EXPENTRY ComSelectDlgProc( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  55. {
  56.  
  57.    APIRET RetCode;
  58.  
  59.    switch(msg)
  60.    {
  61.       //*********************************
  62.       case WM_INITDLG:
  63.          RetCode = WmInitComSelect(  hwnd);
  64.          return (MRESULT)1;
  65.  
  66.  
  67.       //*********************************
  68.       case WM_COMMAND:
  69.          switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value    */
  70.          {
  71.             case DID_OK:
  72.                RetCode = OpenComPort(  hwnd);
  73.                if (RetCode != 0)
  74.                   break;
  75.  
  76.             case DID_CANCEL: 
  77.                WinDismissDlg( hwnd, TRUE ); 
  78.                return (MRESULT)FALSE;
  79.  
  80.            default:
  81.                break;
  82.          }
  83.          break;
  84.  
  85.  
  86.       //*********************************
  87.       default:
  88.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  89.    }
  90.    return (MRESULT)0;
  91. }
  92.  
  93. /****************************************************************************
  94.  
  95. ****************************************************************************/
  96. MRESULT EXPENTRY ComInitDlgProc( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  97. {
  98.  
  99.    APIRET RetCode;
  100.  
  101.    switch(msg)
  102.    {
  103.       //*********************************
  104.       case WM_INITDLG:
  105.          
  106.          if ( CommPortOpen(hwnd) == FALSE)
  107.             {
  108.             WinDismissDlg( hwnd, TRUE );  
  109.             return (MRESULT)FALSE;
  110.             }
  111.  
  112.          InitLineBits(hwnd);
  113.          InitializeSpinButton( hwnd);
  114.  
  115.          return (MRESULT)1;
  116.  
  117.  
  118.       //*********************************
  119.       case WM_COMMAND:
  120.          switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value    */
  121.          {
  122.             case DID_OK:
  123.                RetCode = SetLineBitVals( hwnd);
  124.                if (RetCode != 0)
  125.                   break;
  126.                RetCode = SetBiteRate( hwnd);
  127.                if (RetCode != 0)
  128.                   break;
  129.             
  130.                
  131.             case DID_CANCEL: 
  132.                WinDismissDlg( hwnd, TRUE ); 
  133.                return (MRESULT)FALSE;
  134.  
  135.            default:
  136.                break;
  137.          }
  138.          break;
  139.  
  140.  
  141.       //*********************************
  142.       default:
  143.          return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  144.    }
  145.    return (MRESULT)0;
  146. }
  147.  
  148.  
  149. /****************************************************************************
  150.  
  151. First time through HandleComm = 0, no port initially selected
  152.  
  153. On "exit" either no port was selected or an initial port was selected or
  154. a different port was selected.
  155.  
  156.  
  157. ****************************************************************************/
  158. APIRET OpenComPort( HWND hwnd)
  159. {
  160.    MRESULT QueryButtonCheck;
  161.    short ButtonIndex;
  162.    APIRET rc;
  163.    ULONG ulAction;
  164.    CHAR PrintBuf[100];
  165.    int i;
  166.  
  167.  
  168.    if (HandleComm != 0) //HandleComm does = 0 first time through
  169.       {                 //find open port and close, so can open new selection
  170.       for (i=0; i < 4; i++)
  171.          {
  172.          if (CommStruct[i].CommHandle == HandleComm)
  173.             {
  174.             rc = DosClose(CommStruct[i].CommHandle);
  175.             CommStruct[i].CommHandle = 0;
  176.             if (rc)
  177.                {
  178.                sprintf(PrintBuf,"RC=%u Line=%u\nFile: %s",rc,__LINE__,__FILE__);
  179.                WinDebugMsg(PrintBuf,hwnd);
  180.                }
  181.             break;
  182.             }
  183.          }
  184.       }
  185.  
  186.    
  187.    //Determine which port selected by user if any
  188.    
  189.    for (ButtonIndex=0; ButtonIndex < 4; ButtonIndex++)
  190.       {
  191.       QueryButtonCheck = WinSendDlgItemMsg(hwnd,
  192.          IDC_COMM1_SELECT+ButtonIndex,
  193.          BM_QUERYCHECK,
  194.          (MPARAM) 0,
  195.          (MPARAM) 0);
  196.  
  197.       if (SHORT1FROMMP(QueryButtonCheck) == 1)
  198.          {
  199.          //Open the selected comm port
  200.          rc = DosOpen(CommStruct[ButtonIndex].CommName,
  201.                      &CommStruct[ButtonIndex].CommHandle,
  202.                      &ulAction,
  203.                      0,
  204.                      FILE_NORMAL,
  205.                      FILE_OPEN,
  206.                      OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE,
  207.                      (PEAOP2) NULL);
  208.  
  209.          if (rc)
  210.             {
  211.             sprintf(PrintBuf,"RC=%u Line=%u\nFile: %s",rc,__LINE__,__FILE__);
  212.             WinDebugMsg(PrintBuf,hwnd);
  213.             WinSetFocus (HWND_DESKTOP,
  214.                            WinWindowFromID(hwnd,DID_OK));
  215.             HandleComm = 0;
  216.             return 1;
  217.             }
  218.  
  219.          // Set the global variable
  220.          HandleComm = CommStruct[ButtonIndex].CommHandle;
  221.  
  222.          return 0;
  223.  
  224.          }
  225.       }
  226.  
  227.    return 0;
  228.  
  229. }
  230. /****************************************************************************
  231.  
  232. ****************************************************************************/
  233. APIRET WmInitComSelect( HWND hwnd)
  234. {
  235.  
  236.    int i;
  237.  
  238.    if (HandleComm == 0) //no comm port open, uncheck all buttons
  239.       {
  240.       for (i=0; i < 4; i++)
  241.          {
  242.           WinSendDlgItemMsg(hwnd,
  243.                         IDC_COMM1_SELECT+i,
  244.                         BM_SETCHECK,
  245.                         MPFROM2SHORT(FALSE,0),
  246.                         NULL);
  247.          WinSetFocus (HWND_DESKTOP,
  248.             WinWindowFromID(hwnd,IDC_COMM1_SELECT+i));
  249.          }
  250.          WinSetFocus (HWND_DESKTOP,
  251.             WinWindowFromID(hwnd,DID_OK));
  252.       return 0;
  253.       }
  254.  
  255.    //otherwise, search for the open comm port and check corresponding button  
  256.  
  257.    for (i=0; i < 4; i++)
  258.       {
  259.       if (CommStruct[i].CommHandle == HandleComm)
  260.          {
  261.           WinSendDlgItemMsg(hwnd,
  262.                         IDC_COMM1_SELECT+i,
  263.                         BM_SETCHECK,
  264.                         MPFROM2SHORT(TRUE,0),
  265.                         NULL);
  266.          WinSetFocus (HWND_DESKTOP,
  267.             WinWindowFromID(hwnd,IDC_COMM1_SELECT+i));
  268.          }
  269.       }
  270.       return 0;
  271.  
  272. }
  273.  
  274.  
  275. /****************************************************************************
  276.  
  277. ****************************************************************************/
  278. APIRET InitLineBits(HWND hwnd)
  279. {
  280.  
  281.    APIRET rc;
  282.    ULONG DataPacketLen;
  283.  
  284.  
  285.  
  286.    rc = DosDevIOCtl (HandleComm,
  287.                      IOCTL_ASYNC,
  288.                      ASYNC_GETLINECTRL,
  289.                      NULL,                  //no parameter packet
  290.                      0,                  // = 0
  291.                      NULL,                  // length of parm packet
  292.                      (PULONG) &DataPacket,
  293.                      sizeof(DataPacket),
  294.                      &DataPacketLen);
  295.  
  296.    rc = DosDevIOCtl (HandleComm,
  297.                      IOCTL_ASYNC,
  298.                      ASYNC_GETLINECTRL,
  299.                      NULL,                  //no parameter packet
  300.                      0,                  // = 0
  301.                      NULL,                  // length of parm packet
  302.                      (PULONG) &DataPacket,
  303.                      sizeof(DataPacket),
  304.                      &DataPacketLen);
  305.  
  306.    if (rc)
  307.       {
  308.       sprintf(PrintBuf,"RC=%u Line=%u\nFile: %s",rc,__LINE__,__FILE__);
  309.       WinDebugMsg(PrintBuf,hwnd);
  310.       }
  311.  
  312.  
  313.    WinSendDlgItemMsg(hwnd,
  314.                      (ULONG) IDC_DATA_BIT5 + (DataPacket.bDataBits - 5),
  315.                      (ULONG) BM_SETCHECK,
  316.                      MPFROM2SHORT(TRUE,0),
  317.                      NULL);
  318.  
  319.    WinSendDlgItemMsg(hwnd,IDC_PARITY_NO + DataPacket.bParity,
  320.                         BM_SETCHECK,
  321.                         MPFROM2SHORT(TRUE,0),
  322.                         NULL);
  323.  
  324.    WinSendDlgItemMsg(hwnd,IDC_STOP_BIT1 + DataPacket.bStopBits,
  325.                         BM_SETCHECK,
  326.                         MPFROM2SHORT(TRUE,0),
  327.                         NULL);
  328.  
  329.  
  330.  
  331.  
  332.    WinSetFocus (HWND_DESKTOP, WinWindowFromID(hwnd,DID_OK));
  333.  
  334.  
  335.    return 0;
  336. }
  337. /****************************************************************************
  338.  
  339. ****************************************************************************/
  340. APIRET SetLineBitVals( HWND hwnd)
  341. {
  342.  
  343.  
  344.    APIRET rc;
  345.    ULONG DataPacketLen;
  346.  
  347.    MRESULT QueryButtonCheck;
  348.    short ButtonIndex;
  349.  
  350.    
  351.    for (ButtonIndex=0; ButtonIndex < 4; ButtonIndex++)
  352.       {
  353.       QueryButtonCheck = WinSendDlgItemMsg(hwnd,
  354.          IDC_DATA_BIT5+ButtonIndex,
  355.          BM_QUERYCHECK,
  356.          (MPARAM) 0,
  357.          (MPARAM) 0);
  358.  
  359.       if (SHORT1FROMMP(QueryButtonCheck) == 1)
  360.          {
  361.          DataPacket.bDataBits = ButtonIndex + 5;
  362.          }
  363.       }
  364.  
  365.    for (ButtonIndex=0; ButtonIndex < 5; ButtonIndex++)
  366.       {
  367.       QueryButtonCheck = WinSendDlgItemMsg(hwnd,
  368.          IDC_PARITY_NO+ButtonIndex,
  369.          BM_QUERYCHECK,
  370.          (MPARAM) 0,
  371.          (MPARAM) 0);
  372.  
  373.       if (SHORT1FROMMP(QueryButtonCheck) == 1)
  374.          {
  375.          DataPacket.bParity = ButtonIndex;
  376.          }
  377.       }
  378.    for (ButtonIndex=0; ButtonIndex < 3; ButtonIndex++)
  379.       {
  380.       QueryButtonCheck = WinSendDlgItemMsg(hwnd,
  381.          IDC_STOP_BIT1+ButtonIndex,
  382.          BM_QUERYCHECK,
  383.          (MPARAM) 0,
  384.          (MPARAM) 0);
  385.  
  386.       if (SHORT1FROMMP(QueryButtonCheck) == 1)
  387.          {
  388.          DataPacket.bStopBits = ButtonIndex;
  389.          }
  390.       }
  391.  
  392.  
  393.    rc = DosDevIOCtl (HandleComm,
  394.                      IOCTL_ASYNC,
  395.                      ASYNC_SETLINECTRL,
  396.                      (PULONG) &DataPacket,
  397.                      sizeof(DataPacket),
  398.                      &DataPacketLen,
  399.                      NULL,              
  400.                      0,                 
  401.                      NULL);
  402.  
  403.  
  404.    rc = DosDevIOCtl (HandleComm,
  405.                      IOCTL_ASYNC,
  406.                      ASYNC_SETLINECTRL,
  407.                      (PULONG) &DataPacket,
  408.                      sizeof(DataPacket),
  409.                      &DataPacketLen,
  410.                      NULL,              
  411.                      0,                 
  412.                      NULL);
  413.  
  414.  
  415.    if (rc)
  416.       {
  417.       sprintf(PrintBuf,"RC=%u Line=%u\nFile: %s",rc,__LINE__,__FILE__);
  418.       WinDebugMsg(PrintBuf,hwnd);
  419.       }
  420.  
  421.    return 0;
  422.  
  423. }
  424.  
  425.  
  426. /*****************************************************************************
  427. *****************************************************************************/
  428. BOOL InitializeSpinButton(HWND hwnd)
  429. {
  430.  
  431.    USHORT usBitRate;
  432.    USHORT ArrayIndex;
  433.    char buffer[35];
  434.    char *p;
  435.  
  436.    if ( !WinSendDlgItemMsg( hwnd, IDC_SET_BIT_RATE, SPBM_SETARRAY, SpinSelectVals,
  437.              MPFROMLONG(TOTALSPINVALS)))
  438.       return FALSE;
  439.  
  440.  
  441.    usBitRate = Get_IOCTL_Bit_Rate(hwnd);
  442.  
  443.  
  444.    p = _itoa(usBitRate,buffer,10);
  445.  
  446.    for (ArrayIndex=0; ArrayIndex<TOTALSPINVALS; ArrayIndex++)
  447.       {
  448.       if ( strcmp( (const char * )SpinSelectVals[ArrayIndex],&buffer[0] ) == 0 )
  449.          {
  450.          WinSendDlgItemMsg( hwnd, IDC_SET_BIT_RATE, SPBM_SETCURRENTVALUE,
  451.              MPFROMLONG(ArrayIndex), NULL);
  452.          return TRUE;
  453.          }
  454.       }
  455.  
  456.    WinSetFocus (HWND_DESKTOP, WinWindowFromID(hwnd,DID_OK));
  457.  
  458.    return TRUE;
  459.  
  460. /****************************************************************************
  461.  
  462. ****************************************************************************/
  463. USHORT SetBiteRate( HWND hwnd)
  464. {
  465.  
  466.    ULONG ArrayIndex=0;
  467.    USHORT usBitRate;
  468.  
  469.    WinSendDlgItemMsg(hwnd,
  470.                         IDC_SET_BIT_RATE,
  471.                         SPBM_QUERYVALUE,
  472.                         &ArrayIndex,
  473.                         MPFROM2SHORT(0,0));
  474.      
  475.  
  476.    usBitRate = atoi( SpinSelectVals[ArrayIndex] );
  477.    Set_IOCTL_Bit_Rate(usBitRate,hwnd );
  478.  
  479.    return 0;
  480.  
  481.    
  482. }
  483.  
  484. /***************************************************************************/
  485. /*                                                                         */
  486. /***************************************************************************/
  487. void Set_IOCTL_Bit_Rate(USHORT BitRate,HWND hwnd)
  488. {
  489.    APIRET rc;
  490.    ULONG ParmPacketLen;
  491.    ParmPacketLen = 2;  //size of Parmpacket
  492.  
  493.    rc = DosDevIOCtl (HandleComm,
  494.                      IOCTL_ASYNC,
  495.                      ASYNC_SETBAUDRATE,
  496.                      (PULONG) &BitRate, 
  497.                      sizeof(BitRate),    //size input parm packet
  498.                      &ParmPacketLen,         // length of parm packet
  499.                      NULL,
  500.                      0,
  501.                      NULL);
  502.  
  503.    rc = DosDevIOCtl (HandleComm,
  504.                      IOCTL_ASYNC,
  505.                      ASYNC_SETBAUDRATE,
  506.                      (PULONG) &BitRate, 
  507.                      sizeof(BitRate),    //size input parm packet
  508.                      &ParmPacketLen,         // length of parm packet
  509.                      NULL,
  510.                      0,
  511.                      NULL);
  512.  
  513.  
  514.    if (rc)
  515.       {
  516.       sprintf(PrintBuf,"RC=%u Line=%u\nFile: %s",rc,__LINE__,__FILE__);
  517.       WinDebugMsg(PrintBuf,hwnd);
  518.       }
  519.  
  520. }
  521. /***************************************************************************/
  522. /*                                                                         */
  523. /***************************************************************************/
  524. USHORT Get_IOCTL_Bit_Rate(HWND hwnd)
  525. {
  526.    APIRET rc;
  527.    USHORT DataPacket=0;
  528.    ULONG DataPacketLen;
  529.    DataPacket = 0;
  530.  
  531.    rc = DosDevIOCtl ( (HFILE) HandleComm,
  532.                      (ULONG) IOCTL_ASYNC,
  533.                      (ULONG) ASYNC_GETBAUDRATE,
  534.                      (PVOID) NULL,                  //no parameter packet
  535.                      (ULONG) NULL,                  // = 0
  536.                      (PULONG) NULL,                  // length of parm packet
  537.                      (PVOID) &DataPacket,
  538.                      (ULONG) sizeof(DataPacket),
  539.                      (PULONG) &DataPacketLen);
  540.  
  541.    rc = DosDevIOCtl ( (HFILE) HandleComm,
  542.                      (ULONG) IOCTL_ASYNC,
  543.                      (ULONG) ASYNC_GETBAUDRATE,
  544.                      (PVOID) NULL,                  //no parameter packet
  545.                      (ULONG) NULL,                  // = 0
  546.                      (PULONG) NULL,                  // length of parm packet
  547.                      (PVOID) &DataPacket,
  548.                      (ULONG) sizeof(DataPacket),
  549.                      (PULONG) &DataPacketLen);
  550.  
  551.  
  552.    if (rc)
  553.       {
  554.       sprintf(PrintBuf,"RC=%u Line=%u\nFile: %s",rc,__LINE__,__FILE__);
  555.       WinDebugMsg(PrintBuf,hwnd);
  556.       }
  557.  
  558.       return DataPacket;
  559.  
  560. }
  561.  
  562. /****************************************************************************
  563.  
  564. ****************************************************************************/
  565. MRESULT EXPENTRY SliderDlgProc( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  566. {
  567.  
  568.    CHAR      acBuffer[10];
  569.    CHAR      *cData;
  570.    USHORT  usNewPctDone;
  571.    SHORT ulValue;
  572.    static SHORT sPtVal=0;
  573.    APIRET rc;
  574.  
  575.     switch(msg)
  576.     {
  577.        //*********************************
  578.        case WM_INITDLG:
  579.  
  580.          if ( CommPortOpen(hwnd) == FALSE)
  581.             {
  582.             WinDismissDlg( hwnd, TRUE );  
  583.             return (MRESULT)FALSE;
  584.             }
  585.          hwndDlg = hwnd; //used in read task to send term input
  586.          
  587.          InitSlider (hwnd, IDC_SLIDER_CONTROL,MaximumTicks,
  588.                          MinorTickSpacing,MinorTickSize, 
  589.                          MajorTickSpacing,MajorTickSize, 
  590.                          DetentSpacing, TextSpacing,    
  591.                         "10.Courier");
  592.  
  593.         //set the limit of the entry field    
  594.          WinSendDlgItemMsg(hwnd,
  595.                      IDC_SLIDER_DATA,
  596.                      EM_SETTEXTLIMIT,
  597.                      (MPARAM)3,
  598.                      (MPARAM)0);
  599.          
  600.          WinStartTimer( hab, hwnd,
  601.                      TMID_QUERY_TIMER,
  602.                      750);  //every 750 msec
  603.          LastVal = 0;        
  604.     
  605.          return 0;
  606.  
  607.       //*********************************
  608.       case WM_TERMINAL_MSG:
  609.          //sent from the DOS read thread
  610.          usNewPctDone    =    (USHORT) mp1;
  611.          if ( (usNewPctDone >= 0)  && (usNewPctDone <= MaximumTicks) )
  612.             {
  613.  
  614.             WinSendDlgItemMsg (hwnd, IDC_SLIDER_CONTROL,
  615.                         SLM_SETSLIDERINFO,
  616.                         MPFROM2SHORT (SMA_SLIDERARMPOSITION,
  617.                                         SMA_INCREMENTVALUE),
  618.                         MPFROMSHORT (usNewPctDone));
  619.              LastVal = usNewPctDone;
  620.              }
  621.  
  622.             return 0;
  623.  
  624.       //*********************************
  625.       case WM_TIMER:
  626.          
  627.             switch(SHORT1FROMMP(mp1))
  628.                {
  629.                case TMID_QUERY_TIMER:
  630.                  {
  631.                  ulValue = (SHORT) WinSendDlgItemMsg(hwnd, IDC_SLIDER_CONTROL,
  632.                      SLM_QUERYSLIDERINFO,
  633.                   MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_INCREMENTVALUE),
  634.                   NULL);
  635.                  
  636.                   if ( ulValue != LastVal)
  637.                      {
  638.                      LastVal = ulValue;
  639.                      cData = _ltoa(ulValue,acBuffer,10);
  640.                      WinSetDlgItemText(hwnd,IDC_SLIDER_DATA, cData);
  641.                      strcat( acBuffer, " ");
  642.                      PrintTerm(acBuffer);
  643.                      }
  644.                   break;
  645.                   }
  646.                default: break;
  647.                }
  648.          break;
  649.  
  650.       //*********************************
  651.       case WM_CONTROL:
  652.          switch(SHORT2FROMMP(mp1))
  653.          {
  654.             case SLN_SLIDERTRACK:
  655.             case  SLN_CHANGE:
  656.                {
  657.                ulValue = (SHORT) WinSendDlgItemMsg(hwnd, IDC_SLIDER_CONTROL,
  658.                   SLM_QUERYSLIDERINFO,
  659.                   MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_INCREMENTVALUE),
  660.                   NULL);
  661.                cData = _ltoa(ulValue,acBuffer,10);
  662.                WinSetDlgItemText(hwnd,IDC_SLIDER_DATA, cData);
  663.                break;
  664.                }
  665.          
  666.          default:
  667.             break;
  668.          
  669.          }
  670.  
  671.         break;
  672.  
  673.         case WM_COMMAND:
  674.             switch (SHORT1FROMMP(mp1))
  675.             {
  676.                 case DID_OK:
  677.                   WinStopTimer( hab,  hwnd, TMID_QUERY_TIMER);
  678.                   WinDismissDlg (hwnd, FALSE);
  679.                   return 0;
  680.  
  681.                 case IDC_MID_POINT:
  682.                 
  683.                       WinSendDlgItemMsg (hwnd, IDC_SLIDER_CONTROL,
  684.                                   SLM_SETSLIDERINFO,
  685.                                   MPFROM2SHORT (SMA_SLIDERARMPOSITION,
  686.                                                   SMA_INCREMENTVALUE),
  687.                                   MPFROMSHORT (MaximumTicks/2));
  688.                      return 0;
  689.             }
  690.          return 0;
  691.  
  692.         default:
  693.             return (WinDefDlgProc (hwnd, msg, mp1, mp2));
  694.     }
  695.     return FALSE;
  696. }
  697. /****************************************************************************
  698.  
  699. ****************************************************************************/
  700.  
  701. VOID InitSlider (HWND    hwnd,                    
  702.                  ULONG   idSlider,                
  703.                  USHORT  usMaximumTicks,          
  704.                  USHORT  usMinorTickSpacing,      
  705.                  USHORT  usMinorTickSize,         
  706.                  USHORT  usMajorTickSpacing,      
  707.                  USHORT  usMajorTickSize,         
  708.                  USHORT  usDetentSpacing,         
  709.                  USHORT  usTextSpacing,           
  710.                  PSZ     pszFont)                 
  711. {
  712.     USHORT     i;                          
  713.     CHAR       buffer[20];                 
  714.     USHORT     usIncrements;
  715.     USHORT     usSpacing;
  716.     WNDPARAMS  wprm;                   
  717.     SLDCDATA   sldcd;                  
  718.     HWND       hwndSlider = WinWindowFromID (hwnd, idSlider);
  719.  
  720.     wprm.fsStatus   = WPM_CTLDATA;      
  721.     wprm.cbCtlData  = sizeof (SLDCDATA);
  722.     wprm.pCtlData   = &sldcd;
  723.  
  724.    WinSendMsg (hwndSlider, WM_QUERYWINDOWPARAMS,
  725.                      MPFROMP(&wprm), 0);
  726.  
  727.    //*********************************************************************
  728.    // Set the total-max num of increments for slider
  729.    sldcd.usScale1Increments = usMaximumTicks +1;
  730.    sldcd.usScale1Spacing = 0;  //let slider do spacing
  731.  
  732.    wprm.fsStatus   = WPM_CTLDATA;  
  733.    wprm.cbCtlData  = sizeof (SLDCDATA);
  734.    wprm.pCtlData   = &sldcd;
  735.  
  736.    //set these paramaters
  737.    WinSendMsg (hwndSlider, WM_SETWINDOWPARAMS,
  738.                     MPFROMP(&wprm), 0);
  739.  
  740.    //*********************************************************************
  741.    //Read these parameters back so we can use them
  742.    wprm.fsStatus   = WPM_CTLDATA;      
  743.    wprm.cbCtlData  = sizeof (SLDCDATA);
  744.    wprm.pCtlData   = &sldcd;
  745.  
  746.    WinSendMsg (hwndSlider, WM_QUERYWINDOWPARAMS,
  747.                      MPFROMP(&wprm), 0);
  748.  
  749.    usIncrements =  sldcd.usScale1Increments;
  750.    usSpacing    =  sldcd.usScale1Spacing;
  751.  
  752.     //*********************************************************************
  753.    if (usMinorTickSpacing != 0)
  754.       {
  755.       for (i = 0; i <= usIncrements; i += usMinorTickSpacing)
  756.          {
  757.           WinSendMsg (hwndSlider,     // Set minor tick
  758.                         SLM_SETTICKSIZE,
  759.                         MPFROM2SHORT(i, usMinorTickSize),
  760.                         NULL);
  761.          }
  762.       }
  763.  
  764.    
  765.     //*********************************************************************
  766.    if (usMajorTickSpacing != 0)
  767.       {
  768.       for (i = 0; i <= usIncrements; i += usMajorTickSpacing)
  769.         {
  770.         WinSendMsg (hwndSlider,     // Set major tick
  771.                         SLM_SETTICKSIZE,
  772.                         MPFROM2SHORT(i, usMajorTickSize),
  773.                         NULL);
  774.         }
  775.       }
  776.  
  777.     //*********************************************************************
  778.     if (usDetentSpacing != 0)
  779.       {
  780.       for (i = 0; i <= usIncrements; i += usDetentSpacing)
  781.         {
  782.         WinSendMsg (hwndSlider,     // Set the detent
  783.                    SLM_ADDDETENT,
  784.                    MPFROM2SHORT((i*usSpacing), usDetentSpacing),
  785.                    NULL);
  786.         }
  787.       }
  788.     //*********************************************************************
  789.     if (usTextSpacing != 0)
  790.       {
  791.       if (pszFont != NULL)
  792.          {
  793.           WinSetPresParam (hwndSlider, PP_FONTNAMESIZE,
  794.                              (strlen(pszFont)+1),  pszFont);
  795.          }
  796.       for (i = 0; i <= usIncrements; i += usTextSpacing)
  797.         {
  798.         _itoa (i, buffer, 10);  
  799.         WinSendMsg (hwndSlider,SLM_SETSCALETEXT,
  800.                         MPFROMSHORT(i),
  801.                         MPFROMP(buffer));
  802.         }
  803.     }
  804.  
  805. }
  806.