I have a window with CTreeControl. I am able to catch WM_MBUTTONDOWN event in area of window (ON_WM_MBUTTONDOWN macro), but not in area of CTreeControl.
Is some way to catch this event for CTreeControl?
Thanks.
You could create a MFC class that inherits from CTreeCtrl and then create WM_MBUTTONDOWN from the class wizard.
Related
I'm planning to create modeless dialog and to receive messages from another thread. According to my understanding to creating modeless dialog I need to create CWinThread and some frame or dialog inside of CWinThread derived class object. But do I really need to create frame/dialog? Why I can't post messages direct to CWinThread derived class object?
You don't need a dialog to receive messages, but you do need a window handle. That window handle does not need to be associated with something visual. What I think you need is a message only window.
In MFC you can do this with CWnd using the CreateEx method to create the message only window. Pass HWND_MESSAGE to the hWndParent parameter of CreateEx.
It is true that you can create a hidden modeless dialog just to receive messages. However, this is grossly wasteful. What's more, MFC is designed around the concept that dialogs are created in the main UI thread. So for a number of different reasons you really do want to avoid creating a dialog just to receive messages in a thread. Use a message only window.
The message handler posts/sends messages to Window handlers, so you need a placeholder window to receive that message and handle as needed.
You can post messages to a CWinThread derived object using PostThreadMessage. But there are some cases where this is dangerous, discussed here:
http://www.codeproject.com/Articles/225755/PostThreadMessage-Demystified
I am developing an application using the MFC library and I am currently trying to prevent the user accidentally changing one of the combo box controls when they are scrolling the mouse wheel.
I am looking for a solution without deriving a new class from the CComboBox class and preventing the mouse scrolling there.
My understanding of the system is that Windows passes the WM_MOUSEWHEEL message to the Combo box control which handles it (scrolling the combo box) and then this is propagated up the chain of parent controls (so them to my CFormView etc.), which means I cannot prevent the scrolling by capturing the event in my form view.
Does anyone have a solution to this problem? Thanks in advance!
You can always derive a control from CComboBox and trap the WM_MOUSEWHEEL message in the control itself. Then simply use your new derived combo box in your form view.
If you don't want to create a derived class (perhaps it's too big a change for your project), you can subclass the combo box and trap the WM_MOUSEWHEEL there.
Override the PreTranslateMessage handler in the main window class and look for WM_MOUSEWHEEL messages. Compare the pMsg->hwnd handle in PreTranslateMessage handler with the combobox handle, if found, filter the messages away.
I am using MFC MDI. I create a window the main document window. I create another window(lets call it second window) as child of MDI Window View, then I create child window(third window) of second window. Again I need to create another window, child window of third window. I have a button on the ribbon and I want to call message handler in the third window to handle this command. I have added message map and all required stuff but it is not calling the message handler. If I define the message handler in MDI window view, it catches the event. If I dont delare the message handler in my main CWinApp class or MDI window View class the button appears disabled.
All my child view classes are inherited from CWnd and main MDI window is derived from CView. Please let me know what I am missing here.
Saba
I am at the loss here. You are using MFC; why using events? use command messages and command message handlers instead events.
Use MFC implemented and well working command routing.
MFC doesnt route messages generated by clicking Ribbon buttons to child windows. If we want to send messages to child windows of MDI windows we need to do it ourselves. Ribbon button's messages are either passed to active MDI window or CWinApp class.
I have created a derived control handling events as mouse movement, left button down up,down etc.
And I have a popup dialog and within that dialog, three child dialogs.
When I use the derived control in my popup dialog, it is working properly.
But when I place my control in any of the child dialog, the mouse events are not handled.
Please suggest a solution.
Thanks in advance,
Madhan
Must to pass forward the events. Catch them on the child dialog with the respective message handlers and then forward them using the ::SendMessage method.
The popup dialog possibly catched up automatically the mouse events and enabled to be forwarded towards.
I dynamically create some ActiveX controls in my MFC app. I want to handle their event such as click, dblclick. But I don't know what kind of message should I catch where to put the code to catch them.
I can add the event handler if I put the these control on the dialog window as I design the GUI. The code automatically added by MFC is below:
BEGIN_EVENTSINK_MAP(CButtonMsgDlg, CDialog)
ON_EVENT(CButtonMsgDlg, IDC_CWBOOLEAN1, DISPID_DBLCLICK, CButtonMsgDlg::DblClickCwboolean1, VTS_NONE)
END_EVENTSINK_MAP()
void CButtonMsgDlg::DblClickCwboolean1()
{
// TODO: Add your message handler code here
}
If you already know the event type at compile time, but don't know the control ids, check How to create a sink interface in a MFC-based COM client