Solved

Windows API class overriding - WM_COMMAND problem.

Posted on 2004-10-07
2
588 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
2 Comments
 
LVL 11

Accepted Solution

by:
KurtVon earned 250 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

770 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