-
February 15th, 2010, 12:56 PM
#1
[RESOLVED] working with slider bar
I've got an MFC app that uses afx messaging.
I have a slider whose position I monitor using the OnHScroll function. It works...too well
As soon as I click on the slider, it enters the OnHScroll function. I don't get a chance to move it my desired new position. What I want is to be able to grab the slider with the mouse, move it to a new position, release the mouse, and have the function retreive this final position.
Is there a neat & simple way to modify my code below to do this ?
Code:
void TestDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
int x;
x= m_Slider.GetPos();
// do some stuff with x
}
m_Slider is of type CSliderCtrl.
My message map contains ON_WM_SCROLL.
Thanks,
ak
-
February 15th, 2010, 01:26 PM
#2
Re: working with slider bar
Are you checking the nSBCode that's getting passed to your handler? Look for the value SB_ENDSCROLL.
-
February 15th, 2010, 02:11 PM
#3
Re: working with slider bar
Thanks - that works !
I just used an if(nSBCode == SB_ENDSCROLL) statement to only perform my operations when SB_ENDSCROLL has been flagged.
One more minor issue -
When I start my application I want the slider bar to start off in position 4. Here's my initialization function :
Code:
BOOL TestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu....
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog...
m_Slider.SetPos(4); // setting the initial slider position
m_Slider.SetRange(0,7);
// other control settings ...
UpdateData(FALSE);
return TRUE;
}
But instead it starts off elsewhere like 0 & as soon as I click the slider with the mouse it hops over to position 4.
How can I make it start at 4 without having to click on the control ?
ak
-
February 15th, 2010, 02:38 PM
#4
Re: working with slider bar
Originally Posted by rowgram
Thanks - that works !
I just used an if(nSBCode == SB_ENDSCROLL) statement to only perform my operations when SB_ENDSCROLL has been flagged.
One more minor issue -
When I start my application I want the slider bar to start off in position 4. Here's my initialization function :
Code:
BOOL TestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu....
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog...
m_Slider.SetPos(4); // setting the initial slider position
m_Slider.SetRange(0,7);
// other control settings ...
UpdateData(FALSE);
return TRUE;
}
But instead it starts off elsewhere like 0 & as soon as I click the slider with the mouse it hops over to position 4.
How can I make it start at 4 without having to click on the control ?
ak
Try SetRange first.
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
|