|
-
March 13th, 2003, 08:41 AM
#5
Actually I had a client that wanted something similar. In my
case, basically simulating a thumbwheel with a slider control.
Here is how I did it (there are probably better ways -
my MFC use is minimal and knowledge limitted). Maybe
you can adapt it to do what you want. (at any rate, with
you move the slider windows sends WM_H_SCROLL message (or
WM_V_SCROLL if vertical). Look up OnHScroll for more info.
- associate a CSliderCtrl variable with your slider control.
(in sample code below I named it : m_xTranslation_slider)
- process WM_H_SCROLL for the dialog (if a horizontal slider)
- add additional member variables to the dialog :
Code:
int m_xTranslation_old_position; // saved position of slider control
int m_xTranslation; // current value of variable you are tracking
- Initialize everything in dialog's OnInitDialog()
Code:
int minRange = 0;
int maxRange = 100;
int avgRange = (minRange+maxRange)/2;
m_xTranslation_slider.SetRange(minRange,maxRange);
m_xTranslation_slider.SetPos( avgRange );
m_xTranslation_old_position = avgRange;
m_xTranslation = 0;
- process WM_H_SCROLL for the dialog (see where I have
the TRACE() for the updated value)
Code:
void CNozzleEditorDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if (pScrollBar->GetSafeHwnd() == m_xTranslation_slider.GetSafeHwnd())
{
int minRange , maxRange , avgRange;
m_xTranslation_slider.GetRange(minRange,maxRange);
avgRange = (minRange + maxRange)/2;
int xTranslation_new_position = m_xTranslation_slider.GetPos();
if (xTranslation_new_position != avgRange)
{
if (xTranslation_new_position == m_xTranslation_old_position)
{
m_xTranslation_old_position = avgRange;
m_xTranslation_slider.SetPos(avgRange);
}
else
{
m_xTranslation += (xTranslation_new_position - m_xTranslation_old_position);
m_xTranslation_old_position = xTranslation_new_position;
TRACE("new value for xTranslation = %d\n",m_xTranslation);
}
}
}
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|