Window Closing Question/Problem

Window Closing Question/Problem

Postby PeterHarmes » Thu Apr 15, 2010 10:06 am

Hi,

I have an app that can open a window to display a mapping web site, the mapping web site can take a while to load (site is java based), so when the app starts, i open the window, load the web site (using tactivex) and then hide the window. Then if the user wants to go to the mapping section of the app, the system shows the window to give the impression that the window loads instantly - this works well.

When the app closes, i try to close the window on the valid of the app window, this gives the appearance that both windows have closed, but when you look in task manager the executable is still running. If i call the window close routine that is in the valid from a menu option, the web window closes ok and then when i close the app, the app closes correctly.

Is there a problem opening a window within a window or is there another way of closing the window on exit of the app?

I have tried 2 methods for closing the web window - oWnd:End() and SendMessage( FindWindow( 0, Default_Text("TITLE", "DEVHIST") ), WM_CLOSE ) - both give the same results.

Regards,

Pete
PeterHarmes
 
Posts: 363
Joined: Wed Feb 15, 2006 2:06 pm
Location: Oxford, England

Re: Window Closing Question/Problem

Postby Richard Chidiak » Thu Apr 15, 2010 11:01 am

Pete

I have been through some problems closing windows inside windows

The way i fixed it is at follows

IF WNDPMAIN # NIL
WNDPMAIN:SetFocus()
WNDPMAIN:PostMsg(WM_CLOSE)
WNDPMAIN := NIL
ENDIF

HTH

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: Window Closing Question/Problem

Postby PeterHarmes » Thu Apr 15, 2010 11:11 am

Hi Richard,

Thanks for the response but the same results i'm afraid - if i close the window before i click on exit, the app closes correctly, if the app tries to close the window through the valid of the original window, the exe remains open (but appears to have closed)

It looks like the closing of the second window is interfering with the closing of the first window (if closed through the valid)

Best regards,

Pete
PeterHarmes
 
Posts: 363
Joined: Wed Feb 15, 2006 2:06 pm
Location: Oxford, England

Re: Window Closing Question/Problem

Postby Richard Chidiak » Thu Apr 15, 2010 11:44 am

Pete

You can also try this

hWnd := FindWnd(....the windo title )
if hWnd != nil
BringWindowToTop( hWnd )
hWnd:SetFocus()
hWnd:PostMsg(WM_CLOSE)
hWnd := NIL
SENDMESSAGE( hWnd, 16 )
ENDIF

HTH
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: Window Closing Question/Problem

Postby PeterHarmes » Thu Apr 15, 2010 11:56 am

Richard: I will try your suggestion in a minute.

I have an example of the problem: - if i call the 2nd window after the on init (through a menu option) the app closes fine - in this example, the window is opened on init and fails to close properly:

Run the app and click on exit - the app will appear to close but will still be running in task manager

Code: Select all  Expand view
#include "FiveWin.ch"
#include "InKey.ch"

STATIC oWnd, oWnd2, oActiveX

FUNCTION main
    PUBLIC cEvents := ""   
   DEFINE WINDOW oWnd FROM 2, 2 TO 20, 70 ;
      TITLE "Test" ;
      MENU BuildMenu()

  ACTIVATE WINDOW oWnd MAXIMIZED ;
  ON INIT OpenNewWind() ;
  VALID ExitApp()
RETURN nil

STATIC FUNCTION BuildMenu
    Local oMenu
    MENU oMenu 2007
        MENUITEM "&Exit" ACTION oWnd:End()
        //MENUITEM "&Open" ACTION OpenNewWind()
        MENUITEM "&Show" ACTION oWnd2:Show()
        MENUITEM "&Hide" ACTION oWnd2:Hide()
    ENDMENU
RETURN oMenu

STATIC FUNCTION ExitApp
    IF oWnd2 <> NIL
        oWnd2:End()
    ENDIF
RETURN .T.

STATIC FUNCTION OpenNewWind
    LOCAL cUrl    := "http://217.35.79.149:9090/emapping/emapping.aspx?key=PNL001&group=0EDF4DF3-150D-BC82-5894-433C2898DF0B&width=960&height=559&language=ENGLISH&address=OX51LG&zoom=14&config=account:N;groups:N;routes:N;fences:N;markers:N;devices:N;toolbar:N;showaddress:N;showcoords:Y;"

    DEFINE WINDOW oWnd2 FROM 2, 2 TO 20, 70 ;
        TITLE "Test2" ;
        MENU BuildMenu2()
       
        oActiveX = TActiveX():New( oWnd2, "Shell.Explorer" )

        oWnd2:oClient = oActiveX // To fill the entire window surface

        oActiveX&#058;Do( "Navigate", cUrl )
   
    ACTIVATE WINDOW oWnd2 ON INIT oWnd2:Hide()
RETURN NIL

