Solved

Easy problem with Message handling

Posted on 2004-09-17
6
736 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
6 Comments
 
LVL 13

Expert Comment

by:SteH
Comment Utility
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
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:drb2k2
Comment Utility
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
Comment Utility
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 125 total points
Comment Utility
/* 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now