[DUG] manually process Windows messages

Ross Levis ross at stationplaylist.com
Tue Jan 26 13:48:12 NZDT 2010


Initial results are looking good, thanks Xander!  Initially I had to "Use"
the Controls and Messages units, which bloated the exe again.  But went
through and found the required constants.  I'll post these here in case it
is useful for someone in the future reading the archives.

 

 const

  WM_QUIT             = $0012;

  WM_NCMOUSEMOVE      = $00A0;

  WM_KEYFIRST         = $0100;

  WM_KEYLAST          = $0108;

  WM_COMMAND          = $0111;

  WM_MOUSEMOVE        = $0200;

  WM_MOUSELAST        = $020A;

  CM_BASE             = $B000;

  CM_ACTIVATE         = CM_BASE + 0;

  CM_DEACTIVATE       = CM_BASE + 1;

  CM_APPKEYDOWN       = CM_BASE + 22;

  CM_APPSYSCOMMAND    = CM_BASE + 23;

  CN_BASE              = $BC00;

 

 

From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Xander (GMail)
Sent: Tuesday, 26 January 2010 10:33 a.m.
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] manually process Windows messages

 

Here is an extract from a class from a very old piece of code I have. I
vaguely remember researching the same topic at the time. See whether this
will work for you (just call the ProcessMessages() method):

 

//--------------------------------------------------------------------------
----

procedure TMain.ProcessMessages;

begin

  while ProcessMessage do {loop};

end;

 

//--------------------------------------------------------------------------
----

function TMain.ProcessMessage: Boolean;

var

  Msg: TMsg;

begin

  Result := False;

  if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then

  begin

    Result := True;

    if Msg.Message <> WM_QUIT then

    begin

      if not IsHintMsg(Msg) and not IsKeyMsg(Msg)  then

      begin

        TranslateMessage(Msg);

        DispatchMessage(Msg);

      end;

    end;

  end;

end;

 

//--------------------------------------------------------------------------
----

function TMain.IsHintMsg(var Msg: TMsg): Boolean;

begin

  with Msg do

    Result := ((Message >= WM_KEYFIRST) and (Message <= WM_KEYLAST)) or

      ((Message = CM_ACTIVATE) or (Message = CM_DEACTIVATE)) or

      (Message = CM_APPKEYDOWN) or (Message = CM_APPSYSCOMMAND) or

      (Message = WM_COMMAND) or ((Message > WM_MOUSEMOVE) and

      (Message <= WM_MOUSELAST)) or (Message = WM_NCMOUSEMOVE);

end;

 

//--------------------------------------------------------------------------
----

function TMain.IsKeyMsg(var Msg: TMsg): Boolean;

var

  WND: HWND;

begin

  Result := False;

  with Msg do

    if (Message >= WM_KEYFIRST) and (Message <= WM_KEYLAST) and

      (GetCapture = 0) then

    begin

      Wnd := HWnd;

      if SendMessage(Wnd, CN_BASE + Message, WParam, LParam) <> 0 then

        Result := True;

    end;

end;

 

Cheers

Xander

 

  _____  

From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of Jolyon Smith
Sent: Tuesday, January 26, 2010 10:24 AM
To: 'NZ Borland Developers Group - Delphi List'
Subject: Re: [DUG] manually process Windows messages

 

I wouldn't expect that at all.  I forget the details of why, but using the
Forms unit unavoidably drags in a whole host of VCL code.  This is easily
tested, just try compiling:

 

program Vacuum;

begin

end.

 

And you get an EXE of 22KB.  Simply adding a "uses Forms;", even without
referencing anything from the Forms unit in the "code" and your equally
non-functional vacuum.exe "explodes" to 382KB (BDS2006).

 

Having said that, 382KB is not exactly excessive "bloat" in my book.

 

So my question for the original poster is what criteria is it that demands
that the executable absolutely has to avoid this overhead?

 

 

From: delphi-bounces at delphi.org.nz [mailto:delphi-bounces at delphi.org.nz] On
Behalf Of John Bird
Sent: Tuesday, 26 January 2010 9:55 a.m.
To: NZ Borland Developers Group - Delphi List
Subject: Re: [DUG] manually process Windows messages

 

I would expect if you specify Forms (to get Application.ProcessMessages) and
only call that and nothing else from Forms then you will only get what
functions are needed linked into your application - I suggest you try it and
see how much bigger it makes the application.

 

John

 

I've looked at what Application.ProcessMessages does but I'm not sure what I
need to get this working.  Any thoughts appreciated, or some code J.

 

Thanks,

Ross.

Tauranga.


  _____  


_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi at delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to delphi-request at delphi.org.nz with Subject:
unsubscribe

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20100126/721ff77b/attachment-0001.html 


More information about the Delphi mailing list