Page 1 of 1

Window WM_CLOSE

Posted: Fri Nov 20, 2009 3:36 pm
by Gary Woodley
Hi,

We have a Main.exe program that calls various other executeables. When we close the Main program we send as an example:-
SendMessage( FindWindow( 0, default_text("TITLE","ORDERS") ), WM_CLOSE ) to all the seperate executeables.

One of our programs (ORDERS.exe) opens a seperate MDI window, unfortunately when it receives the WM_CLOSE it actually errors before the VALID is called that closes the MDI window. Is there any way to catch WM_CLOSE so I can close the MDI as soon as it receives the message.

I have added an MDI window close which is called on the VALID of the ORDERS screen and it closes correctly, but when the ORDERS.exe receives the WM_CLOSE from the Mian window it errors before the VALID is called.

Any ideas how to stop the error?

Regards

Gary

Re: Window WM_CLOSE

Posted: Fri Nov 20, 2009 4:42 pm
by Antonio Linares
Gary,

Here you have a working example to manage WM_CLOSE yourself:

Code: Select all

#include "FiveWin.ch"

function Main()

   local oWnd := TMyMDI():New()

   ACTIVATE WINDOW oWnd

return nil

CLASS TMyMDI FROM TMDIFrame

   METHOD HandleEvent( nMsg, nWParam, nLParam )

ENDCLASS

METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TMyMDI

   if nMsg == WM_CLOSE
      return nil // nil requires default Windows behavior
   endif
   
return Super:HandleEvent( nMsg, nWParam, nLParam )   
 
Could you please post here your error.log to review it ? thanks

Re: Window WM_CLOSE

Posted: Wed Nov 25, 2009 3:46 pm
by Gary Woodley
Hi Antonio,

Does that mean I have to change my original class that created the MDI Window?

Unfortunately I don’t get an error log, but the Visual Studio Just-in-time debugger displays stating ‘An unhandled Win32 exception has occurred’ . If I run the program on a Vista system no error seems to occur. Opening Microsoft Visual Studio displays:-
Unhandled exception at 0x0044e55a in ord_mod.exe: 0xC0000005: Access violation reading location 0x00000000.

Regards

Gary

Re: Window WM_CLOSE - Solved

Posted: Wed Nov 25, 2009 4:09 pm
by Gary Woodley
Hi Antonio,

Problem solved, we issue a SendMessage( FindWindow( 0, "NEWSCHED" ), WM_CLOSE ) followed by Inkey(.1) to the window (NEWSCHED) that was causing the problem and now functions correctly. Needed the time delay as well, I assume to allow the mdi to close before the main window closed.

Regards

Gary

Re: Window WM_CLOSE

Posted: Wed Nov 25, 2009 6:26 pm
by Antonio Linares
Gary,

> Does that mean I have to change my original class that created the MDI Window?

Yes, you may modify FWH\source\classes\mdiframe.prg, recompile it and use it as another OBJ of your EXE, or use an inherited Class as I have shown you.

There is no other way to modify the behavior for WM_CLOSE management.