English 中文(简体)
Handling wm_mousewheel message in WTL
原标题:

I am trying to handle wm_mousewheel for my application.

Code:

BEGIN_MSG_MAP(DxWindow)     
  MESSAGE_HANDLER(WM_MOUSEWHEEL, KeyHandler)
END_MSG_MAP()
.
.
.

LRESULT DxWindow::KeyHandler( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled )
 {
     if(uMsg==wm_mousewheel)
     {
       //Perform task.
     }
     return 0;
 }

But this code doesn t work.KeyHandler doesn t receive wm_mousewheel message. I am testing this application on vista. If my approach is wrong how to handle wm_mousewheel properly? Do vista is responsible for failure in handling wm_mousewheel message?

最佳回答

From the doc: The WM_MOUSEWHEEL message is sent to the focus window when the mouse wheel is rotated. The DefWindowProc function propagates the message to the window s parent. There should be no internal forwarding of the message, since DefWindowProc propagates it up the parent chain until it finds a window that processes it.

  1. Change your test to if(uMsg == WM_MOUSEWHEEL).
  2. Check that your window or one of it s children has focus.
  3. If this is related to your previous wtl-child-window-event-handling question, I edited my answer to not forward WM_MOUSEWHEEL.
问题回答

Well, first, you don t have to somehow check uMsg in message handler, because in this situation every message handler is bound to one concrete message.

Second, these atl macroses usually mean to write something like CHAIN_MSG_MAP(CMyBaseClass) at the end of your map.

Anyway, what you ve posted here looks ok, except this part:

if(uMsg==wm_mousewheel)
{
  //Perform task.
}

Try erasing it, adding a breakpoint to the handler and debugging. Also you could try adding another neutral message handler (such as WM_CLICK) and tracing it s behavior.

This is the example from MSDN, and the code block that you ve posted actually follows it.

class CMyWindow : ...
{
public:
   ...

   BEGIN_MSG_MAP(CMyWindow)
      MESSAGE_HANDLER(WM_PAINT, OnPaint)
      MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
      CHAIN_MSG_MAP(CMyBaseWindow)
   END_MSG_MAP()

   LRESULT OnPaint(UINT uMsg, WPARAM wParam, 
                   LPARAM lParam, BOOL& bHandled)
   { ... }

   LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, 
                      LPARAM lParam, BOOL& bHandled)
   { ... }
};




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签