STATIC FUNCTION BuildMenu2
    Local oMenu
    MENU oMenu 2007
        MENUITEM "&Exit" ACTION oWnd2:End()
    ENDMENU
RETURN oMenu

function EventInfo( event, aParams, pParams, oActiveX )
   local cMsg := "Event: " + cValToChar( event ) + CRLF
   local n
   
   cMsg += "Params: " + CRLF
   
   for n = 1 to Len( aParams )
      cMsg += cValToChar( aParams[ n ] ) + CRLF
   next
   
   if event == "BeforeNavigate2"
      // MsgInfo( aParams[ 2 ] )
      // SetEventParam( pParams, 7, .t. ) // Comment this to allow navigation
   endif  

return cMsg + CRLF

function OleInvoke( hObj, cMethod, uParam )

#ifndef __XHARBOUR__
   return __ObjSendMsg( TOleAuto():New( hObj ), cMethod, uParam )
#else  
   local aParams := hb_aParams()

   aParams[ 1 ] = TOleAuto():New( hObj )

   return hb_execFromArray( @__ObjSendMsg(), aParams )  
#endif

function OleSetProperty( hObj, cPropName, uValue )

return __ObjSendMsg( TOleAuto():New( hObj ), "_" + cPropName, uValue )

function OleGetProperty( hObj, cPropName )

return __ObjSendMsg( TOleAuto():New( hObj ), cPropName )
 
PeterHarmes
 
Posts: 363
Joined: Wed Feb 15, 2006 2:06 pm
Location: Oxford, England

Re: Window Closing Question/Problem

Postby Daniel Garcia-Gil » Thu Apr 15, 2010 12:28 pm

Hello Peter

a window in hide mode, not capture messages

1 suggestion:
limitation: show the screen before close, but is very fast
Code: Select all  Expand view

STATIC FUNCTION ExitApp
    IF oWnd2 <> NIL
        oWnd2:Show()
        oWnd2:End()
    ENDIF
RETURN .T.


2 suggestion:
limitation: is not a float window, only inside main window
Code: Select all  Expand view

    DEFINE WINDOW oWnd2 FROM 2, 2 TO 20, 70 ;
        TITLE "Test2" ;
        MENU BuildMenu2() OF oWnd
 
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Window Closing Question/Problem

Postby Daniel Garcia-Gil » Thu Apr 15, 2010 1:13 pm

Peter

the suggestion 1 work some times

suggestion 3
Code: Select all  Expand view

#include "FiveWin.ch"
#include "InKey.ch"

STATIC oWnd, oWnd2, oActiveX

FUNCTION main
    PUBLIC cEvents := ""    
   DEFINE WINDOW oWnd FROM 2, 2 TO 20, 70 ;
      TITLE "Test" ;
      MENU BuildMenu()

  ACTIVATE WINDOW oWnd MAXIMIZED ;
  ON INIT OpenNewWind() ;
  VALID ExitApp()
RETURN nil

STATIC FUNCTION BuildMenu
    Local oMenu
    MENU oMenu 2007
        MENUITEM "&Exit" ACTION oWnd:End()
        //MENUITEM "&Open" ACTION OpenNewWind()
        MENUITEM "&Show" ACTION ( oWnd2:Show(), BringWindowToTop( oWnd2:hWnd ) )
        MENUITEM "&Hide" ACTION ( oWnd2:Hide() )
    ENDMENU
RETURN oMenu

STATIC FUNCTION ExitApp
    IF oWnd2 <> NIL
        oWnd2:End()
    ENDIF
RETURN .T.

STATIC FUNCTION OpenNewWind
    LOCAL cUrl    := "http://217.35.79.149:9090/emapping/emapping.aspx?key=PNL001&group=0EDF4DF3-150D-BC82-5894-433C2898DF0B&width=960&height=559&language=ENGLISH&address=OX51LG&zoom=14&config=account:N;groups:N;routes:N;fences:N;markers:N;devices:N;toolbar:N;showaddress:N;showcoords:Y;"

    DEFINE WINDOW oWnd2 FROM 2, 2 TO 20, 70 ;
        TITLE "Test2" ;
        MENU BuildMenu2() OF oWnd
       
        oActiveX = TActiveX():New( oWnd2, "Shell.Explorer" )

        oWnd2:oClient = oActiveX // To fill the entire window surface

        oActiveX&#058;Do( "Navigate", cUrl )
        oWnd2:bGotFocus = {|| BringWindowToTop( oWnd2:hWnd ) }
   
    ACTIVATE WINDOW oWnd2 ON INIT ( SetParent( oWnd2:hWnd, GetDesktopWindow() ), oWnd2:Hide() )
RETURN NIL

STATIC FUNCTION BuildMenu2
    Local oMenu
    MENU oMenu 2007
        MENUITEM "&Exit" ACTION oWnd2:End()
    ENDMENU
RETURN oMenu

