?
Solved

Trapping WM_CREATE message

Posted on 2004-08-11
11
Medium Priority
?
971 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

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