home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Power Pack / Visual_Basic4_Power_Pack.bin / vb4files / scentsls / sldemo2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-20  |  41.9 KB  |  1,304 lines

  1. //***************************************************************************
  2. //
  3. //  PROGRAM   : SLDEMO2.CPP
  4. //
  5. //  PROGRAMMER: Steven R Clabaugh
  6. //              SRC Enterprises
  7. //
  8. //  PURPOSE   : SRC Enterprises Slider Custom Control Class for
  9. //              C++ programing.
  10. //
  11. // Note that when a Slider Control is created with the CONTROL statement
  12. // in dialogs, it is not possible to use the Slider Class.  You can use the
  13. // Slider Class when creating the Slider directly in the dialog's
  14. // WM_INITDIALOG message handler.  This is demonstrated in the SLBankDialog6
  15. // function.  Dialogs 1-5 are identical to the dialogs in the SLDEMO1.C
  16. // program.
  17. // 
  18. //***************************************************************************
  19. #include <windows.h>
  20. #include <srcentsl.h>
  21. #include "sldemo2.h"
  22.  
  23. ///**************************************************************************
  24. //***************************************************************************
  25. //
  26. //      Global Variables
  27. //
  28. //***************************************************************************
  29. //***************************************************************************
  30. HINSTANCE hInst;  // current instance
  31.  
  32. char   MainWndClassName[] = "SLDemo2WClass",
  33.        MainWndMenu[]      = "SLDemo2Menu",
  34.        ProgTitle[]        = "SLDemo2 - Slider Sample Application";
  35.  
  36. LPSTR cBuff  = "         ";
  37.  
  38. //***************************************************************************
  39. //
  40. //  FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
  41. //
  42. //  PURPOSE: calls initialization function, processes message loop
  43. //
  44. //***************************************************************************
  45. int PASCAL WinMain(HINSTANCE hInstance,     // current instance
  46.                    HINSTANCE hPrevInstance, // previous instance
  47.                    LPSTR  lpCmdLine,        // command line
  48.                    int    nCmdShow)         // show-window type
  49. {
  50.  
  51.    MSG msg;   // message
  52.  
  53.    //****************************************************************
  54.  
  55.    if (!hPrevInstance)                  // Other instances of app running?
  56.        if (!InitApplication(hInstance)) // Initialize shared things
  57.            return (FALSE);              // Exits if unable to initialize
  58.  
  59.    // Perform initializations that apply to a specific instance
  60.    if (!InitInstance(hInstance, nCmdShow))
  61.        return (FALSE);
  62.  
  63.    // Acquire and dispatch messages until a WM_QUIT message is received.
  64.    while (GetMessage(&msg,       // message structure
  65.            NULL,                 // handle of window receiving the message
  66.            NULL,                 // lowest message to examine
  67.            NULL))                // highest message to examine
  68.        {
  69.        TranslateMessage(&msg);   // Translates virtual key codes
  70.        DispatchMessage(&msg);    // Dispatches message to window
  71.    }
  72.  
  73.    UnregisterClass((LPSTR)MainWndClassName,hInst);
  74.  
  75.    return (msg.wParam);          // Returns the value from PostQuitMessage
  76.  
  77. } // end WinMain
  78.  
  79. //***************************************************************************
  80. //
  81. //  FUNCTION: InitApplication(HINSTANCE)
  82. //
  83. //  PURPOSE: Initializes window data and registers window class
  84. //
  85. //***************************************************************************
  86. BOOL InitApplication(HINSTANCE hInstance)
  87.  
  88. {
  89.  
  90.    WNDCLASS  wc;
  91.  
  92.    //****************************************************************
  93.  
  94.    // Fill in window class structure with parameters that describe the
  95.    // main window.
  96.  
  97.    wc.style = NULL;
  98.    wc.lpfnWndProc = (WNDPROC)MainWndProc;
  99.    wc.cbClsExtra = 0;
  100.    wc.cbWndExtra = 0;
  101.    wc.hInstance = hInstance;
  102.    wc.hIcon = LoadIcon(hInstance,"progicon");
  103.    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  104.    wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  105.    wc.lpszMenuName =  MainWndMenu;
  106.    wc.lpszClassName = MainWndClassName;
  107.  
  108.    // Register the window class and return success/failure code.
  109.    return (RegisterClass(&wc));
  110.  
  111. }  // end InitApplication
  112.  
  113. //***************************************************************************
  114. //
  115. //  FUNCTION:  InitInstance(HINSTANCE, int)
  116. //
  117. //  PURPOSE:  Saves instance handle and creates main window
  118. //
  119. //***************************************************************************
  120. BOOL InitInstance(HINSTANCE hInstance, // Current instance identifier.
  121.                   int       nCmdShow)  // Param for first ShowWindow() call.
  122. {
  123.  
  124.    HWND hWnd;  // Main window handle
  125.  
  126.    //****************************************************************
  127.  
  128.    // Save the instance handle
  129.    hInst = hInstance;
  130.  
  131.    // Create a main window for this application instance.
  132.    hWnd = CreateWindow(
  133.        MainWndClassName,
  134.        ProgTitle,
  135.        WS_OVERLAPPEDWINDOW,
  136.        10,
  137.        10,
  138.        320,
  139.        220,
  140.        NULL,
  141.        NULL,
  142.        hInstance,
  143.        NULL
  144.    );
  145.  
  146.    // If window could not be created, return "failure"
  147.    if (!hWnd)
  148.        return (FALSE);
  149.  
  150.    // Make the window visible; update its client area; and return "success"
  151.    ShowWindow(hWnd, nCmdShow);  // Show the window
  152.    UpdateWindow(hWnd);          // Sends WM_PAINT message
  153.    return (TRUE);               // Returns the value from PostQuitMessage
  154.  
  155. }  // end InitInstance
  156.  
  157. //***************************************************************************
  158. //
  159. //  FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
  160. //
  161. //  PURPOSE:  Processes messages
  162. //
  163. //***************************************************************************
  164. long FAR PASCAL __export MainWndProc(
  165.                      HWND     hWnd,    // window handle
  166.                      unsigned message, // type of message
  167.                      WORD     wParam,  // additional information
  168.                      LONG     lParam)  // additional information
  169. {
  170.  
  171.    static HWND hSLEdit1, hSLEdit2, hSLEdit3, hSLEdit4;
  172.  
  173.    // Declare instances of Slider Class                        
  174.    static CSRCEntSL Slider1, Slider2, Slider3, Slider4;
  175.  
  176.    //****************************************************************
  177.  
  178.    switch (message)
  179.    {
  180.  
  181.       case WM_CREATE:
  182.  
  183.          // The four Sliders in the main window are created
  184.          // using the Slider Class functions.
  185.  
  186.          // Create Slider1 on the Main windlow client area.
  187.          // This will be a vertical, NON-reversed slider w/hand cursor
  188.          Slider1.Create(
  189.             NULL,      // Vertical, Nonreversed Slider
  190.             "slface1", // Resource name for the Slider Face
  191.             "slknob1", // Resource name for the Slider Knob
  192.             16,30,     // Slider X,Y position within the main client window
  193.             6,         // Knob slide position
  194.             6,         // Knob upper limit position
  195.             99,        // Knob lower limit position
  196.             0,100,     // range min & max
  197.             0,         // set an initial value
  198.             TRUE,      // Use the hand mouse cursor
  199.             TRUE,      // Enable the mouse
  200.             hWnd,      // Parent window handle
  201.             SLIDER1,   // Slider ID value
  202.             hInst);    // This Program's instance
  203.  
  204.          // EDIT control to display Slider1's value
  205.          hSLEdit1 = CreateWindow(
  206.             "EDIT",
  207.             "0",
  208.             WS_CHILD | WS_VISIBLE | WS_BORDER | WS_DISABLED,
  209.             12,140,32,22,
  210.             hWnd,
  211.             SLEDIT1,
  212.             hInst,
  213.             NULL
  214.          );
  215.          wsprintf(cBuff,"%d",Slider1.GetVal());
  216.          SetWindowText(hSLEdit1,cBuff);
  217.  
  218.          // Create Slider2 on the Main windlow client area.
  219.          // This will be a vertical, reversed slider w/arrow cursor
  220.          // Use the same face and knob as Slider 1
  221.          Slider2.Create(
  222.             SL_REVERSED,  // Vertical, reversed Slider
  223.             "slface1",  // Resource name for the Slider Face
  224.             "slknob1",  // Resource name for the Slider Knob
  225.             81,30,      // Slider X,Y position within the main client window
  226.             6,          // Knob slide position
  227.             6,          // Knob upper limit position
  228.             99,         // Knob lower limit position
  229.             0,100,      // range min & max
  230.             0,          // set an initial value
  231.             FALSE,      // Use the arrow mouse cursor
  232.             TRUE,       // Enable the mouse
  233.             hWnd,       // Parent window handle
  234.             SLIDER2,    // Slider ID value
  235.             hInst);     // This Program's instance
  236.  
  237.          // EDIT control to display Slider2's value
  238.          hSLEdit2 = CreateWindow(
  239.             "EDIT",
  240.             "0",
  241.             WS_CHILD | WS_VISIBLE | WS_BORDER | WS_DISABLED,
  242.             77,140,32,22,
  243.             hWnd,
  244.             SLEDIT2,
  245.             hInst,
  246.             NULL
  247.          );
  248.          wsprintf(cBuff,"%d",Slider2.GetVal());
  249.          SetWindowText(hSLEdit2,cBuff);
  250.  
  251.          // Create Slider3 on the Main windlow client area.
  252.          // This will be a horizontal, NON-reversed slider w/hand cursor
  253.          Slider3.Create(
  254.             SL_HORZ,   // Horizontal, Nonreversed Slider
  255.             "slface2", // Resource name for the Slider Face
  256.             "slknob2", // Resource name for the Slider Knob
  257.             140,50,    // Slider X,Y position within the main client window
  258.             6,         // Knob slide position
  259.             5,         // Knob upper limit position
  260.             60,        // Knob lower limit position
  261.             0,100,     // range min & max
  262.             0,         // set an initial value
  263.             TRUE,      // Use the hand mouse cursor
  264.             TRUE,      // Enable the mouse
  265.             hWnd,      // Parent window handle
  266.             SLIDER3,   // Slider ID value
  267.             hInst);    // This Program's instance
  268.  
  269.          // EDIT control to display Slider3's value
  270.          hSLEdit3 = CreateWindow(
  271.             "EDIT",
  272.             "0",
  273.             WS_CHILD | WS_VISIBLE | WS_BORDER | WS_DISABLED,
  274.             210,51,32,22,
  275.             hWnd,
  276.             SLEDIT3,
  277.             hInst,
  278.             NULL
  279.          );
  280.          wsprintf(cBuff,"%d",Slider3.GetVal());
  281.          SetWindowText(hSLEdit3,cBuff);
  282.  
  283.          // Create Slider4 on the Main windlow client area.
  284.          // This will be a horizontal, NON-reversed slider w/arrow cursor
  285.          // Use the same face and knob as Slider 3
  286.          Slider4.Create(
  287.             SL_HORZ | SL_REVERSED ,   // Horizontal, reversed Slider
  288.             "slface2", // Resource name for the Slider Face
  289.             "slknob2", // Resource name for the Slider Knob
  290.             140,110,   // Slider X,Y position within the main client window
  291.             6,         // Knob slide position
  292.             5,         // Knob upper limit position
  293.             60,        // Knob lower limit position
  294.             0,100,     // range min & max
  295.             0,         // set an initial value
  296.             FALSE,     // Use the hand mouse cursor
  297.             TRUE,      // Enable the mouse
  298.             hWnd,      // Parent window handle
  299.             SLIDER4,   // Slider ID value
  300.             hInst);    // This Program's instance
  301.  
  302.          // EDIT control to display Slider3's value
  303.          hSLEdit4 = CreateWindow(
  304.             "EDIT",
  305.             "0",
  306.             WS_CHILD | WS_VISIBLE | WS_BORDER | WS_DISABLED,
  307.             210,111,32,22,
  308.             hWnd,
  309.             SLEDIT4,
  310.             hInst,
  311.             NULL
  312.          );
  313.          wsprintf(cBuff,"%d",Slider4.GetVal());
  314.          SetWindowText(hSLEdit4,cBuff);
  315.  
  316.       break;  // end WM_CREATE
  317.  
  318.       case WM_PAINT:
  319.       {
  320.  
  321.          PAINTSTRUCT ps;
  322.  
  323.          //**********************************************************
  324.  
  325.          BeginPaint(hWnd,&ps);
  326.  
  327.          SetBkColor(ps.hdc,RGB(192,192,192));
  328.          TextOut(ps.hdc,5,5,"Slider 1",8);
  329.          TextOut(ps.hdc,70,5,"Slider 2",8);
  330.          TextOut(ps.hdc,150,30,"Slider 3",8);
  331.          TextOut(ps.hdc,150,90,"Slider 4",8);
  332.  
  333.          EndPaint(hWnd,&ps);
  334.  
  335.       }
  336.       break;  // end WM_PAINT
  337.  
  338.       case WM_COMMAND:
  339.  
  340.          switch (wParam)
  341.          {
  342.  
  343.  
  344.             // Here we handle the messages sent from Slider1
  345.             case SLIDER1:
  346.                wsprintf(cBuff,"%d",Slider1.GetVal());
  347.                SetWindowText(hSLEdit1,cBuff);
  348.             break;
  349.  
  350.             // Here we handle the messages sent from Slider2
  351.             case SLIDER2:
  352.                wsprintf(cBuff,"%d",Slider2.GetVal());
  353.                SetWindowText(hSLEdit2,cBuff);
  354.             break;
  355.  
  356.             // Here we handle the messages sent from Slider3
  357.             case SLIDER3:
  358.                wsprintf(cBuff,"%d",Slider3.GetVal());
  359.                SetWindowText(hSLEdit3,cBuff);
  360.             break;
  361.  
  362.             // Here we handle the messages sent from Slider4
  363.             case SLIDER4:
  364.                wsprintf(cBuff,"%d",Slider4.GetVal());
  365.                SetWindowText(hSLEdit4,cBuff);
  366.             break;
  367.  
  368.  
  369.             case IDM_ABOUT:
  370.             {
  371.  
  372.                FARPROC lpProcAbout; // pointer to the "About" function
  373.  
  374.                //****************************************************
  375.  
  376.                lpProcAbout = MakeProcInstance((FARPROC)About, hInst);
  377.  
  378.                DialogBox(hInst,
  379.                          "AboutBox",
  380.                          hWnd,
  381.                          lpProcAbout);
  382.  
  383.                FreeProcInstance(lpProcAbout);
  384.             }
  385.             break;
  386.  
  387.             case IDM_VGAUGE:
  388.             {
  389.  
  390.                FARPROC lpProcAbout; // pointer dialog function
  391.  
  392.                //****************************************************
  393.  
  394.                lpProcAbout = MakeProcInstance((FARPROC)VGaugeDialog1, hInst);
  395.  
  396.                DialogBox(hInst,
  397.                          "VGaugeDLG1",
  398.                          hWnd,
  399.                          lpProcAbout);
  400.  
  401.                FreeProcInstance(lpProcAbout);
  402.             }
  403.             break;
  404.  
  405.             case IDM_HGAUGE:
  406.             {
  407.  
  408.                FARPROC lpProcAbout; // pointer dialog function
  409.  
  410.                //****************************************************
  411.  
  412.                lpProcAbout = MakeProcInstance((FARPROC)HGaugeDialog2, hInst);
  413.  
  414.                DialogBox(hInst,
  415.                          "HGaugeDLG2",
  416.                          hWnd,
  417.                          lpProcAbout);
  418.  
  419.                FreeProcInstance(lpProcAbout);
  420.             }
  421.             break;
  422.  
  423.             case IDM_VTHERM:
  424.             {
  425.  
  426.                FARPROC lpProcAbout; // pointer dialog function
  427.  
  428.                //****************************************************
  429.  
  430.                lpProcAbout = MakeProcInstance((FARPROC)VThermDialog3, hInst);
  431.  
  432.                DialogBox(hInst,
  433.                          "VThermDLG3",
  434.                          hWnd,
  435.                          lpProcAbout);
  436.  
  437.                FreeProcInstance(lpProcAbout);
  438.             }
  439.             break;
  440.  
  441.             case IDM_HTHERM:
  442.             {
  443.  
  444.                FARPROC lpProcAbout; // pointer dialog function
  445.  
  446.                //****************************************************
  447.  
  448.                lpProcAbout = MakeProcInstance((FARPROC)HThermDialog4, hInst);
  449.  
  450.                DialogBox(hInst,
  451.                          "HThermDLG4",
  452.                          hWnd,
  453.                          lpProcAbout);
  454.  
  455.                FreeProcInstance(lpProcAbout);
  456.             }
  457.             break;
  458.  
  459.             case IDM_RVTHERM:
  460.             {
  461.  
  462.                FARPROC lpProcAbout; // pointer dialog function
  463.  
  464.                //****************************************************
  465.  
  466.                lpProcAbout = MakeProcInstance((FARPROC)RVThermDialog5, hInst);
  467.  
  468.                DialogBox(hInst,
  469.                          "RVThermDLG5",
  470.                          hWnd,
  471.                          lpProcAbout);
  472.  
  473.                FreeProcInstance(lpProcAbout);
  474.             }
  475.             break;
  476.  
  477.             case IDM_SLBANK:
  478.             {
  479.  
  480.                FARPROC lpProcAbout; // pointer dialog function
  481.  
  482.                //****************************************************
  483.  
  484.                lpProcAbout = MakeProcInstance((FARPROC)SLBankDialog6, hInst);
  485.  
  486.                DialogBox(hInst,
  487.                          "SLBankDLG6",
  488.                          hWnd,
  489.                          lpProcAbout);
  490.  
  491.                FreeProcInstance(lpProcAbout);
  492.             }
  493.             break;
  494.  
  495.  
  496.          } // end switch(wParam)
  497.  
  498.       break; // end WM_COMMAND
  499.  
  500.       case WM_DESTROY:                  // message: window being destroyed
  501.          PostQuitMessage(0);
  502.       break;
  503.  
  504.       default:   // Passes it on if unproccessed
  505.          return (DefWindowProc(hWnd, message, wParam, lParam));
  506.  
  507.    }
  508.  
  509.    return (NULL);
  510.  
  511. } // end MainWndProc
  512.  
  513. //***************************************************************************
  514. //
  515. //  FUNCTION: About(HWND, unsigned, WORD, LONG)
  516. //
  517. //  PURPOSE:  "About" dialog box
  518. //
  519. //***************************************************************************
  520. BOOL FAR PASCAL __export About(HWND     hDlg,
  521.                                unsigned message,
  522.                                WORD     wParam,
  523.                                LONG     lParam)
  524. {
  525.  
  526.    BOOL bRC;
  527.  
  528.    //****************************************************************
  529.  
  530.    bRC = TRUE;
  531.  
  532.    switch (message)
  533.    {
  534.  
  535.       case WM_INITDIALOG:
  536.       break;
  537.  
  538.       case WM_COMMAND:
  539.          switch (wParam)
  540.          {
  541.  
  542.             case IDOK:
  543.             case IDCANCEL:
  544.                EndDialog(hDlg,TRUE);
  545.             break;
  546.  
  547.          } // end switch(wParam)
  548.  
  549.       break;
  550.  
  551.       default:
  552.          bRC = FALSE;  // Didn't process a message
  553.  
  554.    } // end switch(message)
  555.  
  556.    return (bRC);
  557.  
  558. }  // end About
  559.  
  560. //***************************************************************************
  561. //
  562. //  FUNCTION: VGaugeDialog1(HWND, unsigned, WORD, LONG)
  563. //            Vertical Gauge
  564. //
  565. //***************************************************************************
  566. BOOL FAR PASCAL __export VGaugeDialog1(HWND     hDlg,
  567.                                        unsigned message,
  568.                                        WORD     wParam,
  569.                                        LONG     lParam)
  570. {
  571.  
  572.    BOOL bRC;
  573.  
  574.    //****************************************************************
  575.  
  576.    bRC = TRUE;
  577.  
  578.    switch (message)
  579.    {
  580.  
  581.       case WM_INITDIALOG:
  582.  
  583.          // Initialize the slider
  584.          SRCEntSLInit(
  585.             GetDlgItem(hDlg,D1SLIDER), // The Slider window handle
  586.             "slface3", // Resource name for the Slider Face
  587.             "slknob3", // Resource name for the Slider Knob
  588.             6,         // Knob slide position
  589.             5,         // Knob upper limit position
  590.             60,        // Knob lower limit position
  591.             0,100,     // range min & max
  592.             0,         // set an initial value
  593.             TRUE,      // Use the hand mouse cursor
  594.             TRUE       // Enable the mouse
  595.          );
  596.  
  597.          // Initialize the slider for use as a guage.
  598.          // Since this slider is used as gauge, there is no need
  599.          // to have an enabled mouse cursor.
  600.          SRCEntSLInit(
  601.             GetDlgItem(hDlg,D1GAUGE), // The Slider window handle
  602.             "gauge1f",  // Resource name for the Slider Face
  603.             "gauge1k",  // Resource name for the Slider Knob
  604.             2,          // Knob slide position
  605.             3,          // Knob upper limit position
  606.             111,        // Knob lower limit position
  607.             0,100,      // range min & max
  608.             0,          // set an initial value
  609.             FALSE,      // To use as a gauge; Use the mouse cursor
  610.             FALSE       // No need for an enabled mouse for gauges
  611.          );
  612.  
  613.       break; // end WM_INITDIALOG
  614.  
  615.       case WM_COMMAND:
  616.          switch (wParam)
  617.          {
  618.  
  619.             case D1SLIDER:  // Handle the Slider Message
  620.  
  621.                // Use the Slider value to set the Gauge Value
  622.                SRCEntSLSetVal(GetDlgItem(hDlg,D1GAUGE),
  623.                               SRCEntSLGetVal(GetDlgItem(hDlg,D1SLIDER)),
  624.                               TRUE);
  625.             break;
  626.  
  627.             case IDOK:
  628.             case IDCANCEL:
  629.                EndDialog(hDlg,TRUE);
  630.             break;
  631.  
  632.          } // end switch(wParam)
  633.  
  634.       break; // end WM_COMMAND
  635.  
  636.       case WM_PAINT:
  637.       {
  638.          PAINTSTRUCT ps;
  639.          RECT rect;
  640.  
  641.          //**********************************************************
  642.  
  643.          BeginPaint(hDlg,&ps);
  644.          GetClientRect(hDlg,&rect);
  645.  
  646.          //**** Paint the client area Light Gray *****
  647.          SelectObject(ps.hdc,GetStockObject(LTGRAY_BRUSH));
  648.          PatBlt(ps.hdc,0,0,rect.right,rect.bottom,PATCOPY);
  649.  
  650.          EndPaint(hDlg,&ps);
  651.  
  652.       };
  653.       break; // end WM_PAINT
  654.  
  655.       default:
  656.  
  657.          bRC = FALSE; // Didn't process a message
  658.  
  659.    } // end switch(message)
  660.  
  661.    return (bRC);
  662.  
  663. }  // end VGaugeDialog1
  664.  
  665. //***************************************************************************
  666. //
  667. //  FUNCTION: HGaugeDialog2(HWND, unsigned, WORD, LONG)
  668. //            Horizontal Gauge
  669. //
  670. //***************************************************************************
  671. BOOL FAR PASCAL __export HGaugeDialog2(HWND     hDlg,
  672.                                        unsigned message,
  673.                                        WORD     wParam,
  674.                                        LONG     lParam)
  675. {
  676.  
  677.    BOOL bRC;
  678.  
  679.    //****************************************************************
  680.  
  681.    bRC = TRUE;
  682.  
  683.    switch (message)
  684.    {
  685.  
  686.       case WM_INITDIALOG:
  687.  
  688.          // Initialize the slider
  689.          SRCEntSLInit(
  690.             GetDlgItem(hDlg,D2SLIDER), // The Slider window handle
  691.             "slface2", // Resource name for the Slider Face
  692.             "slknob2", // Resource name for the Slider Knob
  693.             6,         // Knob slide position
  694.             5,         // Knob upper limit position
  695.             60,        // Knob lower limit position
  696.             0,100,     // range min & max
  697.             0,         // set an initial value
  698.             TRUE,      // Use the hand mouse cursor
  699.             TRUE       // Enable the mouse
  700.          );
  701.  
  702.          // Initialize the slider for use as a guage.
  703.          // Since this slider is used as gauge, there is no need
  704.          // to have an enabled mouse cursor.
  705.          SRCEntSLInit(
  706.             GetDlgItem(hDlg,D2GAUGE), // The Slider window handle
  707.             "gauge2f",  // Resource name for the Slider Face
  708.             "gauge2k",  // Resource name for the Slider Knob
  709.             20,         // Knob slide position
  710.             8,          // Knob upper limit position
  711.             109,        // Knob lower limit position
  712.             0,100,      // range min & max
  713.             0,          // set an initial value
  714.             FALSE,      // To use as a gauge; Use the mouse cursor
  715.             FALSE       // No need for an enabled mouse for gauges
  716.          );
  717.  
  718.       break; // end WM_INITDIALOG
  719.  
  720.       case WM_COMMAND:
  721.          switch (wParam)
  722.          {
  723.  
  724.             case D2SLIDER:  // Handle the Slider Message
  725.  
  726.                // Use the Slider value to set the Gauge Value
  727.                SRCEntSLSetVal(GetDlgItem(hDlg,D2GAUGE),
  728.                               SRCEntSLGetVal(GetDlgItem(hDlg,D2SLIDER)),
  729.                               TRUE);
  730.             break;
  731.  
  732.             case IDOK:
  733.             case IDCANCEL:
  734.                EndDialog(hDlg,TRUE);
  735.             break;
  736.  
  737.          } // end switch(wParam)
  738.  
  739.       break; // end WM_COMMAND
  740.  
  741.       case WM_PAINT:
  742.       {
  743.          PAINTSTRUCT ps;
  744.          RECT rect;
  745.  
  746.          //**********************************************************
  747.  
  748.          BeginPaint(hDlg,&ps);
  749.          GetClientRect(hDlg,&rect);
  750.  
  751.          //**** Paint the client area Light Gray *****
  752.          SelectObject(ps.hdc,GetStockObject(LTGRAY_BRUSH));
  753.          PatBlt(ps.hdc,0,0,rect.right,rect.bottom,PATCOPY);
  754.  
  755.          EndPaint(hDlg,&ps);
  756.  
  757.       };
  758.       break; // end WM_PAINT
  759.  
  760.       default:
  761.          bRC = FALSE; // Didn't process a message
  762.  
  763.    } // end switch(message)
  764.  
  765.    return (bRC);
  766.  
  767. }  // end HGaugeDialog2
  768.  
  769. //***************************************************************************
  770. //
  771. //  FUNCTION: VThermDialog3(HWND, unsigned, WORD, LONG)
  772. //            Vertical Thermometer Style Guage
  773. //
  774. //***************************************************************************
  775. BOOL FAR PASCAL __export VThermDialog3(HWND     hDlg,
  776.                                        unsigned message,
  777.                                        WORD     wParam,
  778.                                        LONG     lParam)
  779. {
  780.  
  781.    BOOL bRC;
  782.  
  783.    //****************************************************************
  784.  
  785.    bRC = TRUE;
  786.  
  787.    switch (message)
  788.    {
  789.  
  790.       case WM_INITDIALOG:
  791.  
  792.          // Initialize the slider
  793.          SRCEntSLInit(
  794.             GetDlgItem(hDlg,D3SLIDER), // The Slider window handle
  795.             "slface3", // Resource name for the Slider Face
  796.             "slknob3", // Resource name for the Slider Knob
  797.             6,         // Knob slide position
  798.             5,         // Knob upper limit position
  799.             60,        // Knob lower limit position
  800.             0,100,     // range min & max
  801.             0,         // set an initial value
  802.             TRUE,      // Use the hand mouse cursor
  803.             TRUE       // Enable the mouse
  804.          );
  805.  
  806.          // Initialize the slider for use as a thermometer guage.
  807.          // Since this slider is used as gauge, there is no need
  808.          // to have an enabled mouse cursor.
  809.          SRCEntSLInit(
  810.             GetDlgItem(hDlg,D3THERM), // The Slider window handle
  811.             "therm5f",  // Resource name for the Slider Face
  812.             "therm5k",  // Resource name for the Slider Knob
  813.             5,          // Knob slide position
  814.             7,          // Knob upper limit position
  815.             107,        // Knob lower limit position
  816.             0,100,      // range min & max
  817.             0,          // set an initial value
  818.             FALSE,      // To use as a gauge; Use the mouse cursor
  819.             FALSE       // No need for an enabled mouse for gauges
  820.          );
  821.  
  822.       break; // end WM_INITDIALOG
  823.  
  824.       case WM_COMMAND:
  825.          switch (wParam)
  826.          {
  827.  
  828.             case D3SLIDER:  // Handle the Slider Message
  829.  
  830.                // Use the Slider value to set the Gauge Value
  831.                SRCEntSLSetVal(GetDlgItem(hDlg,D3THERM),
  832.                               SRCEntSLGetVal(GetDlgItem(hDlg,D3SLIDER)),
  833.                               TRUE);
  834.             break;
  835.  
  836.             case IDOK:
  837.             case IDCANCEL:
  838.                EndDialog(hDlg,TRUE);
  839.             break;
  840.  
  841.          } // end switch(wParam)
  842.  
  843.       break; // end WM_COMMAND
  844.  
  845.       case WM_PAINT:
  846.       {
  847.          PAINTSTRUCT ps;
  848.          RECT rect;
  849.  
  850.          //**********************************************************
  851.  
  852.          BeginPaint(hDlg,&ps);
  853.          GetClientRect(hDlg,&rect);
  854.  
  855.          //**** Paint the client area Light Gray *****
  856.          SelectObject(ps.hdc,GetStockObject(LTGRAY_BRUSH));
  857.          PatBlt(ps.hdc,0,0,rect.right,rect.bottom,PATCOPY);
  858.  
  859.          EndPaint(hDlg,&ps);
  860.  
  861.       };
  862.       break; // end WM_PAINT
  863.  
  864.       default:
  865.          bRC = FALSE; // Didn't process a message
  866.  
  867.    } // end switch(message)
  868.  
  869.    return (bRC);
  870.  
  871. }  // end VThermDialog3
  872.  
  873. //***************************************************************************
  874. //
  875. //  FUNCTION: HThermDialog4(HWND, unsigned, WORD, LONG)
  876. //            Horizontal Thermometer Style Gauge
  877. //
  878. //***************************************************************************
  879. BOOL FAR PASCAL __export HThermDialog4(HWND     hDlg,
  880.                                        unsigned message,
  881.                                        WORD     wParam,
  882.                                        LONG     lParam)
  883. {
  884.  
  885.    BOOL bRC;
  886.  
  887.    //****************************************************************
  888.  
  889.    bRC = TRUE;
  890.  
  891.    switch (message)
  892.    {
  893.  
  894.       case WM_INITDIALOG:
  895.  
  896.          // Initialize the slider
  897.          SRCEntSLInit(
  898.             GetDlgItem(hDlg,D4SLIDER), // The Slider window handle
  899.             "slface2", // Resource name for the Slider Face
  900.             "slknob2", // Resource name for the Slider Knob
  901.             6,         // Knob slide position
  902.             5,         // Knob upper limit position
  903.             60,        // Knob lower limit position
  904.             0,100,     // range min & max
  905.             0,         // set an initial value
  906.             TRUE,      // Use the hand mouse cursor
  907.             TRUE       // Enable the mouse
  908.          );
  909.  
  910.          // Initialize the slider for use as a thermometer guage.
  911.          // Since this slider is used as gauge, there is no need
  912.          // to have an enabled mouse cursor.
  913.          SRCEntSLInit(
  914.             GetDlgItem(hDlg,D4THERM), // The Slider window handle
  915.             "therm1f",  // Resource name for the Slider Face
  916.             "therm1k",  // Resource name for the Slider Knob
  917.             20,         // Knob slide position
  918.             9,          // Knob upper limit position
  919.             109,        // Knob lower limit position
  920.             0,100,      // range min & max
  921.             0,          // set an initial value
  922.             FALSE,      // To use as a gauge; Use the mouse cursor
  923.             FALSE       // No need for an enabled mouse for gauges
  924.          );
  925.  
  926.       break; // end WM_INITDIALOG
  927.  
  928.       case WM_COMMAND:
  929.          switch (wParam)
  930.          {
  931.  
  932.             case D4SLIDER:  // Handle the Slider Message
  933.  
  934.                // Use the Slider value to set the Gauge Value
  935.                SRCEntSLSetVal(GetDlgItem(hDlg,D4THERM),
  936.                               SRCEntSLGetVal(GetDlgItem(hDlg,D4SLIDER)),
  937.                               TRUE);
  938.             break;
  939.  
  940.             case IDOK:
  941.             case IDCANCEL:
  942.                EndDialog(hDlg,TRUE);
  943.             break;
  944.  
  945.          } // end switch(wParam)
  946.  
  947.       break; // end WM_COMMAND
  948.  
  949.       case WM_PAINT:
  950.       {
  951.          PAINTSTRUCT ps;
  952.          RECT rect;
  953.  
  954.          //**********************************************************
  955.  
  956.          BeginPaint(hDlg,&ps);
  957.          GetClientRect(hDlg,&rect);
  958.  
  959.          //**** Paint the client area Light Gray *****
  960.          SelectObject(ps.hdc,GetStockObject(LTGRAY_BRUSH));
  961.          PatBlt(ps.hdc,0,0,rect.right,rect.bottom,PATCOPY);
  962.  
  963.          EndPaint(hDlg,&ps);
  964.  
  965.       };
  966.       break; // end WM_PAINT
  967.  
  968.       default:
  969.          bRC = FALSE; // Didn't process a message
  970.  
  971.    } // end switch(message)
  972.  
  973.    return (bRC);
  974.  
  975. }  // end HThermDialog4
  976.  
  977. //***************************************************************************
  978. //
  979. //  FUNCTION: RVThermDialog5(HWND, unsigned, WORD, LONG)
  980. //            Reversed Vertical Thermometer Style Guage
  981. //
  982. //***************************************************************************
  983. BOOL FAR PASCAL __export RVThermDialog5(HWND     hDlg,
  984.                                         unsigned message,
  985.                                         WORD     wParam,
  986.                                         LONG     lParam)
  987. {
  988.  
  989.    BOOL bRC;
  990.  
  991.    //****************************************************************
  992.  
  993.    bRC = TRUE;
  994.  
  995.    switch (message)
  996.    {
  997.  
  998.       case WM_INITDIALOG:
  999.  
  1000.          // Initialize the slider
  1001.          SRCEntSLInit(
  1002.             GetDlgItem(hDlg,D5SLIDER), // The Slider window handle
  1003.             "slface4", // Resource name for the Slider Face
  1004.             "slknob4", // Resource name for the Slider Knob
  1005.             6,         // Knob slide position
  1006.             5,         // Knob upper limit position
  1007.             109,       // Knob lower limit position
  1008.             0,100,     // range min & max
  1009.             0,         // set an initial value
  1010.             TRUE,      // Use the hand mouse cursor
  1011.             TRUE       // Enable the mouse
  1012.          );
  1013.  
  1014.          // Initialize the slider for use as a thermometer guage.
  1015.          // Since this slider is used as gauge, there is no need
  1016.          // to have an enabled mouse cursor.
  1017.          SRCEntSLInit(
  1018.             GetDlgItem(hDlg,D5THERM), // The Slider window handle
  1019.             "therm2f",  // Resource name for the Slider Face
  1020.             "therm2k",  // Resource name for the Slider Knob
  1021.             6,          // Knob slide position
  1022.             9,          // Knob upper limit position
  1023.             109,        // Knob lower limit position
  1024.             0,100,      // range min & max
  1025.             0,          // set an initial value
  1026.             FALSE,      // To use as a gauge; Use the mouse cursor
  1027.             FALSE       // No need for an enabled mouse for gauges
  1028.          );
  1029.  
  1030.       break; // end WM_INITDIALOG
  1031.  
  1032.       case WM_COMMAND:
  1033.          switch (wParam)
  1034.          {
  1035.  
  1036.             case D5SLIDER:  // Handle the Slider Message
  1037.  
  1038.                // Use the Slider value to set the Gauge Value
  1039.                SRCEntSLSetVal(GetDlgItem(hDlg,D5THERM),
  1040.                               SRCEntSLGetVal(GetDlgItem(hDlg,D5SLIDER)),
  1041.                               TRUE);
  1042.             break;
  1043.  
  1044.             case IDOK:
  1045.             case IDCANCEL:
  1046.                EndDialog(hDlg,TRUE);
  1047.             break;
  1048.  
  1049.          } // end switch(wParam)
  1050.  
  1051.       break; // end WM_COMMAND
  1052.  
  1053.       case WM_PAINT:
  1054.       {
  1055.          PAINTSTRUCT ps;
  1056.          RECT rect;
  1057.  
  1058.          //**********************************************************
  1059.  
  1060.          BeginPaint(hDlg,&ps);
  1061.          GetClientRect(hDlg,&rect);
  1062.  
  1063.          //**** Paint the client area Light Gray *****
  1064.          SelectObject(ps.hdc,GetStockObject(GRAY_BRUSH));
  1065.          PatBlt(ps.hdc,0,0,rect.right,rect.bottom,PATCOPY);
  1066.  
  1067.          EndPaint(hDlg,&ps);
  1068.  
  1069.       };
  1070.       break; // end WM_PAINT
  1071.  
  1072.       default:
  1073.          bRC = FALSE; // Didn't process a message
  1074.  
  1075.    } // end switch(message)
  1076.  
  1077.    return (bRC);
  1078.  
  1079. }  // end RVThermDialog5
  1080.  
  1081. //***************************************************************************
  1082. //
  1083. //  FUNCTION: SLBankDialog6(HWND, unsigned, WORD, LONG)
  1084. //            Bank of Slider2
  1085. //
  1086. //  We can use the Slider Class in this dialog since the Sliders are not
  1087. //  being created with CONTROL statements in the dialog's resource.
  1088. //
  1089. //***************************************************************************
  1090. BOOL FAR PASCAL __export SLBankDialog6(HWND     hDlg,
  1091.                                        unsigned message,
  1092.                                        WORD     wParam,
  1093.                                        LONG     lParam)
  1094.  
  1095. {
  1096.  
  1097.    BOOL bRC;
  1098.                             
  1099.    // Declare instances of Slider Class                        
  1100.    static CSRCEntSL Slider1, Slider2, Slider3, Slider4;
  1101.  
  1102.    //**********************************************************************
  1103.  
  1104.    bRC = TRUE;
  1105.  
  1106.    switch (message)
  1107.    {
  1108.  
  1109.       case WM_INITDIALOG:
  1110.       {
  1111.  
  1112.          HBITMAP hlface1, hmface1, hrface1;
  1113.          BITMAP  BMInfo;
  1114.  
  1115.          int rfw, mfw, lfw;    // width face bitmaps
  1116.  
  1117.          //***********************************************************
  1118.  
  1119.          // Before the Sliders are created, we need to load the face
  1120.          // bitmaps and get the their widths
  1121.          hlface1  = LoadBitmap(hInst,"lface1");
  1122.          hmface1  = LoadBitmap(hInst,"mface1");
  1123.          hrface1  = LoadBitmap(hInst,"rface1");
  1124.  
  1125.          // Get widths of face bitmaps
  1126.          GetObject(hlface1,sizeof(BITMAP),(LPSTR)&BMInfo);
  1127.          lfw = BMInfo.bmWidth;
  1128.          GetObject(hmface1,sizeof(BITMAP),(LPSTR)&BMInfo);
  1129.          mfw = BMInfo.bmWidth;
  1130.          GetObject(hrface1,sizeof(BITMAP),(LPSTR)&BMInfo);
  1131.          rfw = BMInfo.bmWidth;
  1132.  
  1133.          // Now Delete them
  1134.          DeleteObject(hlface1);
  1135.          DeleteObject(hmface1);
  1136.          DeleteObject(hrface1);
  1137.  
  1138.          // Now we create the sliders
  1139.  
  1140.          // The reason for using the Class Create() function to create
  1141.          // the slider windows rather than the CONTROL statement in the
  1142.          // resource file is because the CONTROL statement position and
  1143.          // size values use dialog box units, thus the sliders cannot be
  1144.          // positioned with pixel precision as is necessary here.
  1145.  
  1146.          // To make the slider bank appear as they do, there is a bitmap
  1147.          // for the left side Slider, the middle Sliders and the right
  1148.          // side Slider, then they are positioned to butt up next to
  1149.          // eack other.
  1150.  
  1151.          Slider1.Create(
  1152.             NULL,                   // Slider Style
  1153.             "lface1",               // Resource name for the Slider Face
  1154.             "knob2",                // Resource name for the Slider Knob
  1155.             SLIDERSX,               // Slider X Position
  1156.             SLIDERSY,               // Slider Y Position
  1157.             7,                      // Knob slide position
  1158.             5,                      // Knob upper limit position
  1159.             110,                    // Knob lower limit position
  1160.             0,100,                  // range min & max
  1161.             0,                      // set an initial value
  1162.             TRUE,                   // Use the hand mouse cursor
  1163.             TRUE,                   // Enable the mouse
  1164.             hDlg,                   // Parent window handle
  1165.             D6SLIDER1,              // Slider ID value
  1166.             hInst);                 // This Program's instance
  1167.  
  1168.          Slider2.Create(
  1169.             NULL,                   // Slider Style
  1170.             "mface1",               // Resource name for the Slider Face
  1171.             "knob2",                // Resource name for the Slider Knob
  1172.             SLIDERSX+lfw,           // Slider X Position
  1173.             SLIDERSY,               // Slider Y Position
  1174.             4,                      // Knob slide position
  1175.             5,                      // Knob upper limit position
  1176.             110,                    // Knob lower limit position
  1177.             0,100,                  // range min & max
  1178.             0,                      // set an initial value
  1179.             TRUE,                   // Use the hand mouse cursor
  1180.             TRUE,                   // Enable the mouse
  1181.             hDlg,                   // Parent window handle
  1182.             D6SLIDER2,              // Slider ID value
  1183.             hInst);                 // This Program's instance
  1184.  
  1185.          Slider3.Create(
  1186.             NULL,                   // Slider Style
  1187.             "mface1",               // Resource name for the Slider Face
  1188.             "knob2",                // Resource name for the Slider Knob
  1189.             SLIDERSX+lfw+mfw,       // Slider X Position
  1190.             SLIDERSY,               // Slider Y Position
  1191.             4,                      // Knob slide position
  1192.             5,                      // Knob upper limit position
  1193.             110,                    // Knob lower limit position
  1194.             0,100,                  // range min & max
  1195.             0,                      // set an initial value
  1196.             TRUE,                   // Use the hand mouse cursor
  1197.             TRUE,                   // Enable the mouse
  1198.             hDlg,                   // Parent window handle
  1199.             D6SLIDER3,              // Slider ID value
  1200.             hInst);                 // This Program's instance
  1201.  
  1202.          Slider4.Create(
  1203.             NULL,                   // Slider Style
  1204.             "rface1",               // Resource name for the Slider Face
  1205.             "knob2",                // Resource name for the Slider Knob
  1206.             SLIDERSX+lfw+(2*mfw),   // Slider X Position
  1207.             SLIDERSY,               // Slider Y Position
  1208.             4,                      // Knob slide position
  1209.             5,                      // Knob upper limit position
  1210.             110,                    // Knob lower limit position
  1211.             0,100,                  // range min & max
  1212.             0,                      // set an initial value
  1213.             TRUE,                   // Use the hand mouse cursor
  1214.             TRUE,                   // Enable the mouse
  1215.             hDlg,                   // Parent window handle
  1216.             D6SLIDER4,              // Slider ID value
  1217.             hInst);                 // This Program's instance
  1218.  
  1219.  
  1220.          // Init the EDIT controls that display the Slider values
  1221.          wsprintf(cBuff,"%d",Slider1.GetVal());
  1222.          SetDlgItemText(hDlg,D6EDIT1,cBuff);
  1223.  
  1224.          wsprintf(cBuff,"%d",Slider2.GetVal());
  1225.          SetDlgItemText(hDlg,D6EDIT2,cBuff);
  1226.  
  1227.          wsprintf(cBuff,"%d",Slider3.GetVal());
  1228.          SetDlgItemText(hDlg,D6EDIT3,cBuff);
  1229.  
  1230.          wsprintf(cBuff,"%d",Slider4.GetVal());
  1231.          SetDlgItemText(hDlg,D6EDIT4,cBuff);
  1232.  
  1233.       }
  1234.       break; // end WM_INITDIALOG
  1235.  
  1236.       case WM_COMMAND:
  1237.          switch (wParam)
  1238.          {
  1239.  
  1240.             case D6SLIDER1:
  1241.                  wsprintf(cBuff,"%d",Slider1.GetVal());
  1242.                  SetDlgItemText(hDlg,D6EDIT1,cBuff);
  1243.             break;
  1244.  
  1245.             case D6SLIDER2:
  1246.                  wsprintf(cBuff,"%d",Slider2.GetVal());
  1247.                  SetDlgItemText(hDlg,D6EDIT2,cBuff);
  1248.             break;
  1249.  
  1250.             case D6SLIDER3:
  1251.                  wsprintf(cBuff,"%d",Slider3.GetVal());
  1252.                  SetDlgItemText(hDlg,D6EDIT3,cBuff);
  1253.             break;
  1254.  
  1255.             case D6SLIDER4:
  1256.                  wsprintf(cBuff,"%d",Slider4.GetVal());
  1257.                  SetDlgItemText(hDlg,D6EDIT4,cBuff);
  1258.             break;
  1259.  
  1260.             case IDOK:
  1261.             case IDCANCEL:
  1262.                EndDialog(hDlg,TRUE);
  1263.             break;
  1264.  
  1265.          } // end switch(wParam)
  1266.  
  1267.       break; // end WM_COMMAND
  1268.  
  1269.       case WM_PAINT:
  1270.       {
  1271.          PAINTSTRUCT ps;
  1272.          RECT rect;
  1273.  
  1274.          //******************************************************
  1275.  
  1276.          BeginPaint(hDlg,&ps);
  1277.          GetClientRect(hDlg,&rect);
  1278.  
  1279.          //**** Paint the client area Light Gray
  1280.          SelectObject(ps.hdc,GetStockObject(LTGRAY_BRUSH));
  1281.          PatBlt(ps.hdc,0,0,rect.right,rect.bottom,PATCOPY);
  1282.  
  1283.  
  1284.          // Label the Sliders
  1285.          SetBkColor(ps.hdc,RGB(192,192,192));
  1286.          TextOut(ps.hdc,20,7,"1",1);
  1287.          TextOut(ps.hdc,44,7,"2",1);
  1288.          TextOut(ps.hdc,68,7,"3",1);
  1289.          TextOut(ps.hdc,92,7,"4",1);
  1290.  
  1291.          EndPaint(hDlg,&ps);
  1292.  
  1293.       };
  1294.       break; // end WM_PAINT
  1295.  
  1296.       default:
  1297.          bRC = FALSE; // Didn't process a message
  1298.  
  1299.    } // end switch(message)
  1300.  
  1301.    return (bRC);
  1302.  
  1303. }  // end SLBankDialog6
  1304.