Solved

Activating a spin control programatically

Posted on 1998-12-11
23
1,357 Views
Last Modified: 2013-11-20
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
Comment
Question by:solomon021499
  • 13
  • 7
  • 3
23 Comments
 
LVL 6

Expert Comment

by:snoegler
ID: 1326075
I hope i did understand your question right :)

MFC version:

spinCtrl->SetPos(...);

SDK:

SendMessage(hWndSpinCtrl,UDM_SETPOS,0,...);
0
 

Author Comment

by:solomon021499
ID: 1326076
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
 

Author Comment

by:solomon021499
ID: 1326077
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
 
LVL 6

Expert Comment

by:snoegler
ID: 1326078
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
 

Author Comment

by:solomon021499
ID: 1326079
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
 

Author Comment

by:solomon021499
ID: 1326080
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
 

Author Comment

by:solomon021499
ID: 1326081
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
 

Expert Comment

by:kanni
ID: 1326082
Hi Solomon,

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

0
 

Expert Comment

by:kanni
ID: 1326083
Hi Solomon,

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

0
 

Expert Comment

by:kanni
ID: 1326084
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
 

Author Comment

by:solomon021499
ID: 1326085
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:solomon021499
ID: 1326086
I meant as if the control had been activated by the mouse when it had not.
0
 

Author Comment

by:solomon021499
ID: 1326087
I meant as if the control had been activated by the mouse when it had not.
0
 

Author Comment

by:solomon021499
ID: 1326088
I meant as if the control had been activated by the mouse when it had not.
0
 
LVL 6

Expert Comment

by:snoegler
ID: 1326089
Can you elaborate why SetPos() doesn't work? Or what you expect the spinner to do?
0
 

Author Comment

by:solomon021499
ID: 1326090
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
 
LVL 6

Expert Comment

by:snoegler
ID: 1326091
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
 

Author Comment

by:solomon021499
ID: 1326092
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
 
LVL 6

Expert Comment

by:snoegler
ID: 1326093
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
 
LVL 6

Expert Comment

by:snoegler
ID: 1326094
BTW: Do you expect the spin control to set another control (Edit control)?
0
 

Author Comment

by:solomon021499
ID: 1326095
Thanks,
I'll look into it and get back to you.
0
 

Author Comment

by:solomon021499
ID: 1326096
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
 
LVL 6

Accepted Solution

by:
snoegler earned 300 total points
ID: 1326097
Thanks :)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
deburging in oracle form 12 76
unable to delete all specified values regedit 38 155
sameEnds challenge 3 107
if loop in java 3 114
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now