Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1525
  • Last Modified:

Activating a spin control programatically

I am trying to activate a spinner programmatically.
I thought I should do this by sending the spin
control a message.
i.e.: spinCtrl->SendMessage(UDN_DELTAPOS,0,(LPNMHDR)&nmHdr);
where nmHdr is a pointer to a NM_UPDOWN structure
which sets the iDelta field to indicate how the spinner changed.
I must be getting the message wrong.

Any suggestions?
I am using MSVC5.0.

Thanks
0
solomon021499
Asked:
solomon021499
  • 13
  • 7
  • 3
1 Solution
 
snoeglerCommented:
I hope i did understand your question right :)

MFC version:

spinCtrl->SetPos(...);

SDK:

SendMessage(hWndSpinCtrl,UDM_SETPOS,0,...);
0
 
solomon021499Author Commented:
Yes, you understand me.
Both of your suggestions should work, but neither is.

I have a handler for the spin control - i.e.:
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_CTRL, OnDeltaposSpinCtrl)

Therefore, OnDeltaposSpinCtrl() should executed when I send
the UDM_SETPOS message or call the SetPos member function.

The problem is that this is not happening.
0
 
solomon021499Author Commented:
Yes, you understand me.
Both of your suggestions should work, but neither is.

I have a handler for the spin control - i.e.:
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_CTRL, OnDeltaposSpinCtrl)

Therefore, OnDeltaposSpinCtrl() should executed when I send
the UDM_SETPOS message or call the SetPos member function.

The problem is that this is not happening.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
snoeglerCommented:
UDN_DELTAPOS is only sent if the spin control is being changed by the keyboard or the
mouse.  It isn't sent if you set the position using 'UDM_SETPOS'.
Why do you need the UDN_DELTAPOS handler to be called?
0
 
solomon021499Author Commented:
I want the same behavior is the up arrow sping control was clicked with the mouse button or the up arrow key was hit.  The handler and codle already exists.  Therefore, sending the message that would execute that code is the way to go.

Unfortunately, sending the UDM_SETPOS message isn't doing the trick either.  The handler is not being executed.

I can of course work around this, but this should be easy.

0
 
solomon021499Author Commented:
I want the same behavior is the up arrow sping control was clicked with the mouse button or the up arrow key was hit.  The handler and codle already exists.  Therefore, sending the message that would execute that code is the way to go.

Unfortunately, sending the UDM_SETPOS message isn't doing the trick either.  The handler is not being executed.

I can of course work around this, but this should be easy.

0
 
solomon021499Author Commented:
I think I need to send a WM_NOTIFY message with the appropriate information in an NM_UPDOWN structure cast to an LPARAM in the SendMessage function.  

However, I haven't gotten this to work either.
0
 
kanniCommented:
Hi Solomon,

I think you need to change the value when the spin button ctrl is clicked.

0
 
kanniCommented:
Hi Solomon,

I think you need to change the value when the spin button ctrl is clicked.

0
 
kanniCommented:
Using the classwizard create a message map for the UDN_DELTAPOS.

ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN1, OnDeltaposSpin1)

Increment the value

      pNMUpDown->iDelta = pNMUpDown->iDelta+5;

Here I have incremented it to 5. It works fine.


0
 
solomon021499Author Commented:
Hi Kanni,
Your suggestion works fine if you can get the handler to execute.  I have a message map and it works fine when the spin control is activated via a mouse click.  I am trying to send this message so that this functions executes as if the mouse had been activated when in actuality it has not.

0
 
solomon021499Author Commented:
I meant as if the control had been activated by the mouse when it had not.
0
 
solomon021499Author Commented:
I meant as if the control had been activated by the mouse when it had not.
0
 
solomon021499Author Commented:
I meant as if the control had been activated by the mouse when it had not.
0
 
snoeglerCommented:
Can you elaborate why SetPos() doesn't work? Or what you expect the spinner to do?
0
 
solomon021499Author Commented:
snoegler,
No I can not elaborate on why SetPos() doesn't work.

I want the application to behave as if the spinner was activated.

For example, if I were talking about a button, I would send do the following:

buttonCtrl->SendMessage(WM_LBUTTONDOWN, MK_LBUTTON,
                        MAKELONG(USHORT(1), USHORT(1)) );
buttonCtrl->SendMessage(WM_LBUTTONUP, MK_LBUTTON,
                        MAKELONG( USHORT(1), USHORT(1)));

to progromatically activate the button.  As a result the button's ON_BUTTON_CLICKED handler would execute.

This is what I want with the spin control.

Thanks.
0
 
snoeglerCommented:
What i mean is:

Does SetPos() don't work? Or is the call of OnDeltaPos() not working, but the position can
be changed?
If the last case fits, could you describe why OnDeltaPos() must be called? Isn't there a other
way?
0
 
solomon021499Author Commented:
First SetPos() does not work.
Second, the UDN_DELTAPOS works when it is executed, but it is not being executed.
Finally, yes there is another way, but it would be the wrong way.  The correct thing to do is simply send this message and have the messaging system handle the rest i.e.: execute the handler.

There must be something wrong with the message that I am sending.
0
 
snoeglerCommented:
I am working with the MFC for quite a while now ... and i've never found a situation where
the SetPos() function didn't work.
I am assuming that maybe the ID you use for the UDN_DELTAPOS handler is wrong.
The SetPos() function _will_ set the value of the spin control. If not, either the spin control
can't be adressed (ID wrong) or the spin control is disabled.
Please check if the ID of the spin control is really equal to the one you use in your ON_xxx
message map entry. If not, i wonder if SetPos(5); ASSERT(GetPos()==5); would work.
BTW: UDN_DELTAPOS is a internal message of the spin control, and is called from within
the spin controls' WM_LBUTTONDOWN handler. I don't think that you can emulate the
UDN_DELTAPOS notification.
Isn't it possible to encapsulate the common functionality you like for the UDN_DELTAPOS
and for your 'position set issue' into a different function ...
0
 
snoeglerCommented:
BTW: Do you expect the spin control to set another control (Edit control)?
0
 
solomon021499Author Commented:
Thanks,
I'll look into it and get back to you.
0
 
solomon021499Author Commented:
snoegler,
Your last bit of information enabled me to figure it out.  You can emulate the UDN_DELTAPOS notification, but you need to send the WM_LBUTTONDOWN message instead of the UDM_SETPOS.

Thanks.  Make another posting as an answer and I'll give you an A.
0
 
snoeglerCommented:
Thanks :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 13
  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now