We help IT Professionals succeed at work.

Converting an executables events to ActiveX

jvoros1
jvoros1 asked
on
Medium Priority
312 Views
Last Modified: 2012-06-22
I'm in the process of converting a windows app to an ActiveX control and I'm having some trouble with the event handelling.

Mainly I'm not sure how I can get 2 files to communicate with one another.  In winWindow.cpp I have the older way of processing events:

static LRESULT PASCAL WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   switch ( message )
   {
      case WM_POWERBROADCAST:
      {
etc...

In axPlugin.h I have the ATL way of processing events:


BEGIN_MSG_MAP(CaxPlugin)
   MESSAGE_HANDLER(WM_INITDIALOG, OnCreate)
    CHAIN_MSG_MAP(CComCompositeControl<CaxPlugin>)
END_MSG_MAP()

How do I get the events in axPlugin.h to run the code in winWindow.cpp?
Is there any catch all way I can do it or do I have to create a new function for every event?
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2012
Commented:
>>Is there any catch all way I can do it or do I have to create a new function for every event?

Let's rather say there is an eays way - remove the 'static' keyword and use 'WindowProc()' like any other function - given that is not used as a WNDPROC at the same time, e.g. in 'OnCreate()', call

WindowProc(m_hWnd,WM_INITDIALOG, wParam,lParam);

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Does that only work for WM_INITDIALOG?
Do I need to add that line for every type of event that I need to process?
or is that sending the code in to that function with every event?
jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
>>Does that only work for WM_INITDIALOG?

No, for any message that is handles in 'WindowProc()' and you have an ATL message handler.

>>Do I need to add that line for every type of event that I need to process?

Yes, that's the idea. The cleaner way would be to port the handling code from 'WindowProc()' to the appropriate ATL handler.
>>>> remove the 'static' keyword and use 'WindowProc()' like any other function

No, that is not the way you should do it. Actually, the WindowProc way is the less comfortable way. Look at the following macro:

>>>> MESSAGE_HANDLER(WM_INITDIALOG, OnCreate)

Here, the ATL wizard already made an association between the OnCreate function (handler) of your window class and the WM_INITDIALOG message. In WindowsProc you somewhere had a switch statement and a

>>>> case WM_INITDIALOG:

statement. You simply could take your old code from below 'case WM_INITDIALOG:'  and put it into the OnCreate member function. Then get rid of all  HWND and plain WinAPI and use the appropriate classes and member functions.

If you need to handle more events simply add the appropriate MESSAGE_HANDLER macro (and a member function).

Regards, Alex


jkr
CERTIFIED EXPERT
Top Expert 2012

Commented:
>>No, that is not the way you should do it.

Interesting. Why should that not work? I wrote that the cleaner way to do that would be to port the funcionality, but I cannot see any reason for that to cause problems.
>>>> Interesting. Why should that not work?

Why did you ask? You already answered yourself. The idea to call old WindowsProc in an Active X control is weird ...

Unfortunately, there is no idea so bad that no one will honour it ....
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.