• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

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?
0
jvoros1
Asked:
jvoros1
  • 3
  • 2
1 Solution
 
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);
0
 
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?
0
 
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.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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


0
 
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.
0
 
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 ....
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now