FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour FindWnd()-Mdi-Dialog NoWait (SOLUCIONADO)
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
FindWnd()-Mdi-Dialog NoWait (SOLUCIONADO)
Posted: Sat Dec 08, 2012 01:14 AM
Hola amigos, ¿pueden ayudar con esto?

En un ambiente MDI, desde WinMain abro un Dialog NOWAIT incrustado en una oChild MDICHILD con 2 xBrowses. Luego abro otro Dialog NOWAIT incrustado en otra MDICHILD. Este último quiero que el usuario no pueda abrirlo mas de 1 vez. Para esto utilizo las siguientes funciones que encontré aquí en el foro:
Code (fw): Select all Collapse
Function ShowApplication(cWndTitle)
   local hWnd := FindWnd( cWndTitle )   //cFileNoExt( HB_ARGV( 0 ) ) ) // Use the window title here!
   
   if hWnd != nil
      if IsIconic( hWnd ) 
         ShowWindow( hWnd, SW_RESTORE ) 
      endif
      SetForeGroundWindow( hWnd )
   endif   
   
Return if(hWnd != nil, .t.,.f.)  //nil   
//----------------------------
Function FindWnd( cTitle ) 
   local hWnd := GetWindow( GetDesktopWindow(), GW_CHILD ) 

   while hWnd != 0 
      if Upper( cTitle ) $ Upper( GetWindowText( hWnd ) ) 
         return hWnd
      endif 

      hWnd = GetWindow( hWnd, GW_HWNDNEXT ) 
   enddo 

return nil


Aparentemente trabajan bien, pero no funcionan en algunos casos:
1 - Si abro por primera vez DIALOG NOWAIT incrustado en la oChild MAXIMIZADA y luego trato de abrir la misma ventana, las funciones detectan correctamente, pero si la minimizo, cambio su tamaño a NORMAL o abro otro DIALOG NOWAIT diferente superpuesto al anterior descrito, las funciones no detectan que tengo esa ventana abierta y permite abrirla nuevamente.
¿Cómo se puede solucionar esto?
Agradezco de antemano.

Saludos.
Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: FindWnd()-Mdi-Dialog NoWait
Posted: Sat Dec 08, 2012 02:51 AM
Hola, con este ejemplo autocontenido lo pueden observar. Si abren las child normalmente, no son detectadas, pero si maximizan alguna si.
Code (fw): Select all Collapse
#include "FiveWin.ch"

#define GW_CHILD      5 
#define GW_HWNDNEXT   2
#define SW_RESTORE    9

static oWnd
//--------------------------------------------------------------------
Function Main()

   SET CENTURY ON

   DEFINE WINDOW oWnd MDI  TITLE "PRUEBA" ;
          MENU BuildMenu()   

   ACTIVATE WINDOW oWnd MAXIMIZED ;
       VALID  MsgNoYes("¿Desea salir?","Salir")

return nil

//----------------------------------------------------------------------------//
Function BuildMenu()
local oMenu

   MENU oMenu 2007
      MENUITEM  "&Abiertas" ACTION Abiertas()
      MENUITEM "&Salir..."  ACTION oWnd:End()
   ENDMENU

return oMenu

//-------------------------
Function Abiertas()
LOCAL oChild, cTitle :="PROBANDO EVITAR ABRIR 2 VECES"
   
if ShowApplication(cTitle)
   MsgStop("Que tratas de hacer?")
   return nil

else

  DEFINE WINDOW oChild MDICHILD OF oWnd ;
       TITLE cTitle  ;
       COLOR 0, GetSysColor( )
      
  ACTIVATE WINDOW oChild;
      VALID ( .T. )
endif

RETURN NIL

//-----------------------------------------
Function ShowApplication(cWndTitle)
   local hWnd := FindWnd( cWndTitle )   //cFileNoExt( HB_ARGV( 0 ) ) ) // Use the window title here!
   
   if hWnd != nil
      if IsIconic( hWnd ) 
         ShowWindow( hWnd, SW_RESTORE ) 
      endif
         SetForeGroundWindow( hWnd )
   endif   
   
Return if(hWnd != nil, .t.,.f.)  //nil   
//----------------------------
Function FindWnd( cTitle ) 
   local hWnd := GetWindow( GetDesktopWindow(), GW_CHILD ) 

   while hWnd != 0 
      if Upper( cTitle ) $ Upper( GetWindowText( hWnd ) ) 
         return hWnd
      endif 

      hWnd = GetWindow( hWnd, GW_HWNDNEXT ) 
   enddo 

return nil

Saludos.
Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: FindWnd()-Mdi-Dialog NoWait (SOLUCIONADO)
Posted: Sat Dec 08, 2012 06:15 AM

Hola, aquí encontré la solución: (sólo unas dos "horitas" en el foro)

viewtopic.php?f=6t=19505hilit=mdistart=15#p102852

Gracias anserkk, Daniel y Armando Picón.

Saludos.

&&&

Francisco J. Alegría P.

Chinandega, Nicaragua.



Fwxh-MySql-TMySql

Continue the discussion