• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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