Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 747
  • Last Modified:

Easy problem with Message handling

Hi all,

I'm pretty sure this is going to be a very easy question, but i've just started with C++ Builder and don't quite understand it yet.

Basically I need to set the Application->OnActivate to a custom function.

I can't seem to find out how to do this.

Every function declaration I try throws up a declaration error.

If I add in

void __fastcall (__closure *TNotifyEvent)(System::TObject, TObject* Sender);

it compiles, but where do I put the name of this function? And where do I put the body of code.

Any help greatly appreciated.

Cheers
DRB2k2
0
drb2k2
Asked:
drb2k2
1 Solution
 
SteHCommented:
Is the application based on a Form? In that case I would suggest to look at the form in the object explorer. Go to the events tab and write a name to the right of OnActivate. This should create the correct body ready for you to edit.
0
 
drb2k2Author Commented:
hmmm ok perhaps my understanding of this is wrong.
But here goes.
It the exe file there is an application pointer. whereby I call
Application->MainForm = A form i've designed

But my problem is that I have written a specific message handler in the Form object. Now when it gets a WM_ACTIVATEAPP message I want it to do something. But it never does. I'm guessing that the messages are getting filtered out somewhere along the line.

I have done some examining and found out that the parent handle to the Form is the application handle. Therefore I assume that my message is getting filtered out in the application message handler.

Since you can set Application->OnActivate to equal a form OnActivate I wanted to design my own custom function to handle this problem.

Note that I can't set application->OnActivate to MainForm->Activate because MainForm is an MDI window that may or may not be needed.

Cheers
DRB2k2
0
 
SteHCommented:
If MainForm is an MDI window (child?) what window/form is visible all the time to choose a child or open and close them. In my understanding MainForm should be always visible and responsible for this. In that case the difference of Application->OnActivate and MainForm->OnActivate should be marginal. In the case that MainForm is a child form there is a great difference I agree.

For my projects no Application derived class existed. But it should be possible to override the OnActivate for it. Most likely you have to derive a class from TApplication in that case and just override OnActivate with your code and assure that your class is used as global Application instance.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
drb2k2Author Commented:
Yes, I feared I would have to do that it seems like a lot work just to write a message handler

Cheers
DRB2k2
0
 
George TokasCommented:
From BCB online help:

TApplication::OnActivate
Occurs when an application becomes active.

__property Classes::TNotifyEvent OnActivate = {read=FOnActivate, write=FOnActivate};

Description

Write an OnActivate event handler to perform special processing when the application becomes active.

An application becomes active when it is initially run or when focus moves from another Windows application back to any window of the application.

That means that you can override this function declaring at Form::Form unit as follows:

Application->OnActivate = MyActivateFunction;
You have also to declare the function on main form's header file at "public" section.

gtokas.
0
 
CayceCommented:
/* Just add a function (public) in your main form */

class PACKAGE TForm1
{
  /* ... */
public:
  void __fastcall ApplicationActivate(TObject* Sender);
};

void __fastcall TForm1::ApplicationActivate(TObject* Sender)
{
  /* Your code */
}

/* And in your constructor */
__fastcall TForm1::TForm1(TComponent Owner) : TForm(Owner)
{
  Application->OnActivate = ApplicationActivate;
}

/* __closure is used to create VARIABLES that poing to procedures, for events you create real procedures and assign them to __closure variables (which are called by the event thrower) */
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

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