I have control, subclassed from CDialogBar, it has some buttons(like on toolbar). When I catch WM_LBUTTONDOWN in the CDialogBar class is it a simple way of getting know if mouse was clicked on one of the buttons that are on the control?
CDialogBar class normally hosts regular windowed controls, so when a button is clicked there, WM_LBUTTONDOWN message is sent to this control window, not the dialog window class. So if you want to intercept those messages (if you really do), you need to either subclass the windows and handle their messages, or install a message hook.
You can also use Spy++ tool to see what messages are effectively reaching your CDialogBar window of interest to see if handling them might be a solution to your challenge.
Related
I have a NSPopover that opens, and if the user clicks somewhere else in the app, the popover closes.
But the problem is that currently that mouseDown event is consumed during the popover-closing process.
Is it possible to still have that mouseDown event go through to the application, but also close the popover?
I had this same problem, so we changed to using NSPopoverBehaviorSemitransient for the behavior type. It no longer steals the mouseDown: and we just added some extra cases for closing the popover manually.
You can subclass the windows contentViewControllers view object.
I did this in the Storyboard file.
In there, implement the mouseDown() method. In there, you can create a notification which can be received at a point in your project where you need to know about the mouse event.
As the 'root view' captures almost all mouseDown() events, you have to filter them in order to only respond to the notification when the popover is displayed.
Don't forget to call super.mouseDown() at the end of your implementation.
If a dialog registers some of its controls as drop-targets, will drag'n'drop messages intended for those controls pass through the dialog's message processing in a way that the dialog can register a message handler to be notified/intercept those messages?
In a similar fashion to this question, I want to catch drag'n'drop events at a higher level in certain circumstances, before individual drop-handlers are invoked. But That question's answers suggest this isn't really possible? How to disable drag/drop when a dialog box is open
If a dialog registers some of its controls as drop-targets, will drag'n'drop messages intended for those controls pass through the dialog's message processing in a way that the dialog can register a message handler to be notified/intercept those messages?
If the controls are using DragAcceptFiles(), WM_DROPFILES messages will go directly to the window procedures of the individual controls, not to the window procedure of the dialog. If you want to intercept the messages, you will have to subclass the individual controls using SetWindowLongPtr() or SetWindowSubClass(), or use a message hook from SetWindowsHookEx().
If the controls are using RegisterDragDrop() instead, drag&drop operations will not go through any window procedures at all, as OLE drag&drop does not use window messages.
In a similar fashion to this question, I want to catch drag'n'drop events at a higher level in certain circumstances, before individual drop-handlers are invoked. But That question's answers suggest this isn't really possible?
This would only be possible with DragAcceptFiles() and subclassing/hooking.
Is there a way to change the position of the popup menu. With top-level windows I can do it by CBTProc Callback Function and MoveWindow. Can I do the same with menus? Needs to be done so that the pop-up menu is located only in the area of its parent window. Something like a light window manager.
Yes, in a WH_CBT hook callback, you'll be notified with an 'nCode' of HCBT_CREATEWND whenever a menu window is created. Test for the class name, standard menu/submenu windows would have a class name of '#32768'. You can then send a MN_GETHMENU message to the window to find out which menu is about to be activated. But as documented, it is too early to move the window when the notification is received, the menu is not even visible yet, so you might need to sub-class the window and process additional messages.
Note that you don't need a hook to be notified when a menu window is shown, you can put a handler for the WM_ENTERIDLE message, test for 'wParam' to see if a menu caused the message, get the menu window from 'lParam' and again send a 'MN_GETHMENU' to find out the specific menu. It is possible to move the window at this point without further message handling. Just be aware that 'WM_ENTERIDLE' will be called multiple times so you need to keep track of you've already moved a particular window or not.
I write a MFC application and need a button which is not taling the input focus away from another window.
Removing the WS_TABSTOP style does unfortunately not help when the use clicks the button with the mouse. When i block WM_LBUTTONDOWN i don't get a visual pressed indication so this doesn't work either.
If there is a specific window you want to keep the focus, you could just force the focus back to your window using the CWnd::SetFocus() command in your button's OnLButtonDown handler.
If you want the focus restored to one of several windows, you could try subclassing CButton and trapping the CWnd::OnSetFocus() message which is sent when the keyboard focus changes to the button.
The OnSetFocus() event includes a CWnd of the control that just lost the focus, so you could manually put it back, either as part of the OnSetFocus() event itself, or later as part of the OnLButtonDown() handler again.
I am trying to get menu/submenu name on mouse left click.For this i need to get some notification when i click on that particular menu/submenu.Look if somebody has the idea to do that?
Instead of reacting to WM_LBUTTONDOWN for a menu, you should instead listen for the WM_COMMAND notification. Windows takes care of all the details of handling mouse movement and clicks within menus.
To work with menu/submenu there is a totally different WMs is
Look in MSDN for this WM_MENUSELECT for example