function EventInfo( event, aParams, pParams, oActiveX )
   local cMsg := "Event: " + cValToChar( event ) + CRLF
   local n
   
   cMsg += "Params: " + CRLF
   
   for n = 1 to Len( aParams )
      cMsg += cValToChar( aParams[ n ] ) + CRLF
   next
   
   if event == "BeforeNavigate2"
      // MsgInfo( aParams[ 2 ] )
      // SetEventParam( pParams, 7, .t. ) // Comment this to allow navigation
   endif  

return cMsg + CRLF

function OleInvoke( hObj, cMethod, uParam )

#ifndef __XHARBOUR__
   return __ObjSendMsg( TOleAuto():New( hObj ), cMethod, uParam )
#else  
   local aParams := hb_aParams()

   aParams[ 1 ] = TOleAuto():New( hObj )

   return hb_execFromArray( @__ObjSendMsg(), aParams )  
#endif

function OleSetProperty( hObj, cPropName, uValue )

return __ObjSendMsg( TOleAuto():New( hObj ), "_" + cPropName, uValue )

function OleGetProperty( hObj, cPropName )

return __ObjSendMsg( TOleAuto():New( hObj ), cPropName )
 
 
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Window Closing Question/Problem

Postby PeterHarmes » Thu Apr 15, 2010 1:17 pm

Hi Daniel,

Suggestion 1 didnt work i'm afraid. I tried suggestion 2 but didnt really like the results.

I have found a solution!!

On the INIT of the first window call a function that starts a timer with an interval of 200 - the function it calls then disables the timer then calls the second window and hides it. System works fine. The system must be getting confused by starting another window during the init of the first window.

The above solution is a bit messy, but hey it works!! If anyone has an alternative solution please let me know.

Thanks for your help Richard & Daniel

Regards,

Pete
PeterHarmes
 
Posts: 363
Joined: Wed Feb 15, 2006 2:06 pm
Location: Oxford, England

Re: Window Closing Question/Problem

Postby Daniel Garcia-Gil » Thu Apr 15, 2010 1:55 pm

Peter..


did you test my suggestion 3???
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Window Closing Question/Problem

Postby PeterHarmes » Thu Apr 15, 2010 2:07 pm

Sorry Daniel, didnt see suggestion 3 - but just tried it and it worked!!

Think i will use your example as using a timer is a bit messy - thanks for your help

Pete
PeterHarmes
 
Posts: 363
Joined: Wed Feb 15, 2006 2:06 pm
Location: Oxford, England

Re: Window Closing Question/Problem

Postby mmercado » Thu Apr 15, 2010 2:13 pm

Hello Peter:
PeterHarmes wrote:The above solution is a bit messy, but hey it works!! If anyone has an alternative solution please let me know.

Why don't you try to do it under a MDI environment ? (map on a MDICHILD window)

So Windows takes care of all closings.

Here a similar sample:
Code: Select all  Expand view
#include "FiveWin.ch"
#include "InKey.ch"

Static oWnd, oWnd2, oActX

Function Main()

   Define Window oWnd From 2, 2 To 20, 70 MDI;
          Title "Test" ;
          Menu BuildMenu()

   Activate Window oWnd Maximized ;
            On Init OpenNewWind()

Return nil

Static Function BuildMenu

   Local oMenu

   Menu oMenu 2007
      Menuitem "&Exit" Action oWnd:End()
      Menuitem "&Show" ACTION oWnd2:Show()
      Menuitem "&Hide" ACTION oWnd2:Hide()
   EndMenu

Return oMenu

Static Function OpenNewWind()

   Local cUrl := "http://217.35.79.149:9090/emapping/emapping.aspx?key=PNL001&group=0EDF4DF3-150D-BC82-5894-433C2898DF0B&width=960&height=559&language=ENGLISH&address=OX51LG&zoom=14&config=account:N;groups:N;routes:N;fences:N;markers:N;devices:N;toolbar:N;showaddress:N;showcoords:Y;"

   Define Window oWnd2 From 2, 2 To 20, 70 Of oWnd MDICHILD;
          Title "Test2"

   oActX = TActiveX():New( oWnd2, "Shell.Explorer" )
   oWnd2:oClient := oActX // To fill the entire window surface
   oActX:Do( "Navigate", cUrl )

   Activate Window oWnd2 On Init oWnd2:Hide()

Return Nil
Best Regards.
manuelmercado at prodigy dot net dot mx
User avatar
mmercado
 
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Re: Window Closing Question/Problem

Postby PeterHarmes » Thu Apr 15, 2010 2:18 pm

Manuel,

I tried using an MDI window, but for some reason the web site was inactive (couldnt click on any links or make the page scroll up & down)

Regards,

Pete

Edit: Looking at your code, i think i was doing something wrong :oops:
PeterHarmes
 
Posts: 363
Joined: Wed Feb 15, 2006 2:06 pm
Location: Oxford, England


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Marc Venken and 100 guests