472,146 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

Losing focus on a slider control within a user control

The problem:
I want to know, definitively when a slider loses focus after a user has
started sliding and hasn't released the mouse yet. It appears that
this is captured with the WM_ACTIVATEAPP message but this only goes to
the form and I want it in the user control that maybe very much removed
from the form's knowledge; i.e. the form may launch a 3rd party form
that, upon a call back, decides to launch other form that has my user
control on it. Yeah, ok, so I should be able to just derive a class
from that 3 rd party form and then have any and every form in my system
pass down the WM_ACTIVATEAPP to all of its children but that will be
very painful with a large application. I could do it the other way and
for each component that may need to deal with this message I could
force them to have to register with the main form but that could also
be very painful and requires application programmers to have the
knowledge that this, very specific user control, needs to be registered
but none others do and that's just messy; I really want this user
control to be self contained so you can just plop it down wherever and
it will just work and not have to write code in your form to deal with
the fact that it doesn't know when it loses focus.

So I was wondering if anyone had some other potential solutions that
would, hopefully, be less messy. I've overrode WndProc and outputted
each and ever message that comes in and there's nothing useful in
most situations.

I'm creating a generic dual slider control, with fine and coarse
adjustments. Controlling the slider will (indirectly) write values
down to hardware via a network connection. When the hardware
acknowledges that it received the request it sends back an LSV event
(last sent value). This gets propagated to my user control so it can
display this value and, IF the user is not currently sliding, it will
update the slider's values since this value can change from multiple
places all sliders should be positioned the same. Due to the
asynchronous nature I could end up with multiple LSV events queued up
so I can't just blindly update the slider because an older LSV event
may yank the slider bar out from underneath the mouse. I also cannot
maintain a count by incrementing for each write and decrementing for
LSV event (but never going <0) and only update the slider when the
count is 0 - i.e. a semaphore type solution. Since there is the
slight possibility that I could lose LSV events and I don't want to
slider thinking that it's still waiting to get some events when it
may never get them and then when it gets ones that it really should pay
attention to it will just ignore them.
The second issue is that I want the user to be able to drag the fine
control and when a limit is hit, and the mouse is to the left or right
of the end of the slider, it will start moving the coarse adjustment at
the same rate. And vice versa. So it will be possible for a user to
drag over the entire valid range by selecting either the fine or coarse
slider. This is required because the user will be focused on an
incoming image from the hardware and doesn't want to have to move the
mouse to select the coarse slider and then reselect the fine slider
ever time they hit the limit of the fine slider. Since we don't get
continuous events when you just hold the mouse button down outside of a
control, and don't move it, I've implemented a timer that gets
started in this situation and starts sliding the coarse slider until it
gets a mouse up event.
The problem is that I can't definitively know when the user is still
dragging the slider (either inside or outside of the control). The
mouse up event only works if they actually released the mouse but
doesn't deal with other ways focus could be lost. If a user hits
Alt-Esc I get nothing. It seems that I can get the Alt-Tab event by
listening to the KeyUp event but this doesn't capture Alt-Esc or
other situations where asynchronous messages pop up in the users face
and take focus.

Side question:
Why isn't there a way to just ask the mouse if a button is depressed
rather than having to wait for events which may get swallowed up by a
parent object? I could just query the mouse and if the mouse button is
still down I could assume that the user is still dragging. There are
some holes in this but it's almost a full solutions.


Mar 22 '06 #1
1 2121
One side thought is that it seems that the slider control must know
when it loses focus in all of these cases because if I drag the slider
back and forth and (while leaving the left button down) I just Alt-Tab
or Alt-Esc and then Alt-Tab back the slider knows that it is now longer

Mar 22 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jason Charalambides | last post: by
reply views Thread by MattB | last post: by
reply views Thread by Stefan De Schepper | last post: by
2 posts views Thread by Paul Helmuth | last post: by
7 posts views Thread by Dave Booker | last post: by
5 posts views Thread by LabGeek | last post: by
reply views Thread by Saiars | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.