home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / mslang / vcslid / msfc / slidevw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-03  |  7.1 KB  |  293 lines

  1. // slidevw.cpp : implementation of the CSlidetstView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "slidetst.h"
  6.  
  7. #include "slidedoc.h"
  8. #include "cslider.h"
  9. #include "slidevw.h"
  10. #include "range.h"
  11.  
  12. #ifdef _DEBUG
  13. #undef THIS_FILE
  14. static char BASED_CODE THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CSlidetstView
  19.  
  20. IMPLEMENT_DYNCREATE(CSlidetstView, CView)
  21.  
  22. BEGIN_MESSAGE_MAP(CSlidetstView, CView)
  23.     //{{AFX_MSG_MAP(CSlidetstView)
  24.     ON_WM_CREATE()
  25.     ON_WM_DESTROY()
  26.     ON_WM_HSCROLL()
  27.     ON_WM_VSCROLL()
  28.     ON_WM_CTLCOLOR()
  29.     ON_COMMAND(IDM_SETHPOS, OnSethpos)
  30.     ON_COMMAND(IDM_SETHRANGE, OnSethrange)
  31.     ON_COMMAND(IDM_SETVPOS, OnSetvpos)
  32.     ON_COMMAND(IDM_SETVRANGE, OnSetvrange)
  33.     ON_COMMAND(IDM_ENABLEVERT, OnEnablevert)
  34.     ON_COMMAND(IDM_ENABLEHORZ, OnEnablehorz)
  35.     ON_COMMAND(IDM_DISABLEVERT, OnDisablevert)
  36.     ON_COMMAND(IDM_DISABLEHORZ, OnDisablehorz)
  37.     ON_COMMAND(IDM_SETHPOS, OnSethpos)
  38.     ON_COMMAND(IDM_GETHRANGE, OnGethrange)
  39.     ON_COMMAND(IDM_GETVRANGE, OnGetvrange)
  40.     //}}AFX_MSG_MAP
  41.     // Standard printing commands
  42.     ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  43.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  44. END_MESSAGE_MAP()
  45.  
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CSlidetstView construction/destruction
  48.  
  49. CSlidetstView::CSlidetstView()
  50. {  
  51.  
  52. }
  53.  
  54. CSlidetstView::~CSlidetstView()
  55. {
  56. }
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CSlidetstView drawing
  60.  
  61. HBRUSH CSlidetstView::OnCtlColor(CDC* dc, CWnd*, UINT)
  62. {                               
  63.     //Paint the control grey
  64.     dc->SetBkColor(RGB(192,192,192));    
  65.     
  66.     return NULL;
  67. }
  68.  
  69.  
  70. void CSlidetstView::OnDraw(CDC* pDC)
  71. {
  72.     CSlidetstDoc* pDoc = GetDocument();
  73.  
  74.     // TODO: add draw code here
  75. }
  76.  
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CSlidetstView printing
  79.  
  80. BOOL CSlidetstView::OnPreparePrinting(CPrintInfo* pInfo)
  81. {
  82.     // default preparation
  83.     return DoPreparePrinting(pInfo);
  84. }
  85.  
  86. void CSlidetstView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  87. {
  88.     // TODO: add extra initialization before printing
  89. }
  90.  
  91. void CSlidetstView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  92. {
  93.     // TODO: add cleanup after printing
  94. }
  95.  
  96.  
  97.  
  98.  
  99. /////////////////////////////////////////////////////////////////////////////
  100. // CSlidetstView diagnostics
  101.  
  102. #ifdef _DEBUG
  103. void CSlidetstView::AssertValid() const
  104. {
  105.     CView::AssertValid();
  106. }
  107.  
  108. void CSlidetstView::Dump(CDumpContext& dc) const
  109. {
  110.     CView::Dump(dc);
  111. }
  112.  
  113. CSlidetstDoc* CSlidetstView::GetDocument() // non-debug version is inline
  114. {
  115.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSlidetstDoc)));
  116.     return (CSlidetstDoc*) m_pDocument;
  117. }
  118.  
  119. #endif //_DEBUG
  120.  
  121. /////////////////////////////////////////////////////////////////////////////
  122. // CSlidetstView message handlers
  123.  
  124. int CSlidetstView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  125. {
  126.     if (CView::OnCreate(lpCreateStruct) == -1)
  127.         return -1;
  128.     
  129.     // Create a vertical slider (id hardcoded at 50)
  130.     pVSlider=new CSlider(m_hWnd,50,
  131.                         WS_CHILD|WS_VISIBLE|SCS_INVERTRANGE|
  132.                         SCS_VERTICAL|SCS_TEXTHASRANGE|
  133.                         SCS_RIGHTTICKS,
  134.                         "1,2000,25",10,20,40,200);
  135.  
  136.     // Create a horizontal slider (id hardcoded at 51)
  137.     pHSlider=new CSlider(m_hWnd,51,
  138.                         WS_CHILD|WS_VISIBLE|SCS_INVERTRANGE|
  139.                         SCS_HORIZONTAL|SCS_TEXTHASRANGE|
  140.                         SCS_TOPTICKS|SCS_BOTTOMTICKS,
  141.                         "1,2000,25",60,110,200,50); 
  142.                         
  143.     // Create a text window to display the current position
  144.     RECT    r={60,20,120,44};
  145.     
  146.     vposWin.Create(WS_VISIBLE|WS_CHILD|WS_BORDER,
  147.                   r,this,12);
  148.                   
  149.     vposWin.ShowWindow(1);
  150.                   
  151.     r.top=80;
  152.     r.bottom=104;
  153.                 
  154.     hposWin.Create(WS_VISIBLE|WS_CHILD|WS_BORDER,
  155.                   r,this,13);
  156.                   
  157.     hposWin.ShowWindow(1);                  
  158.     return 0;
  159. }
  160.  
  161. void CSlidetstView::OnDestroy()
  162. {
  163.     CView::OnDestroy();
  164.     
  165.     // TODO: Add your message handler code here
  166.     delete pVSlider;
  167.     delete pHSlider;
  168. }
  169.  
  170. void CSlidetstView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  171. {
  172.     // See if this is the slider 
  173.     if (pScrollBar->m_hWnd==pHSlider->m_hWnd)
  174.     {
  175.     
  176.         int curPos=pHSlider->getPos(); 
  177.         
  178.             // This is for testing only - you only need to use nPos
  179.             //  and would not normally call getPos to get the position
  180.         ASSERT (curPos==(int)nPos);
  181.         
  182.         char szText[20];
  183.     
  184.         wsprintf(szText,"%d",nPos);                 
  185.         hposWin.SetWindowText(szText);    
  186.     }
  187. }
  188.  
  189. void CSlidetstView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  190. {
  191.     // See if this is the slider 
  192.     if (pScrollBar->m_hWnd==pVSlider->m_hWnd)
  193.     {
  194.     
  195.         int curPos=pVSlider->getPos(); 
  196.         
  197.             // This is for testing only - you only need to use nPos
  198.             //  and would not normally call getPos to get the position
  199.         ASSERT (curPos==(int)nPos);
  200.     
  201.             // Display the current position    
  202.         char szText[20];
  203.     
  204.         wsprintf(szText,"%d",nPos);                 
  205.         vposWin.SetWindowText(szText);    
  206.     }
  207. }
  208.  
  209.  
  210. void CSlidetstView::OnSethrange()
  211. {
  212.   CRange    dlg;
  213.   
  214.   if (dlg.DoModal())
  215.   {
  216.      pHSlider->setRange(atoi(dlg.m_Low.GetBuffer(10)),
  217.                         atoi(dlg.m_High.GetBuffer(10)));  
  218.   }
  219.     
  220. }
  221.  
  222. void CSlidetstView::OnSetvpos()
  223. {
  224.     char    szTemp[30];           
  225.     int     nVal;
  226.     
  227.     vposWin.GetWindowText(szTemp,30);
  228.     nVal=atoi(szTemp);
  229.     pVSlider->setPos(nVal);
  230. }
  231.  
  232. void CSlidetstView::OnSetvrange()
  233. {
  234.   CRange    dlg;
  235.      
  236.   if (dlg.DoModal())
  237.   {                              
  238.      pVSlider->setRange(atoi(dlg.m_Low.GetBuffer(10)),
  239.                         atoi(dlg.m_High.GetBuffer(10)));
  240.   }
  241. }
  242.  
  243. void CSlidetstView::OnSethpos()
  244. {
  245.     char    szTemp[30];           
  246.     int     nVal;
  247.     
  248.     hposWin.GetWindowText(szTemp,30);
  249.     nVal=atoi(szTemp);
  250.     pHSlider->setPos(nVal);
  251. }
  252.  
  253. void CSlidetstView::OnEnablevert()
  254. {
  255.    pVSlider->EnableWindow(TRUE);       
  256. }
  257.  
  258. void CSlidetstView::OnEnablehorz()
  259. {
  260.    pHSlider->EnableWindow(TRUE);        
  261. }
  262.  
  263. void CSlidetstView::OnDisablevert()
  264. {
  265.    pVSlider->EnableWindow(FALSE);       
  266. }
  267.  
  268. void CSlidetstView::OnDisablehorz()
  269. {        
  270.    pHSlider->EnableWindow(FALSE);
  271. }
  272.  
  273. void CSlidetstView::OnGethrange()
  274. {
  275.     long    lVal;
  276.     char    szMsg[100];
  277.         
  278.     lVal=pHSlider->getRange();
  279.     wsprintf(szMsg,"%d to %d",LOWORD(lVal),HIWORD(lVal));
  280.     AfxMessageBox(szMsg);
  281. }
  282.  
  283. void CSlidetstView::OnGetvrange()
  284. {
  285.     long    lVal;
  286.     char    szMsg[100];
  287.         
  288.     lVal=pVSlider->getRange();
  289.     wsprintf(szMsg,"%d to %d",LOWORD(lVal),HIWORD(lVal));
  290.     AfxMessageBox(szMsg);
  291.     
  292. }
  293.