Hi Glenn,

I admit I was looking at a slightly older version of the CVS (since I
can't get access to CVS at work anymore), but most things are the same
from what I checked at home.

You mention that messages are queued and combined. I'd not class myself
as highly experienced with Windows messaging, but the PeekMessage call
in DoEvents specifies "PM_REMOVE" to delete the message it captures from
the queue, so this message should be removed. Are you saying that when
one uses PeekMessage, WM_LBUTTONDOWN messages will be continually
generated by windows, even if PM_REMOVE is specified?

The problem is that if GetMessage is called when the mouse button is
down, the WM_LBUTTONDOWN message is received, and if you then call
GetMessage again, no message is received. However if you call
PeekMessage with PM_REMOVE set you get the WM_LBUTTONDOWN message, then
if you call PeekMessage again with PM_REMOVE set, you get the
WM_LBUTTONDOWN message a second time, then a third time, over and over
*until another event occurs such as WM_PAINT or WM_MOUSEMOVE*.

There is a function (WaitForInputIdle)that "waits until the specified
process is waiting for user input with no input pending, or until the
time-out interval has elapsed" and a flag for PeekMessage (PM_NOYIELD)
that "prevents the system from releasing any thread that is waiting for
the caller to go idle"

Perhaps these might fix the problem?

I'm pretty sure that the textfield character-doubling could be to do
with the fact that one gets both WM_KEYDOWN and WM_KEYUP messages when a
key is pressed, and a character is produced for both for some reason. I
will muck about with the CVS version (which I can now obtain at work
thanks to my cute PC-Anywhere-Via-HTTP-Proxy thingy :) ) and see if I
can find a way to solve the problem.

Steve

-----Original Message-----
From: Glenn Linderman [mailto:[EMAIL PROTECTED]
Sent: 09 December 2003 19:03
To: Stephen Pick
Cc: Win32 GUI Hackers
Subject: Re: [perl-win32-gui-hackers] DoEvents() bug.


On approximately 12/9/2003 2:59 AM, came the following characters from
the keyboard of Stephen Pick:

> Hi all.
> 
> When I do this:
> 
> Win32::GUI::Dialog()
> 
> I receive all my events like WM_LBUTTONDOWN (-onMouseDown) once, as
> should happen.
> 
> When I do this:
> 
> while(1) {
>       Win32::GUI::DoEvents()
>       print "Loop!\n";
> }
> 
> I get endless calls to my event handler so long as the mouse button is
> down. I have NO idea why. Must be some kind of windows internal thing.

Certain Windows messages are "queued and combined" if you are not 
looking, but the more often you look, the more often you get them....  I

could say if MouseDown is one of those, off hand.

I have noticed that a difference between Dialog() and DoEvents() is that

if used to process a dialog box containing a text box, that the former 
responds normally, but the latter generally doubles the characters 
received by the text box.  One difference in my situation is that I was 
  calling DoEvents() from an event, and that might cause some sort of 
reentrancy problem, but I couldn't understand what it would be if it is 
such.  I gave up and restructured my code to use Dialog() only.

> Additionally, since the code for DoEvents() and Dialog() is
practically
> identical except that DoEvents uses PeekMessage and Dialog uses
> GetMessage, I copied both into seperate files and took a look at them
in
> WinMerge. Interesting. Dialog does ENTER; SAVETMPS; before doing
> GetMessage and FREETMPS; LEAVE; at the end of it's while() loop.
> DoEvents() doesn't do this. 

This is because Dialog is "long-running" and needs to be sure to do Perl

temporary variable management, and DoEvents returns to Perl more often, 
so can let Perl do the temporary variable management.  I think.

> Also, DoEvents has the line "acc =
> perlud->hAcc;", and Dialog() DOESNT have that. Dialog() does a
> comparison on acc (acc != NULL) in the next few lines just like
DoEvents
> does, but this comparison will always yield false in Dialog().

I think that was one of the lines I "fixed" in making accelerator keys 
work.  If not, it should have been.  What version of source are you 
looking at?

> So. I don't have a compiler here but this is weird. Surely these
> functions should be identical but for the change from GetMessage to
> PeekMessage. Moreover, if these functions should be identical then why
> write the same code for both when a simple function that does either
> PeekMessage or GetMessage depending on an argument would remove a lot
of
> redundant code, for example the new function checkEvents(hwnd,
> peekmessage) would do the current Dialog() code with PeekMessage if
> peekmessage was set to 1, otherwise it'd do GetMessage, and the
Dialog()
> and DoEvents() methods could be truncated to:

Well, the exit condition is different too, not just the call to 
GetMessage vs PeekMessage.  But that also could be based on the 
"argument".  I agree there is much redundant code there, also see
DoModal.

> 
> DWORD
> Dialog(hwnd=NULL)
>       HWND hwnd
> CODE:
>       RETVAL = checkEvents(hwnd,0);
> OUTPUT:
>       RETVAL
> 
> DWORD
> DoEvents(hwnd=NULL)
>       HWND hwnd
> CODE:
>       RETVAL = checkEvents(hwnd,1);
> OUTPUT:
>       RETVAL
> 
> 
> 
> Steve
> 
> 
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive?  Does it
> help you create better code?  SHARE THE LOVE, and help us help
> YOU!  Click Here: http://sourceforge.net/donate/
> _______________________________________________
> Perl-Win32-GUI-Hackers mailing list
> Perl-Win32-GUI-Hackers@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-hackers
> 
> 

-- 
Glenn -- http://nevcal.com/
===========================
Like almost everyone, I receive a lot of spam every day, much of it
offering to help me get out of debt or get rich quick.  It's ridiculous.
-- Bill Gates

And here is why it is ridiculous:
  The division that includes Windows posted an operating profit of $2.26

  billion on revenue of $2.81 billion.
  --from Reuters via 
http://biz.yahoo.com/rc/031113/tech_microsoft_msn_1.html

So that's profit of over 400% of investment... with a bit more 
investment in Windows technology, particularly in the area of 
reliability, the profit percentage might go down, but so might the bugs 
and security problems?  Seems like it would be a reasonable tradeoff. 
WalMart earnings are 3.4% of investment.


Reply via email to