?
Solved

Easy problem with Message handling

Posted on 2004-09-17
6
Medium Priority
?
746 Views
Last Modified: 2013-11-17
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
Comment
Question by:drb2k2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 13

Expert Comment

by:SteH
ID: 12082803
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
 

Author Comment

by:drb2k2
ID: 12082914
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
 
LVL 13

Expert Comment

by:SteH
ID: 12082953
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.

 

Author Comment

by:drb2k2
ID: 12083027
Yes, I feared I would have to do that it seems like a lot work just to write a message handler

Cheers
DRB2k2
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 12086285
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
 
LVL 9

Accepted Solution

by:
Cayce earned 500 total points
ID: 12102350
/* 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

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question