Solved

Windows API class overriding - WM_COMMAND problem.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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 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…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now