Converting an executables events to ActiveX

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?
jvoros1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
>>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);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jvoros1Author 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?
jkrCommented:
>>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.
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

itsmeandnobodyelseCommented:
>>>> 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


jkrCommented:
>>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.
itsmeandnobodyelseCommented:
>>>> 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 ....
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.