?
Solved

Windows API class overriding - WM_COMMAND problem.

Posted on 2004-10-07
2
Medium Priority
?
601 Views
Last Modified: 2008-01-09
I've been playing around with the Windows API controls a bit, and I started creating some basic wrappers for them out of boredom. I did this by getting the standard class (BUTTON, STATIC, etc), change the name of the class, and changing the WNDPROC to that of my own.
Inside my own WNDPROC, I'd intercept the WM_LBUTTONDOWN, WM_RBUTTONDOWN, etc messages, do what I wanted (call a function pointer if applicable) and then run it through the original classes WNDPROC so it would act and display like normal.
At first it was a bit of a problem, doing things like "button->on_click(function)" type things, since the default standard class (BUTTON, STATIC, etc) sends the WM_COMMAND messages to the parent, and not my WNDPROC, so as a run around, I used the WM_LBUTTONDOWN: call_on_lbd(); inside my WNDPROC etc.
Then after I'd finished playing around with BUTTON, STATIC, COMBOBOX, and EDIT, I started on LISTBOX. The problem with this is that there are no specific messages being sent to my WNDPROC that tell me when a new item is being selected. Yea, it sends things like WM_LBUTTONDOWN, etc. But nothing specific towards what index in the list box is being selected (unlike the combo box where for some reason I receive some WM_COMMAND messages (specifically when something new is being selected) in my WNDPROC and the parents proc... Wierd...).
So my question (finally :P) is this:
Is there any way to redirect, or some how force the WM_COMMAND messages to my WNDPROC function? The parent doesn't need to know when something it being clicked, I want to know that inside my custom class.
A very, very basic code example:

class Control
{
...
      //my override WNDPROC thingy
      static LRESULT CALLBACK wnd_proc(...)
      {
            Control *c = (Control *)GetWindowLong(...);
            WNDCLASS wc;
            GetClassInfo(h_inst, c->base_class(), &wc);

            switch(message) {
            case WM_LBUTTONDOWN:
                  c->call_on_lbd();
            case WM_RBUTTONDOWN:
                  c->call_on_rbd();
            case...
      }

      return wc.lpfnWndProc(...); //call the base class’s WNDPROC
      }
}
0
Comment
Question by:Larn0s
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
KurtVon earned 1000 total points
ID: 12248994
No, unfortunately there is none.  There is a trick called "reflection" that MFC uses.  All MFC windows send these messages to the control window that generated them to see if they are handled there.  I can't remember if the window tries to handle the message bfore or after it reflects them to the control, but I'm sure if there was an easy or standard way to do this without reflection, the MFC programmers would have done it.

Hope this helps.
0
 

Author Comment

by:Larn0s
ID: 12249947
Ah, dang.
Oh well, thanks for the info KurtVon. It helped me do what I wanted (figured it out n' such).
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question