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

  1. //***************************************************************************
  2. //
  3. //  Program   : SLDEMO3.CPP
  4. //
  5. //  Programmer: Steven R Clabaugh
  6. //              SRC Enterprises
  7. //
  8. //  Purpose   : Bare-bones Windows MFC application used to demonstrate
  9. //              Slider Control Class.
  10. //              Does not use a VIEW class or a DOCUMENT class.
  11. //
  12. //***************************************************************************
  13. #include <afxwin.h>
  14. #include <srcentsl.h>
  15. #include "resource.h"
  16. #include "sldemo3.h"
  17.  
  18. //***************************************************************************
  19. //***************************************************************************
  20. // Implementation for the application class 'CTheApp'
  21. //***************************************************************************
  22. //***************************************************************************
  23.  
  24. //***************************************************************************
  25. //
  26. //  Application Class 'InitApplication' member function
  27. //
  28. //***************************************************************************
  29. BOOL CTheApp::InitApplication()
  30. {
  31.  
  32.    // The reason we register a window class is to provide the ability to set
  33.    // the client area to the color of our choice.
  34.    // The class name is returned in the application class m_ClassName
  35.    // data member and passed to the CMainWnd class's contructor within the
  36.    // InitInstance function.
  37.    m_WndClassName = AfxRegisterWndClass(
  38.                        NULL,                               // Class Style
  39.                        LoadStandardCursor(IDC_ARROW),      // Cursor
  40.                        CreateSolidBrush(RGB(192,192,192)), // Client Area Color
  41.                        LoadIcon(AFX_IDI_STD_FRAME)         // Application Icon
  42.                  );
  43.  
  44.    return TRUE;
  45.  
  46. } // End CTheApp::InitApplication
  47.  
  48. //***************************************************************************
  49. //
  50. //  Application Class 'InitInstance' member function
  51. //
  52. //  Creates and shows the main window
  53. //
  54. //***************************************************************************
  55. BOOL CTheApp::InitInstance()
  56. {
  57.  
  58.    //  Declare the Application's Main Window object
  59.    //    and call its constructor
  60.    m_pMainWnd = new CMainWnd(m_WndClassName);
  61.  
  62.    // Make the window visable; Update its client area; return successfull
  63.    m_pMainWnd->ShowWindow(m_nCmdShow);   // Show the window
  64.    m_pMainWnd->UpdateWindow();           // Sends WM_PAINT Msg
  65.    return TRUE;
  66.  
  67. } // End CTheApp::InitInstance
  68.  
  69. //**** End Application Class Implementation *********************************
  70. //***************************************************************************
  71. //***************************************************************************
  72.  
  73. //***************************************************************************
  74. //***************************************************************************
  75. // Implementation for the application's Main Window class 'CMainWnd'
  76. //***************************************************************************
  77. //***************************************************************************
  78.  
  79. //***************************************************************************
  80. //
  81. //  CMainWnd Class Constructor
  82. //
  83. //***************************************************************************
  84. CMainWnd::CMainWnd(CString WndClassName)
  85. {
  86.  
  87.    // Create the Main Window
  88.    Create(WndClassName,                  // Window Class Name
  89.           AfxGetAppName(),               // Text for Window Title Bar
  90.           WS_OVERLAPPEDWINDOW,           // Window Style
  91.           CRect(10,10,270,190),          // Window Position and Size
  92.           NULL,                          // Overlapped Windows have no Parent
  93.           "MAINMENU",                    // Main Menu Resource Name
  94.           0,                             // No Extened style attributes
  95.           NULL                           // Pointer Not Needed
  96.          );
  97.  
  98. } // End CMainWnd::CMainWnd Class Constructor
  99.  
  100. //***************************************************************************
  101. //
  102. //  Create the message map for the main window procedure
  103. //
  104. //***************************************************************************
  105. BEGIN_MESSAGE_MAP(CMainWnd, CFrameWnd)
  106.    //{{AFX_MSG_MAP(CMainWnd)
  107.    ON_COMMAND(ID_APP_ABOUT,OnAbout)
  108.    ON_COMMAND(IDSL_MYSLIDER,OnMySlider)
  109.    ON_WM_CREATE()
  110.    //}}AFX_MSG_MAP
  111. END_MESSAGE_MAP()
  112.  
  113. //**** End Message Map ******************************************************
  114.  
  115. //***************************************************************************
  116. //
  117. //  Main Window WM_CREATE Message Handler
  118. //
  119. //***************************************************************************
  120. int CMainWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
  121. {
  122.  
  123.  
  124.    // One note to make here, is that the last 3 parms in the Create
  125.    // function must be type cast to UINT when programming with MFC
  126.    // style programming. 
  127.  
  128.    m_MySlider.Create(
  129.       NULL,                              // Slider Style
  130.       (LPSTR)IDB_SLFACE1,                // Slider Face
  131.       (LPSTR)IDB_SLKNOB1,                // Slider Knob
  132.       50,14,                             // Slider Position
  133.       6,                                 // Knob Slide position
  134.       6,                                 // Knob upper limit position
  135.       99,                                // Knob lower limit position
  136.       0,100,                             // range min & max
  137.       0,                                 // set a value
  138.       TRUE,                              // Use a hand mouse cursor
  139.       TRUE,                              // Enable the mouse
  140.       (UINT)m_hWnd,                      // Parent window handle
  141.       (UINT)IDSL_MYSLIDER,               // Slider ID value
  142.       (UINT)AfxGetInstanceHandle()       // Program instance
  143.    );
  144.  
  145.    m_MyGauge.Create(
  146.       NULL,                              // Slider Style
  147.       (LPSTR)IDB_GAUGE3F,                // Slider Face
  148.       (LPSTR)IDB_GAUGE3K,                // Slider Knob
  149.       150,10,                            // Slider Position
  150.       5,                                 // Knob Slide position
  151.       5,                                 // Knob upper limit position
  152.       109,                               // Knob lower limit position
  153.       0,100,                             // range min & max
  154.       0,                                 // set a value
  155.       FALSE,                             // Use a hand mouse cursor
  156.       FALSE,                             // Disable the mouse
  157.       (UINT)m_hWnd,                      // Parent window handle
  158.       (UINT)IDSL_MYGAUGE,                // Slider ID value
  159.       (UINT)AfxGetInstanceHandle()       // Program instance
  160.    );
  161.  
  162.    m_MyGauge.SetVal(m_MySlider.GetVal(),TRUE);
  163.    return 0;
  164.  
  165. }  // END WM_CREATE
  166.  
  167. //***************************************************************************
  168. //
  169. //  Main Window WM_COMMAMD:ID_ABOUT Command Message Handler
  170. //
  171. //***************************************************************************
  172. void CMainWnd::OnAbout()
  173. {
  174.  
  175.    CDialog about(IDD_ABOUTBOX);
  176.    about.DoModal();
  177.  
  178. } // End CMainWnd::OnAbout
  179.  
  180. //***************************************************************************
  181. //
  182. //  Main Window WM_COMMAMD:MYSLIDER Command Message Handler
  183. //
  184. //***************************************************************************
  185. void CMainWnd::OnMySlider()
  186. {
  187.  
  188.    // Set the Gauge to the value of the Slider
  189.    m_MyGauge.SetVal(m_MySlider.GetVal(),TRUE);
  190.  
  191. } // End CMainWnd::OnMySlider
  192.  
  193. //**** End Application's Main Window Class Implementation *******************
  194. //***************************************************************************
  195. //***************************************************************************
  196.  
  197. //***************************************************************************
  198. //***************************************************************************
  199. // Begin Application Execution
  200. //***************************************************************************
  201. //***************************************************************************
  202.  
  203. //***************************************************************************
  204. //
  205. //  Global Data
  206. //
  207. //***************************************************************************
  208.  
  209. // By declaring a global application object, the whole application runs
  210. CTheApp NEAR theApp;
  211.