Visual C++ - Event for ComboBox - visual-c++

I'd like to know if there is an event for ComboBox in Visual C++ that I can utilyze for doing something when mouse passes over the items of the combobox. Thank you

You could try WM_DRAWITEM notification, but you might need an owner drawn style for that.
The draw item member contains an itemAction that indicates for what situation the item needs to draw itself.

Have a look at TrackMouseEvent().
You will probably need to create a class for your combobox (derived from CComboBox); to add the TrackMouseEvent() in it.
There are messages to handle the mouse hover (when the mouse is inside the client area of the CWnd) and mouse leave (when mouse leaves the client area of the CWnd).

Related

Is there a way to create something likea draggable menu in wearable device in Android?

I was wondering if it is possible to create something like a menu that I can drag either by the side or from above on a wearable device. But I don't want it to affect the activity I have. You know like on a smart phone and you drag down the menu with some settings like brightness, rotation, etc...
To elaborate, I have a timer with a progress bar, but my activity would be overcrowded if I added any other stuff. So I want something to drag from the top of the screen to check on something, then drag again to return to my view that has the timer and progress bar. I basically have an activity where I make some selections, I wanted my selections to appear in that draggable menu thing to check to see my selections displayed there.
There are two drawer components for the type of behavior that you describe. Which one is better depends on the specifics of your implementation. The documentation for Navigation Drawer and Action Drawer can be found here.

Calling OnDraw in MFC SDI application

I am trying to make a MFC SDI application in VC++ to draw different shapes on click of the respective button. We have written our code inside the OnDraw() function. But Ondraw gets automatically called on running the application. We want it to be called only on the onclick of respective button. How do we proceed..?
When a shape button is clicked set a member variable that remembers what you want to draw.
Call Invalidate. This will cause OnDraw to be called by the framework.
In OnDraw check the member variable and draw the shape.
You must permit OnDraw to draw every time it is called by the framework. That is how the window image is restored after being uncovered, unminimized, resized, etc.
You cant prevent that OnDraw is only called when you press a button.
OnDraw in a view is called when WM_PAINT arrives and asks the window to repaint itself. Not executing OnDraw would cause nothing to be drawn at all.
OnDraw is also called when your application is minimized and maximized again, or when the size of the window changes.
Also I can not think about a scenario, where I want drawing only when a button is pressed. You need to be more precise. here.
OnDraw, as xMRi said, is called by the framework ... but if you want to draw something only when you click on a button, why don't you create a member variable, setup when you click the button, and get count when OnDraw is executed ?
void CYourAppView::OnDraw(CDC* pDC)
{
// MFC code
if(m_bButtonWasClicked)
{
// draw what ever you want
}
}

Is there a way to defocus fields in CDialog of VC++?

When I make a dialog using CDialog project of VC++,
I can not defocus any field on this dialog(CDialog).
What I want to do is how some field can be defocused
when I clicked the outside of this field with mouse.
Thanks for any advice and comments.
The only obvious question: WHY? Why do you want to de-focus from a control, and (possibly) not give focus to any control? Some control within the dialog should have a keyboard focus!
You can however, make a textbox, which would be outside the visible area of dialog, and SetFocus on that control, whenever you get WM_MOUSE* message(s) on the CDialog.

MFC KeyPresses on Properties Docking Window being catched as other Control accelerators

I have a Visual C++ application where there are, among other things, a CListCtrl in the Main Frame and a Dockable Pane with a properties Window.
When I press the Delete key on the Properties Window, the application also understands it as "Delete selected item" of the CListCtrl.
Some similar behaviours occur for other keys.
How can I say that I don't want this to go also to the CListCtrl?
Ok, I made a PreTranslateMessage function in the Mainframe class, that puts the HACCCEL current accelerator table in a temporary variable when the input comes from the Properties Control or a descendent of it, then call the parent class PreTranslateMessage, and finally retake the original accelerator table in the end of this function.
Now, I have another question: Is this the best solution? Doesn't seem to me it is!

Altering the YUI menu's mousing behavior

I'm using Yui to build a "popup" menu that works a bit differently with the mouse than usual. This is not a ContextMenu, because I want it to respond to left clicks, and the ContextMenu seems bent on responding to right clicks.
Following the examples, if I do this, the menu comes up and everything is close to how I want it:
YAHOO.util.Event.addListener(myClickTarget, 'click', myThingGotClicked);
In my myThingGotClicked function, I manually set the menu's position and show() it.
My problem is that I want to "bind" the menu visibility to the state of the mouse button. That is, on a mouseDown, I want the menu to come up, and on a mouseUp, I want the menu to disappear (selecting the active item, if any). So, listening to the 'click' event doesn't do the right thing, because a "click" is only sent after mouseUp.
The "obvious" solution is to do this:
YAHOO.util.Event.addListener(myClickTarget, 'mousedown', myThingGotClicked);
But this doesn't work. Stepping through in a debugger, you can see that it does actually bring up the menu on a mousedown, but then something immediately hides the menu. At full speed, it looks like nothing happens at all.
Any thoughts?
The problem is that the MenuManager class listens for the mousedown event at the document level and hides all visible Menu instances. So, since you are building a unique sort of Menu implementation, you'll need to stop the propagation of the mousedown event inside your handler so that the MenuManager doesn't handle the event. Here is some pseudo code for you:
var myThingGotClicked = function (event) {
YAHOO.util.Event.stopPropagation(event);
// Do other stuff
};
YAHOO.util.Event.on(myClickTarget, 'mousedown', myThingGotClicked);
Todd
That's a bit closer, as the menu does pop up, but if you try to make a selection in the menu, the text selection of the page underneath goes sort of nuts. I also need to add a mouseup handler, I think, as the menu doesn't go down on mouse release.
What I really want here are menus that work like menus on every version of the Mac OS (until more recently when OS X added the "click to make the menu 'sticky' to the default behavior).

Resources