Solved

Trapping WM_CREATE message

Posted on 2004-08-11
11
943 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 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