Board index » delphi » Doing something wrong...

Doing something wrong...

program Project1;
uses Windows;
var Msg: TMsg;
begin

  while GetMessage(Msg, 0, 0, 0) do
  begin
    TranslateMessage(Msg);
    DispatchMessage(Msg);
  end;

end.

Step 1. Compile.
Step 2. Run.
Step 3. Ctrl+Alt+Delete, and kill Project1. It immediately says that the
application is not responding. What am I doing wrong here?

TiA

 

Re:Doing something wrong...


Quote
Sean Hamilton wrote:

> program Project1;
> uses Windows;
> var Msg: TMsg;
> begin

>   while GetMessage(Msg, 0, 0, 0) do
>   begin
>     TranslateMessage(Msg);
>     DispatchMessage(Msg);
>   end;

> end.

We are trying to be smart aren't we.

Helpful hint: Before calling GetMessage, try having a handle with which
to get messages.

MH.

--
Martin Harvey. mar...@pergolesi.demon.co.uk
     http://www.pergolesi.demon.co.uk

The Usenet Oracle has pondered your question deeply.  Your question
was: Will your answer to this question be in the negative?
And in response, thus spake the Oracle: Memory fault.  Core dumped.

Re:Doing something wrong...


Sean Hamilton <breadst...@planetquake.com> skrev i en
nyhedsmeddelelse:Ruxi4.4246$nh2.143...@cac1.rdr.news.psi.ca...

Quote
>   while GetMessage(Msg, 0, 0, 0) do
>   begin
>     TranslateMessage(Msg);
>     DispatchMessage(Msg);
>   end;

> application is not responding. What am I doing wrong here?

You have successfully created an endless loop.
You should look for a WM_QUIT message and quit when you receive it.

Finn Tolderlund

Re:Doing something wrong...


In article <Ruxi4.4246$nh2.143...@cac1.rdr.news.psi.ca>, "Sean Hamilton"

Quote
<breadst...@planetquake.com> writes:
>  while GetMessage(Msg, 0, 0, 0) do
>  begin
>    TranslateMessage(Msg);
>    DispatchMessage(Msg);
>  end;

I don't know for sure but maybe 0 is an invalid handle so GetMessage is
returning -1 but Delphi is interpreting that as true rather than false (I've
found some oddities in pointers as boolean).

Although you are actually handling messages at that point, an
Application.ProcessMessages at the end of the loop would correcxt matters, and
demonstrate if my theory is correct.

Alan Lloyd
alangll...@aol.com.

Re:Doing something wrong...


Quote
Finn Tolderlund wrote:

> You have successfully created an endless loop.
> You should look for a WM_QUIT message and quit when you receive it.

True... but that won't cause task manager to indicate that the app is
not responding. All task manager needs to check is that the app receives
messages OK, which it doesn't.

MH.

--
Martin Harvey. mar...@pergolesi.demon.co.uk
     http://www.pergolesi.demon.co.uk

The Usenet Oracle has pondered your question deeply.  Your question
was: Will your answer to this question be in the negative?
And in response, thus spake the Oracle: Memory fault.  Core dumped.

Re:Doing something wrong...


Quote
Sean Hamilton wrote...
>program Project1;
>uses Windows;
>var Msg: TMsg;
>begin

>  while GetMessage(Msg, 0, 0, 0) do
>  begin
>    TranslateMessage(Msg);
>    DispatchMessage(Msg);
>  end;

>end.

>Step 1. Compile.
>Step 2. Run.
>Step 3. Ctrl+Alt+Delete, and kill Project1. It immediately says that the
>application is not responding. What am I doing wrong here?

I might be mistaken, but this could be because you haven't got any wndporc
associated with the current thread. I think 'does not respond' means windows
failed to send message such as WM_QUIT to your app. Help says that
DispatchMessage dispatches messages to window procedure.

Try creating hidden window. I got an api-written app and everything works
ok - kill works nicely, I just do some job on wm_quit and wm-destroy.

Bye.
/lexi

Re:Doing something wrong...


The line

while GetMessage(Msg, 0, 0, 0) do

will break on WM_QUIT. So there! :)

Quote
Martin Harvey <mar...@pergolesi.demon.co.uk> wrote in message

news:388B64E4.E1A08110@pergolesi.demon.co.uk...
Quote
> Finn Tolderlund wrote:

> > You have successfully created an endless loop.
> > You should look for a WM_QUIT message and quit when you receive it.

> True... but that won't cause task manager to indicate that the app is
> not responding. All task manager needs to check is that the app receives
> messages OK, which it doesn't.

> MH.

> --
> Martin Harvey. mar...@pergolesi.demon.co.uk
>      http://www.pergolesi.demon.co.uk

> The Usenet Oracle has pondered your question deeply.  Your question
> was: Will your answer to this question be in the negative?
> And in response, thus spake the Oracle: Memory fault.  Core dumped.

Re:Doing something wrong...


AlanGLLoyd wrote in <20000123114537.25251.00000...@nso-bk.aol.com> ...

Quote
>>  while GetMessage(Msg, 0, 0, 0) do
>>  begin
>>    TranslateMessage(Msg);
>>    DispatchMessage(Msg);
>>  end;

>I don't know for sure but maybe 0 is an invalid handle so GetMessage is
>returning -1 but Delphi is interpreting that as true rather than false
(I've
>found some oddities in pointers as boolean).

GetMessage(Msg,0,0,0) is truly valid (it's tested). 0 means it gets all the
thread's messages, but not only hwnd's.

Quote
>Although you are actually handling messages at that point, an
>Application.ProcessMessages at the end of the loop would correcxt matters,
and
>demonstrate if my theory is correct.

Alan, Application.ProcessMessages works nearly the same way as this cycle
does. Although it uses PeekMessage instead of GetMessage, the idea is
exactly the same, so this cycle is fully correct.

Using Application means using forms unit. And all [beep] vcl stuff. It is
noot needed when writing clear api applications.

Bye.
/lexi

Re:Doing something wrong...


Quote
On Sat, 22 Jan 2000 22:50:10 -0800, Sean Hamilton wrote:
>program Project1;
>uses Windows;
>var Msg: TMsg;
>begin

>  while GetMessage(Msg, 0, 0, 0) do
>  begin
>    TranslateMessage(Msg);
>    DispatchMessage(Msg);
>  end;

>end.

>Step 1. Compile.
>Step 2. Run.
>Step 3. Ctrl+Alt+Delete, and kill Project1. It immediately says that the
>application is not responding. What am I doing wrong here?

Your application creates no windows.  Messages are sent to windows.  No
windows, no way to post a message to your app.  If you can't send it a
message, then obviously it can't respond to one.

--
"The privileged being which we call human is distinguished from other
animals only by certain double-edged manifestations which in charity we
can only call 'inhuman.'" -- Epiktistes

Re:Doing something wrong...


Quote
Sean Hamilton wrote:

> The line

> while GetMessage(Msg, 0, 0, 0) do

> will break on WM_QUIT. So there! :)

I reckon it'll break on just about anything :-PP

MH.

--
Martin Harvey. mar...@pergolesi.demon.co.uk
     http://www.pergolesi.demon.co.uk

The Usenet Oracle has pondered your question deeply.  Your question
was: Will your answer to this question be in the negative?
And in response, thus spake the Oracle: Memory fault.  Core dumped.

Other Threads