Solved

Trapping WM_CREATE message

Posted on 2004-08-11
11
960 Views
Last Modified: 2008-02-01
Is it possible to execute an event whenever a process is being created?

When i take a look at WinSight32, i see that it's able to catch all WM_CREATE messages. However, Application.OnMessage won't catch them all, only those that are sent directly to my application.

Thus, actually, my question comes down to: "can i trap ALL WM_CREATE messages?"

Thanks!
Evarest
0
Comment
Question by:Evarest
[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
  • 7
  • 4
11 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11781096
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
  private
  protected
    procedure OnWMCreate (var Msg: TWMCreate); message WM_CREATE;
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.OnWMCreate(var Msg: TWMCreate);
begin
  // your code here
  ShowMessage('CREATE');
end;

end.
0
 
LVL 4

Author Comment

by:Evarest
ID: 11781835
That's the code i used, but this won't work for messages _outside_ my application.

Again, i want to have a procedure that can trap ->ALL<- WM_CREATE messages, thus also those that originate from other applications...

Evarest
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11781875
If you want to take all WM_CREATE messages - you will have to use global hook DLL.

http://www.gajits.com/delphihooks.asp
this is a good place to start from.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:Evarest
ID: 11782143
That works!

However it seems that setting hooks slows down your system quite a bit. When I set the hook and open an app, all tends to take more time than before... Can it be that these hooks are kind of bottlenecks?
0
 
LVL 4

Author Comment

by:Evarest
ID: 11782147
And if so, is there a better way to know when a new process is being started (without having to create a list with all processes)?
0
 
LVL 4

Author Comment

by:Evarest
ID: 11782200
Forget i asked, i think i'm being somewhat paranoid :-)

However, still, is there a way to know when a new process is being started (without having to create a list with all processes)? I'd rather not use the hook, as WM_CREATE messages tend to popup quite often...

Evarest
0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 50 total points
ID: 11782206
Frankly, I don't know another way to trap messages from another application.

I used hooks before (for key-logger) and I don't think this slows down the system. You can cause some slow with some wrong loop inside the hook or something else. But basically the hook will not affect the system performance in a way that user can notice.
0
 
LVL 4

Author Comment

by:Evarest
ID: 11784025
OK,

seems that there isn't another way to see when a process in being launched...

Thanks!
Evarest
0
 
LVL 4

Author Comment

by:Evarest
ID: 11789023
Just for the curious ones :-)

I have managed to find why my code seemed to slow down my computer.

The problem lays in the code included in the hooking dll Ivanov_G directed me to:

http://www.gajits.com/delphihooks.asp

When I run this code (i used the dll CALLWNDPROCRET.dpr), it'll do a callback on a procedure:

function WNDPROCRET_HookProc(nCode: Integer; iWPARAM: wParam; iLPARAM: lParam): LResult; stdcall;

As your dll is kind-a attached to your application, by use of SetMainHandle(Handle: HWND), it'll get into problems when you focus or even move your mouse over any form, control, whatever of your application! You'll see that your CPU usage jumps from 0-95 in about a sec :-)

I couldn't find a real solution, except sending some extra information whether the program was maximized or not to the dll. However, this didn't seem to work completely...

As i couldn't solve this problem completely, i decided not to use Hooks after all...

Evarest
0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11790723
"your CPU usage jumps from 0-95 in about a sec"

I didn't have this problem when using hooks. I don't know what to advice you.
0
 
LVL 4

Author Comment

by:Evarest
ID: 11791314
Maybe that's because you only use the WH_GETMESSAGE. This will only monitor the mousebutton and keyboard, and thus won't give any problems regarding CPU... (as all other messages are disregarded)
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

724 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