Solved

Windows API class overriding - WM_COMMAND problem.

Posted on 2004-10-07
2
592 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

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

Suggested Solutions

Title # Comments Views Activity
Writing a parser for java language 4 91
C++ to C# code conversion issue 4 117
Finding Divisors 5 35
what type of pointer is this pointer? 3 22
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

735 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