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.
Related
Is there a way, after selection of a color, to programmatically hide the color picker of the TComboColorBox? I've searched on the web and Embarcadero community but couldn't find a way to do this.
The answer is no, there is no designed way to hide (collapse) the popup programmatically. And you did not explain why you think it would be necessary to have.
Keep in mind that there are 4 subcontrols, that the user may want to use:
a THueTrackBar,
an alpha channel trackbar,
a color quad, and
a hex color value edit box.
An automatic collapse of the popup would be just annoying.
The user can at any time decide to close the popup simply by clicking on the constantly visible bar.
With reference to your comment:
After your answer, I realized that I must implement a color picker component that shows a rect containing a TComboColorBox and a TButton as childs. Clicking the child button, in turn, hides the container rect itself.
I have told you twice that the user can close the popup part of the TComboColorBox simply by clicking on the component (the base part of it).
In fact, the user can click anywhere outside of the popup window in order to close the popup window. The popup is closed immediately when the focus moves away from it.
In my opinion there's no need for a special "Close" button.
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!!
I have an app with a popover that appears on a status bar item. The thing is, when you click on the icon while you're in a full screen app, then move the mouse away from the menu bar to click on something in the popup, the menu bar moves up, and so does the popup. It's annoying.
Anyone know of any way to solve this? I've tried attaching an invisible menu to the popup, but I can't get the menu to be invisible.
Screenshot for clarity, the annoying part is where I wave my mouse around:
The popover window is moving because its parent window is the status item window, and when the parent window moves, the child moves with it. (Before I investigated this, I didn't even know Cocoa had parent and child windows.) I solved the problem with this code immediately after showing the popover:
NSWindow *popoverWindow = self.popup.contentViewController.view.window;
[popoverWindow.parentWindow removeChildWindow:popoverWindow];
Now, the menu bar still moves up, but at least the popup stays in the same place.
Either use Carbon events or watch for things happening to the menu bar (window of type NSStatusBarWindow):
Notifications of type
NSWindowDidChangeOcclusionStateNotification
NSWindowDidMoveNotification
NSWindowWillCloseNotification
NSWindowDidCloseNotification
with an object of class NSStatusBarWindow should give you enough information about the menu bar showing or hiding to add proper handling.
Super-hacky approach:
Custom window with some super-high window level to make it appear over the menu bar, then add a transparent custom view to the new window that catches and handles/blocks mouse clicks according to your needs.
Or:
Get the window instance the popover is using to display and track/handle NSWindowWillMoveNotification / NSWindowDidMoveNotification.
I converted #tbodt's answer to Swift 4 and confirmed that is resolves this issue:
let popoverWindow = popup.contentViewController.view.window as? NSWindow
popoverWindow?.parent?.removeChildWindow(popoverWindow!)
How to "notify" the parent window about the "scroll event" of its child window, a "list box" control, each time it is scrolled up or down in WIN32 API?
I am trying to make a dictionary using the WIN32 API. I created a parent window, and then created a child window list box control in it.
I want to add "50 word lists" at a time to the list box control from the database, so that the application does not take time at all during the start up.
And then, I want to keep a track of the "scroll bar position" (the "SCROLLINFO" structure's "nPos" value) of the list box control as the user scrolls up or down the word lists, so that I can call a function that adds 50 more words at the end of the list box when it has been almost scrolled up to the bottom.
In the main window procedure function, inside the "switch" statement I used the "WM_VSCROLL" window message hoping to catch the child window list box control’s scroll event. The child window list box control has "LBS_NOTIFY" style. But all in vain! The list box control’s scroll event is not being notified to its parent window. The parent window also is not doing anything in the "WM_VSCROLL" message for its child window list box control’s scroll event.
Please kindly help me, guide me, show me with code examples how to "notify" the parent window about the "scroll event" of its child window, a "list box" control, each time it is scrolled up or down in WIN32 API.
Scrolling messages are only sent to the window that is actually being scrolled, in this case the ListBox. LBS_NOTIFY only applies to a few select messages, which do not include scrolling messages. You would have to subclass the ListBox via either SetWindowLongPtr(GWL_WNDPROC) or SetWindowSubclass() and have your subclass procedure catch the scrolling messages and forward the info to the parent window as needed.
You usually only have one button that looks like a "default button".
However, I made a child window and placed two buttons in it (with the child window as their parent). Then I put the child window inside a dialog and displayed it.
Suddenly, the buttons stay highlighted even when I click other buttons!
Why?
Your child window needs the WS_EX_CONTROLPARENT style, to allow the dialog to handle the notifications from its children.