Solved

Activating a spin control programatically

Posted on 1998-12-11
23
1,415 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
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
 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
dog bark java program 15 112
fizzArray  challenge 1 96
changeXy challenge 13 89
Is there a simple front-end menu system. 9 105
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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