Forum > Win32/64

Program doesn't close. PeekMessage always has WM_QUIT

(1/3) > >>

wk:
Hi,

I am running Lazaurs 2.0.13 (fixes, with fpcupdeluxe).
I converted an older and big Delphi program to Lazarus. It is for Windows with win32 widgetset. After some work it runs nice.
The program is multithreaded, some timers.

But when I close it PeekMessage in win32object.inc:399 always has a message of WM_QUIT. So the outer loop of AppProcessMessages can not be left.

I tried to replace the 'break' on line 404 with an 'exit': program ends normal. Heap shows no problems.

Is there a way to see where the message is from? How can I debug this problem?

Thanks for your help.

440bx:

--- Quote from: wk on July 06, 2021, 05:17:24 pm ---Is there a way to see where the message is from? How can I debug this problem?

Thanks for your help.

--- End quote ---
That can take a little work.  The "easy" way, which may turn out not to be easy, would be to use GetMessagePos and initially _presume_ the message is caused by one of the windows that contains the position.

The other way, more reliable, is to use an API spy.  That will tell you which window posted the message.   One free and capable API monitor is at rohitab.com

HTH.

wk:
Thank you, that helped.

I tried with the API Monitor, enabled "Windows Application UI Development" -> "Windows and Messages" -> All of "Messages and Message Queues".
The hangs in a loop with
PeekMessageW and PostQuitMessage(0).
Information from PeekMessageW is the same I can get from AMessage in the code.

I got the Window with following code:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Buffer: array[0..256] of Char;       and changed the if to

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---        if AMessage.message = WM_QUIT then        begin          GetWindowTextA(WindowFromPoint(AMessage.pt), Buffer, Length(Buffer));          PostQuitMessage(AMessage.wParam);          break;        end;  
This showed, that the Message is from the main form.
I'm not sure, if WindowFromPoint is reliable, because after letting it run a while Buffer has other window names.

Is there a way to get more information from the API Monitor?


440bx:
The question in my mind is, if there is already a WM_QUIT message in the message queue, there is no need to post another one, letting Windows process the WM_QUIT is the natural thing to do. 

My question is, why are you posting another WM_QUIT ?

wk:
Thanks for the hint.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---PostQuitMessage(AMessage.wParam);is original code from win32object.inc:403

When I remove PostQuitMessage, the program closes without problems.

Is this a bug in the LCL?

Navigation

[0] Message Index

[#] Next page

Go to full version