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

Easy problem with Message handling

Posted on 2004-09-17
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.

Question by:drb2k2
LVL 13

Expert Comment

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.

Author Comment

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.

LVL 13

Expert Comment

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.
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.


Author Comment

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

LVL 16

Expert Comment

by:George Tokas
ID: 12086285
From BCB online help:

Occurs when an application becomes active.

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


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.


Accepted Solution

Cayce earned 125 total points
ID: 12102350
/* Just add a function (public) in your main form */

class PACKAGE TForm1
  /* ... */
  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) */

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hide carret in RichEdit 4 67
edit html 3 140
Visual Studio 2013  Distorts Chrome Browser 2 182
Error E2158 compiling with Delphi XE10 Seattle 2 112
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

856 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