MFC: How do you handle putting up a right drag-and-drop context menu? - winapi

I have a drop target (CTreeView) that accepts CF_HDROP. When I drag/drop using left mouse button, it works as expected (with Move/Copy option via shift/ctrl keys), when I do a drag/drop using the right button, it treats it the same as the left, no context menu. I've tried dragging from the desktop to the tree view (as well as internally from a list view to the tree view).
I am aware of the method of showing a context menu when the program internally handles the process of checking when the right button down, track when dragging when mouse moves, and releasing button to do drop. But since this is a drop-target from anything (using OnDrop()), how do I handle getting the context menu to show for the option to either copy or move?
Thanks!!

Related

Win32 Dialog box: how to keep all objects in windows centered when resizing

I am building and maintaining a Win32 app using Visual Studio.
I have recently edited the .rc file adding WS_THICKFRAME to my dialog STYLE line for all dialog windows to allow them to be resizable.
My current problem is, when I resize a window, its content remains fixed to the left. How can I make the window's content remain centered when resizing using the border?
Pointing to any relevant documentation on this would also be helpful, as I have not had lucky finding that.
If you only want to reposition (rather than resize) the individual controls, an easy way would be to create a non-modal container dialog to hold the controls, make that dialog a child of the resizable dialog, and then when you handle WM_SIZE for the outer dialog, you only have to reposition that one non-modal dialog.
Your new position is ((newWidth- controlDlgWidth) / 2, (newHeight-controlDlgHeight)/2), where controlDlgWidth, controlDlgHeight are the width and height of the child dialog.
I say to use a non-modal dialog for this, so that you can continue using a resource script, rather than needing to add a whole bunch of explicit CreateWindow() calls.

How to auto-activate cocoa window so you don't need to click twice?

I have two windows: A main window and an inspector panel. Both have sliders and draggable items.
You have to click twice every time you work in the other window. First click activates the window. Second click allows a drag to start.
Is it possible to have a click in a window automatically activate it AND allow the event to pass through to the controls so you don't need to do it twice all the time when switching between an inspector panel and main window?
The first thing to try is to set the panel's becomesKeyOnlyIfNeeded property to true. That way, you main window will remain key even if the user clicks and drags on controls within the panel.
Otherwise, you have to handle this in each different view class. A view should override -acceptsFirstMouse: to return true if it wants to handle the same mouse event that activates the window. For custom view classes, this is straightforward. If you're using standard controls and they don't already implement -acceptsFirstMouse: to return true, you'll need to subclass them and use those subclasses instead.

XCode: Moving UI-elements in storyboard editor

Is it possible to lock or freeze elements in storyboard editor so that they are ignored, when clicking and dragging?
My problem is that I have several elements underneath two big UIViews that cover the whole window. So in order to for example move a button underneath them I first have to move the big views out of the way, move the button, then move them back.
Is there a better way?
When I select the element in the tree-view on the left, it gets deselected as soon as I click on the storyboard. Perhaps there's a keyboard shortcut to keep the selection while dragging?
There isn't I'm afraid, at least not that I've ever been aware of.
You can use the object navigator / tree-view on the left to select your items, then you can move objects around using the x/y/w/h properties on the size inspector.
Another solution could be to set the items you don't want to drag around to hidden while you're dragging other elements around.

How to respond to _one_ click on a control in a cocoa window that is not key?

I have a button in a child window.
If I am working in the parent window (it is key), and I click once on the button in the child window, this click makes the child window key. I then have to click a second time to make the control (in this case, a button) respond.
How can I immediately respond to a click on that button in a non-key window?
This is controlled individually for each view class by -[NSView acceptsFirstMouse:] which returns NO by default. Subclasses have to return YES to allow the first click to work.
However, NSButton implementation already returns YES so it should work as is, unless your button is not painted by NSButton instance.

combobox dropdown window can show beyond the combobox window,how?

in windows, how can make a 'child' window beyond the parent window, and the parent window always in active status (GetActiveWindow() return parent), just like the combobox dropdown window.
I think these are the main points when trying to do this:
The pop-up is a top-level window which has the same parent as the control. (i.e. The pop-up is not a child of the control. It's not a child-window at all; it's a top-level window, but one without a thick window border etc. so it doesn't look like a normal top-level window.) That's why it can extend outside of the control's boundaries.
When the pop-up is created it is shown using ShowWindow(hWndPopup, SW_SHOWNA) so that it does not take the input focus. This prevents the parent window from going inactive.
When the pop-up is created you capture the mouse using SetCapture. You then track where the mouse is and highlight items within the pop-up when the mouse overlaps them. When the mouse button is clicked you act on whatever is under the mouse (or cancel the pop-up if the mouse isn't over it at all). Remember to respond to WM_CAPTURECHANGED, in case something else captures the mouse. And remember to ReleaseCapture when you are done.
The popup should handle WM_MOUSEACTIVATE by returning MA_NOACTIVATEANDEAT.

Resources