home *** CD-ROM | disk | FTP | other *** search
- // mydlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "speed.h"
- #include "mydlg.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyDlg dialog
-
-
- CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CMyDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CMyDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Initialize the data members
- m_ScrollPosition = 50;
- m_ScrollMin = 0;
- m_ScrollMax = 100;
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- }
-
- void CMyDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMyDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
- //{{AFX_MSG_MAP(CMyDlg)
- ON_WM_VSCROLL()
- ON_BN_CLICKED(IDC_ENABLE, OnEnable)
- ON_BN_CLICKED(IDC_DISABLE, OnDisable)
- ON_BN_CLICKED(IDC_HIDE, OnHide)
- ON_BN_CLICKED(IDC_SHOW, OnShow)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyDlg message handlers
-
- BOOL CMyDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
-
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Extract the pointer of the scroll bar.
- CScrollBar* pSB =
- (CScrollBar*) GetDlgItem ( IDC_SCROLL_SPEED);
-
- // Set the range of the scroll bar.
- pSB -> SetScrollRange (m_ScrollMin,
- m_ScrollMax );
-
- // Set the position of the scroll bar.
- pSB -> SetScrollPos ( m_ScrollPosition );
-
-
- // Declare local variables
- CString LabelContents;
- char sPos[25];
-
- // Convert the current position from an integer to a string.
- itoa ( m_ScrollPosition, sPos, 10 );
-
- // Update the variable of the label.
- LabelContents = (CString) "Speed:" + sPos ;
-
- // Update the caption of the label
- SetDlgItemText(IDC_SPEED_LABEL, LabelContents);
-
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- void CMyDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // TODO: Add your message handler code here and/or call default
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- CString LabelContents;
- char sPos[25];
- int iCurrent;
-
- switch (nSBCode)
- {
- case SB_THUMBPOSITION:
-
- // Set the scroll bar to its new position.
- pScrollBar->SetScrollPos ( nPos );
-
-
- // Update the caption of the label.
- itoa ( nPos, sPos, 10 );
- LabelContents = (CString) "Speed:" + sPos ;
-
- SetDlgItemText(IDC_SPEED_LABEL,LabelContents);
- break;
-
- case SB_LINEDOWN:
-
- // Get the current position
- iCurrent = pScrollBar->GetScrollPos();
-
-
- // Increase current position by 1 (if possible)
- iCurrent = iCurrent + 1;
-
- if ( iCurrent >= m_ScrollMax )
- iCurrent = m_ScrollMax;
-
- // Set scroll bar to its new position.
- pScrollBar->SetScrollPos ( iCurrent );
-
-
- // Update the caption of the label.
- itoa ( iCurrent, sPos, 10 );
-
- LabelContents = (CString) "Speed:" + sPos ;
-
- SetDlgItemText(IDC_SPEED_LABEL,LabelContents);
- break;
-
- case SB_LINEUP:
-
- // Get the current position
- iCurrent = pScrollBar->GetScrollPos();
-
-
- // Decrease current position by 1 (if possible)
- iCurrent = iCurrent - 1;
-
- if ( iCurrent <= m_ScrollMin )
- iCurrent = m_ScrollMin;
-
- // Set scroll bar to its new position.
- pScrollBar->SetScrollPos ( iCurrent );
-
-
- // Update the caption of the label.
- itoa ( iCurrent, sPos, 10 );
- LabelContents = (CString) "Speed:" + sPos ;
-
- SetDlgItemText(IDC_SPEED_LABEL,LabelContents);
- break;
-
- case SB_PAGEDOWN:
-
- // Get the current position.
- iCurrent = pScrollBar->GetScrollPos();
-
- // Increase scroll bar (if possible).
- iCurrent = iCurrent + 1;
-
- if ( iCurrent >= m_ScrollMax )
- iCurrent = m_ScrollMax;
-
-
- // Set scroll bar to its new position.
- pScrollBar->SetScrollPos ( iCurrent );
-
-
- // Update the caption of the label.
- itoa ( iCurrent, sPos, 10 );
- LabelContents = (CString) "Speed:" + sPos ;
-
- SetDlgItemText(IDC_SPEED_LABEL,LabelContents);
- break;
-
- case SB_PAGEUP:
-
- // Get the current position.
- iCurrent = pScrollBar->GetScrollPos();
-
- // Decrease scroll bar (if possible).
- iCurrent = iCurrent - 1;
-
- if ( iCurrent <= m_ScrollMin )
- iCurrent = m_ScrollMin;
-
-
- // Set scroll bar to its new position.
- pScrollBar->SetScrollPos ( iCurrent );
-
-
- // Update the caption of the label.
- itoa ( iCurrent, sPos, 10 );
- LabelContents = (CString) "Speed:" + sPos ;
-
- SetDlgItemText(IDC_SPEED_LABEL,LabelContents);
- break;
-
- case SB_THUMBTRACK:
-
- // Set scroll bar to its new position.
- pScrollBar->SetScrollPos ( nPos );
-
- // Update the caption of the label.
- itoa ( nPos, sPos, 10 );
- LabelContents = (CString) "Speed:" + sPos ;
- SetDlgItemText(IDC_SPEED_LABEL,LabelContents);
- break;
-
-
- }
-
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
- CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
- }
-
- void CMyDlg::OnOK()
- {
- // TODO: Add extra validation here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Extract the pointer of the scroll bar whose
- // ID is IDC_SCROLL_SPEED
- CScrollBar* pSB =
- (CScrollBar*) GetDlgItem ( IDC_SCROLL_SPEED);
-
- // Extract the thumb position of the scroll bar, and
- // assign it to the m_ScrollPosition data member.
- m_ScrollPosition = pSB -> GetScrollPos ();
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
-
- CDialog::OnOK();
- }
-
- void CMyDlg::OnEnable()
- {
- // TODO: Add your control notification handler code here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Enable the scroll bar
- GetDlgItem(IDC_SCROLL_SPEED)->EnableWindow(TRUE);
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- }
-
- void CMyDlg::OnDisable()
- {
- // TODO: Add your control notification handler code here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Disable the scroll bar
- GetDlgItem(IDC_SCROLL_SPEED)->EnableWindow(FALSE);
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
- }
-
- void CMyDlg::OnHide()
- {
- // TODO: Add your control notification handler code here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Hide the scroll bar
- GetDlgItem(IDC_SCROLL_SPEED)->ShowWindow(SW_HIDE);
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
- }
-
- void CMyDlg::OnShow()
- {
- // TODO: Add your control notification handler code here
-
- //////////////////////
- // MY CODE STARTS HERE
- //////////////////////
-
- // Un-hide the scroll bar
- GetDlgItem(IDC_SCROLL_SPEED)->ShowWindow(SW_SHOW);
-
- ////////////////////
- // MY CODE ENDS HERE
- ////////////////////
-
-
- }
-