notification code for mouse over a tab item - c

I have a tab control created by CreateWindowEx(NULL, WC_TABCONTROL,...). I would like to have a notification when a mouse is over a tab item. The tab control has the style TCS_TOOLTIPS and when the mouse is over a tab item for an amount TTDT_INITIAL ms (whose default value is double click time), it will display a tooltip.
But I also need a notification immediately when a mouse is over a tab item. But I don't want to modify the TTDT_INITIAL value. In fact, when a mouse is over a non-selected tab item, it will change the color to blue by default. But I can not find the notification (and its receiver) for this thing.
So I would like to know if there is a way to be notified immediately when a mouse is over a tab item (winapi only).

There is no notification for that particular purpose. The tabs are not their own controls, the entire TabControl as a whole is one control. What you can do is have your window procedure for the TabControl catch WM_MOUSEMOVE messages, and then call TabCtrl_HitTest() to determine which tab is currently underneath the mouse. Keep track of the current tab so you can detect when the mouse moves across a tab boundary onto a new tab.

Related

Silverlight: How to route mouse events from one control to another?

If I catch mouse move/mouse button down events in one control, how do I route the caught event to another control?
In MSDIN documentation I found WPF UIElement.RaiseEvent but it seems it doesn't exist in Silverlight.
The reason for this question is the following issue.
I have an application where user is able to pick a control on the screen to retrieve control's ID (a custom property). While user picks a control, I don't want default actions of the control to be triggered - no button clicks, no text highlighting, no link navigation etc. That's why when entering the "picking mode", I put a transparent overlay over my application and after user clicks on it I find the element behind the overlay, get its ID and remove the overlay.
This approach is working fine except one scenario when there is a scroll viewer on the screen and user might want to pick an element which is scrolled out of view. Thus when picking elements, user at first clicks on a scrollbar to scroll the required element into view, but the scrollbar doesn't work because its behind the overlay.
Currently I have working code which detects if the element under mouse cursor (and behind the overlay) is a scrollbar instance, and thus I ignore it for my picking process - my application doesn't require picking scrollbars. But how do I pass the mouse event from the overlay to the scrollbar behind?
The short answer is, you can't route the mouse events.
But what you can do is: as long as the mouse is hovered over a Scrollbar you can set the IsHitTestVisible property of your mouseClick catcher overlay to false. The click will just go through it. Or can you only detect the Scrollbar the moment the user clicks?

ComboBox doesn't raise keyboard and mouse events as expected

I use Silverlight 4.0 and have got problems with ComboBox control. I want to implement a popup menu which will show and hide itself without clicking mouse. It should show when I place cursor on its region - this prt works well. Then it should hide whenever mouse pointer is placed outside of its region for a while. I implemented it with MouseEnter and MouseLeave events. My problem is ComboBox - this control behaves weirdly, in my opinion. Normally I would expect it to raise MouseEnter event when I put the cursor on it and MouseLeave when I put the mouse cursor anywhere else. The real situation is different: Whenever I click the combobox, it opens and shows the list of options, and immediately sends LostFocus and MouseLeave events. So it seems like the control lost keyboard focus and mouse pointer has been moved out of its region, while actually the combobox list of optins is open and active and has keyboard focus in it.
So the question is how can I know in my program what is happening in comboboxes? In order to correctly hide my popup menu, I need to know when the list of options in a combobox is open or closed. I can't see any events for this or any other documentation. (Wanted behavior is: If a combobox is closed, I hide my popup menu based on the position of mouse cursor. If a combobox is open, I never hide my popup menu until user either selects something in the combobox, or closes the combobox.)
Also, if you have got a good experience with a third party combobox replacement, which looks and works similarly AND raises events I need, please let me know.
MSDN has two events listed for ComboBox that you might want to look at.
http://msdn.microsoft.com/en-us/library/system.windows.controls.combobox_events(v=VS.95).aspx
DropDownClosed Occurs when the drop-down portion of the combo box closes.
DropDownOpened Occurs when the drop-down portion of the combo box opens.

WPF equivalent of LVS_EX_ONECLICKACTIVATE?

I've got a WPF application with a ListBox in it. For this list box, I'd like to mimic the behaviour of the users control panel (since Windows Vista) -- that is: you single-click on a list item, and it's the same as double-clicking.
In Win32, I'd do this by turning on the LVS_EX_ONECLICKACTIVATE style.
In WPF, I've attempted to do this by handling the MouseLeftButtonUp event. Unfortunately, and this is odd, it sometimes picks up the wrong item.
For example, if you double-click the title bar (caption) to maximise the window, the second mouse-up occurs over the list box, and the event is raised. Similarly, if an item is partially in view, clicking on it scrolls it into view, but the mouse-up is raised against the item that's now in view, not the one clicked.
Now, again, if this was Win32 (before LVS_EX_ONECLICKACTIVATE), I'd get mouse capture on the mouse down, remember the item, and check that I had capture on mouse up.
But it's not Win32, it's WPF. How do I do single-click activation in a WPF list box?
I must admit I never stumbled across the LVS_EX_ONECLICKACTIVATE by now, but as I understood it handling "SelectionChanged" should do the trick.
Or is there a difference between double clicking on selection or activation on selection?

Incorrect item gets selected when starting a drag on an item in an ItemsControl

I am implementing a DragDrop framework for WPF (which incidentally you can find here).
I have a problem in that when the user MouseDowns on an ItemsControl we don't know immediately if they intended to click the item to select it, or to begin a drag. If the user clicks an item and then quickly moves the cursor, another item other than the clicked item can become selected before we determine that a drag has started (especially if clicking on the item freezes the UI for a short time to load data etc).
I think this problem didn't exist in WinForms as dragging the mouse with the button held down didn't cause another item to become selected - the selection was made only on the item on which the click occurred.
In the PreviewMouseDown event I can set the e.Handled property to prevent another item becoming selected, which works fine if the user actually did intend to start a drag, but then they can't actually select the item.
Anyone know how to handle this?
Store/use the point at which they originally moused-down, and use that to resolve the item to drag.

Set focus in WPF textbox

I am writing a control in WPF that draws a shape on a form and then draws dimensions of this shape. These dimensions are editable so they are shown in a text box. When the user changes a dimension in a text box the shape is updated.
I am updating the shape when the textbox showing the dimension loses focus i.e. as soon as the text box loses the focus the shape and all the dimensions are redrawn. A text box loses focus in one of two ways - either when user presses tab key or when user clicks in another control outside the text box.
My problem is that when user presses tab key or clicks somewhere else outside the text box the whole control is redrawn and the focus is not set to the next control where it should be. This is really annoying because tabs stop working altogether and to set a focus using mouse the user has to click twice. Is there a way around this?
An image of my control is shown below
alt text http://img223.imageshack.us/img223/9496/cavity.png
It seems that you want to manage the tab order yourself in this window and to do that, I'd think you would subscribe to the GotKeyboardFocus and LostKeyboardFocus events on those edit fields and then drive focus to the appropriate location if you're not happy with where focus has gone.

Resources