need to close others windows when my application is running

need to close others windows when my application is running

Postby areang » Thu Mar 01, 2007 10:41 pm

Hi All !

My application is running, but users playing the games. :twisted:

How to close others active windows when my application is running.

Thank's for help

Best Regards
Areang
areang
 
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm

Re: need to close others windows when my application is runn

Postby Enrico Maria Giordano » Fri Mar 02, 2007 7:57 am

Code: Select all  Expand view
#define GW_HWNDFIRST   0
#define GW_HWNDLAST   1
#define GW_HWNDNEXT   2
#define GW_HWNDPREV   3
#define GW_OWNER   4
#define GW_CHILD   5

#define WM_CLOSE 16


STATIC FUNCTION CLOSEAPPS( hMWnd )

    LOCAL ahWnd := {}

    LOCAL hWnd := GETWINDOW( hMWnd, GW_HWNDFIRST )

    LOCAL i

    SYSREFRESH()

    WHILE hWnd != 0
        IF GETWINDOW( hWnd, GW_OWNER ) = 0 .AND.;
           ISWINDOWVISIBLE( hWnd ) .AND.;
           hWnd != hMWnd .AND.;
           !EMPTY( GETWINDOWTEXT( hWnd ) ) .AND.;
           !( GETWINDOWTEXT( hWnd ) == "Program Manager" )

            AADD( ahWnd, hWnd )
        ENDIF

        hWnd = GETWINDOW( hWnd, GW_HWNDNEXT )
    ENDDO

    FOR i = 1 TO LEN( ahWnd )
        POSTMESSAGE( ahWnd[ i ], WM_CLOSE, 0, 0 )
    NEXT

    RETURN NIL


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Rochinha » Fri Mar 02, 2007 12:46 pm

Areang,

Here is my LanHouse Spy. To use it.

1 - Create a C:\Spyfolder on server and install the LanHouse Spy.
2 - Share the C:\SpyFolder to other machines.
3 - Exec the LanHouse Spy on each machine.

To lock one machine, open ACESSOS.DBF on server, locate user and change status for STATUS field, true or false.

Implement the Enrico's code to improve.

Full SERVICE.PRG code
Code: Select all  Expand view
#include "FiveWin.ch"
#include "dll.ch"

#DEFINE WM_SYSCOMMAND  274     // &H112
#DEFINE SC_TASKLIST   61744    //&HF130
#DEFINE SC_SCREENSAVE 61760   // &HF140
#DEFINE SW_HIDE           0   // &H0
#DEFINE SW_SHOWNA         8   // &H8
#DEFINE SW_SHOW           5   // &H5
#DEFINE SW_SHOWNORMAL     1
#DEFINE SC_MONITORPOWER  61808   //&HF170   Gracias a Ramon Ramirez por la info
#DEFINE SM_CLEANBOOT     67

#DEFINE GWL_EXSTYLE   (-20)
#DEFINE WS_EX_LAYERED 0x00080000
#DEFINE LWA_ALPHA     0x00000002
#DEFINE LWA_COLORKEY  0x00000001

#DEFINE GW_CHILD      5
#DEFINE GW_HWNDNEXT   2
#DEFINE RT_BITMAP     2
#DEFINE MB_ICONEXCLAMATION 48
#DEFINE CBM_INIT 4 && should move to prg header
#DEFINE DIB_RGB_COLORS 0 && should move to prg header

static hLib, hDib

Function Main(_tempo_)
   Local oB, oApp, oIcon, oTimer, cImgFile := "service.bmp", oClp
   public cUsuario := space(15), cImage, cIMGAlerta, oEsconde
   lStatus := .f.
   Default _tempo_ := "05"
   cPath   := cFilePath( GetModuleFileName( GetInstance() ) )
   nTempo     := VerifyINI( "SERVICE", "TEMPO" , "360", cPath+"service.ini" )
   cImage     := VerifyINI( "SERVICE", "IMAGEM", "NAO", cPath+"service.ini" )
   cIMGAlerta := VerifyINI( "SERVICE", "ALERTA", "SIM", cPath+"service.ini" )
   //hLib := LoadLibrary( "freeimage.dll" )
   //if hLib <= 32
   //   MsgStop( "Freeimage.dll nao foi carregada" )
   //   return 0
   //endif
   if !file("service.dbf")
      DbCreate("service.dbf",{ { "Usuario"  , "C", 15, 0},;
                               { "Data"     , "D",  8, 0},;
                               { "Hora"     , "C",  8, 0},;
                               { "Imagem"   , "C", 30, 0} } )
   endif
   if !file("acessos.dbf")
      DbCreate("acessos.dbf",{ { "Usuario"  , "C", 15, 0},; // Pode ser IP
                               { "Serial"   , "C", 10, 0},;
                               { "Data"     , "D",  8, 0},;
                               { "HoraINI"  , "C",  8, 0},;
                               { "HoraFIM"  , "C",  8, 0},;
                               { "Status"   , "L",  1, 0},;
                               { "Imagem"   , "C", 30, 0} } )
   endif
   USE service NEW SHARED
   USE acessos NEW SHARED
   HDSerial := HDSerial()
   dbGoTop()
   locate for alltrim(acessos->serial) = alltrim(HDSerial)
   if .not. found()
      MsgGet( "Configuracao", "Nick do Usuario:", @cUsuario )
      dbNetAppend( 0 )             // Adiciona usuario a lista
      acessos->Data    := Date()   // coloca a data do dia do acesso
      acessos->Usuario := cUsuario // coloca o nome do usuario
      acessos->Serial  := HDSerial // coloca o nome do usuario
      acessos->Status  := .F.      // e autentica o usuario mas nao libera
      dbNetReglock()
   else
      lStatus := acessos->Status   // verifica se o usuario esta liberado
   endif
   dbSelectArea( "acessos" )
   set filter to alltrim(acessos->serial) = alltrim(HDSerial)
   dbGoTop()
   //---------------
   ServiceProcess(1)
   //---------------
   DEFINE BRUSH oB COLOR CLR_HGRAY
   DEFINE ICON oIcon FILE "LOGO.ICO"
   DEFINE CLIPBOARD oClp OF oApp
   //ShowWindow( FindWindow(nil,'Program Manager'), SW_SHOW)
   //ShowWindow(FindWindow( 'Shell_TrayWnd',nil), SW_SHOWNA)
   //if ! lStatus
   //   cBmp := "service.bmp"
   //   DEFINE BRUSH  oBrush STYLE NULL
   //   DEFINE BITMAP oBmp FILENAME cBmp
   //          hDC    := oBmp:hDC
   //   DEFINE WINDOW oEsconde FROM 0,0 TO 600,800 PIXEL BRUSH oBrush STYLE WS_POPUP
   //   ACTIVATE WINDOW oEsconde ON PAINT PalBmpDraw( hDC, 0, 0, oBmp:hBitmap )
   //endif
   DEFINE WINDOW oApp FROM 0,0 to 1,1 pixel TITLE "Service" BRUSH oB STYLE WS_POPUP ICON "racer.ico"
          DEFINE TIMER oTimer OF oApp INTERVAL (val(_tempo_)*1000) ACTION GravaProcess( cImgFile, oApp )
          ACTIVATE TIMER oTimer
   ACTIVATE WINDOW oApp ON INIT (Shell_NotifyIcon( 0, "racer.ico" ), oApp:Hide()) //VALID (oEsconde:End(), .t.)
   ShowWindow( FindWindow(nil,'Program Manager'), SW_SHOW)
   ShowWindow(FindWindow( 'Shell_TrayWnd',nil), SW_SHOWNA)
   Return NIL                   

//-------------------------------------
Function GravaProcess( cImgFile, oWnd )
//-------------------------------------
   if cImage = "SIM"
      //hWnd := FindWindow(nil,'Program Manager')
      //hBmp := WndBitmap( hWnd )
      //fErase(cImgFile)
      //hDib := DibFromBitmap( hBmp )
      //DibWrite( cImgFile, hDib )
      //WaitRun( "nconvert -out jpeg -q 100 -D "+cImgFile, 0 )
      dbSelectArea( "service" )
      dbAppend()
      service->usuario := NetName()
      service->data    := Date()
      service->hora    := Time()
      service->imagem  := StrTran( cImgFile, ".bmp", ".jpg" )
      dbNetReglock()
   endif
   //USE service SHARED
   //dbCloseAll()
   if cIMGAlerta = "SIM"
      //Ballon("C A P T U R E I "+acessos->USUARIO,2)
      Ballon("Capturei mais uma imagem",2)
   endif
   dbSelectArea( "acessos" )
   dbGoTop()
   lStatus := acessos->Status
   if lStatus // Se usuario esta liberado para uso da maquina ela sera ativada
      //Ballon("M O S T R A N D O "+acessos->USUARIO,2)
      WinExec( "servshow", 7 )
      ShowWindow( FindWindow(nil,'Program Manager'), SW_SHOW)
      ShowWindow(FindWindow( 'Shell_TrayWnd',nil), SW_SHOWNA)
   else
      //Ballon("E S C O N D E N D O "+acessos->USUARIO,2)
      WinExec( "servhide", 7 )
      ShowWindow(FindWindow( 'Shell_TrayWnd',nil), SW_HIDE)
      ShowWindow( FindWindow(nil,'Program Manager'), SW_HIDE)
   endif
   //lOk := fiSave( 0, hDib, cImgFile )
   //if !lOk
   //   MsgInfo( "Can't not save file" )
   //endif
   //MsgRun('gravei')
   Return NIL

//-------------------------------------
Function ServiceProcess( mode )
//-------------------------------------
   Local nProcessId := 0
   Default mode := 0
   nProcessId := GCP( )
   If Abs( nProcessId ) > 0
      RSProcess( nProcessId, mode )
   Endif
   RETURN

//-------------------------------------
Function Ballon(cBallonMsg,nBallonTime)
//-------------------------------------
   local oDlgBallon, oBrush
   default cBallonMsg := "Nova mensagem chegando..."
   DEFINE WINDOW oDlgBallon ;
          FROM GetSysMetrics(1),GetSysMetrics(0)-300 TO 200,200 PIXEL ;
          COLOR nRGB(255,255,255),nRGB(255,255,230) ;
          NO CAPTION BORDER NONE
          @ 5, 5 GET cBallonMsg MEMO OF oDlgBallon SIZE 195,195 PIXEL COLOR nRGB(000,000,000),nRGB(255,255,230) NOBORDER NO MODIFY NO VSCROLL
   //ACTIVATE WINDOW oDlgBallon ON INIT ( LayeredWindow( oDlgBallon, 070 ), MoveDLG(oDlgBallon,nBallonTime) )
   ACTIVATE WINDOW oDlgBallon ON INIT MoveDLG(oDlgBallon,nBallonTime)
   return nil

//-------------------------------------
Function LayeredWindow( oWnd, nLay )
//-------------------------------------
   //SetWindowLong( oWnd:hWnd, GWL_EXSTYLE, GetWindowLong( oWnd:hWnd, GWL_EXSTYLE ) | WS_EX_LAYERED )
   SetWindowLong( oWnd:hWnd, GWL_EXSTYLE, WS_BORDER )
   SetWindowLong( oWnd:hWnd, GWL_EXSTYLE, WS_EX_LAYERED )
   SetLayeredWindowAttributes( oWnd:hWnd, 0, ( 255 * nLay ) / 100, LWA_ALPHA )
   Return NIL

//-------------------------------------
Function dbNetCommit( tempo )
//-------------------------------------
   private sempre
   dbCommit()
   dbRUnlock()                                           // tenta incluir registro
   if RLock()                                            // se conseguiu
      mensagem(" Aguarde... Tentando liberar o registro")// se nao conseguiu
      sempre = (tempo = 0)                               // fica tentando inclusao
      for i = 1 to 10                                    // ate o tempo esgotar ou
         dbRUnlock()                                     // o usuario se encher...
         if .not. neterr()
            return .t.
         endif
         inkey(.5)                 && espera 1/2 segundo
         tempo = tempo - .5
      next
   endif
   return (.f.)                 && nao bloqueado

//-------------------------------------
Function dbNetAppend( tempo )
//-------------------------------------
   private sempre
   dbappend()                                            // tenta incluir registro
   if .not. neterr()                                     // se conseguiu
      return (.t.)                                       // retorna verdadeiro
   endif
   mensagem(" Aguarde... Tentando Acesso aos Arquivos ") // se nao conseguiu
   sempre = (tempo = 0)                                  // fica tentando inclusao
   do while (sempre .or. tempo > 0) .and. inkey()<>27    // ate o tempo esgotar ou
      dbappend()                                         // o usuario se encher...
      if .not. neterr()
         return .t.
      endif
      inkey(.5)                 && espera 1/2 segundo
      tempo = tempo - .5
   enddo
   return (.f.)                 && nao bloqueado

//-------------------------------------
Function dbNetReglock( tempo )
//-------------------------------------
   private sempre
   if rlock()
      return (.t.)              && bloqueado
   endif
   dbUnlockAll()
   mensagem(" Aguarde... Tentando Acesso aos Arquivos ")
   sempre = (tempo = 0)
   do while (sempre .or. tempo > 0) .and. inkey()<>27

      if rlock()
         return (.t.)           && bloqueado
      endif
      inkey(.5)                 && espera 1/2 segundo
      tempo = tempo - .5
   enddo
   return (.f.)                 && nao bloqueado

//-------------------------------------
Function MoveDLG(oDlgBallon,oDlgTime)
//-------------------------------------
   oDlgAltura := GetSysMetrics(1)
   for i = 1 to 20
       oDlgAltura := oDlgAltura - i
       oDlgBallon:Move( oDlgAltura, 100, 200, 200, .t. )
       SysWait(.02)
   next
   SysWait(oDlgTime)
   for i = 1 to 20
       oDlgAltura := oDlgAltura + i
       oDlgBallon:Move( oDlgAltura, 100, 200, 200, .t. )
       SysWait(.02)
   next
   oDlgBallon:end()
   return

//-------------------------------------
Function HDSERIAL()
//-------------------------------------
   return substr(alltrim(str(nSerialHD())),1,8)

//-------------------------------------
Function MENSAGEM( MENSAGEM, TEMPO )
//-------------------------------------
   if tempo <> NIL
      MsgStop( OemToAnsi(MENSAGEM) )
   else
      MsgRun( OemToAnsi(MENSAGEM) )
   endif

//-------------------------------------
Function Ping(DestinationAddress)
//-------------------------------------
   local IcmpHandle,Replicas
   local RequestData:="Testando ping",;
         RequestSize:=15,;
         RequestOptions:="",;
         ReplyBuffer:=space(278),;
         ReplySize:=278,;
         Timeout:=500 && Milisegundos de espera
   default DestinationAddress := "10.10.10.3"
   DestinationAddress:=left(alltrim(DestinationAddress)+space(15),15)
   //MsgGet("Ping...","Introduzca dirección IP",@DestinationAddress)
   IcmpHandle:=IcmpCreateFile()
   Replicas:=IcmpSendEcho(IcmpHandle,;
                          inet_addr(DestinationAddress),;
                          RequestData,;
                          RequestSize,0,;
                          ReplyBuffer,;
                          ReplySize,;
                          Timeout)
   IcmpCloseHandle(IcmpHandle)
   if Replicas > 0
      msginfo("A maquina "+alltrim(DestinationAddress)+" existe")
   else
      msginfo("A maquina "+alltrim(DestinationAddress)+" nao existe")
   endif
   return nil

//----------------------------------------------------
DLL32 FUNCTION RSProcess(npID  AS LONG ,nMode AS LONG ) AS LONG FROM "RegisterServiceProcess" LIB "kernel32.DLL"
DLL32 FUNCTION GCP() AS LONG FROM "GetCurrentProcessId" LIB "kernel32.dll"
DLL32 STATIC FUNCTION FISAVE( nFormat AS LONG, hDib AS LONG, cFileName AS LPSTR, nFlags AS LONG ) AS BOOL PASCAL FROM "_FreeImage_Save@16" LIB hLib
//----------------------------------------------------
DLL32 FUNCTION WSAGetLastError() AS _INT PASCAL FROM "WSAGetLastError" LIB "wsock32.dll"
DLL32 FUNCTION inet_addr(cIP AS STRING) AS LONG PASCAL FROM "inet_addr" LIB "wsock32.dll"
DLL32 FUNCTION IcmpCreateFile() AS LONG PASCAL FROM "IcmpCreateFile" LIB "icmp.dll"
DLL32 FUNCTION IcmpCloseHandle(IcmpHandle AS LONG) AS LONG PASCAL FROM "IcmpCloseHandle" LIB "icmp.dll"
DLL32 FUNCTION IcmpSendEcho(IcmpHandle AS LONG,;
                            DestinationAddress AS LONG,;
                            RequestData AS STRING,;
                            RequestSize AS LONG,;
                            RequestOptions AS LONG,;
                            ReplyBuffer AS LPSTR,;
                            ReplySize AS LONG,;
                            Timeout AS LONG) AS LONG PASCAL FROM "IcmpSendEcho" LIB "icmp.dll"

#include "errorsys.prg"

function VerifyINI( _section_, _entry_, _var_, _inifile_, _grava_ )
   oIni := TIni():New( _inifile_ )
   if _grava_ = .t.
      oIni:Set( _section_, _entry_, _var_ )
   endif
   return oIni:Get( _section_, _entry_, _var_, _var_ )


To save a photo of terminal change the lines below:

Code: Select all  Expand view
...
      //hWnd := FindWindow(nil,'Program Manager')
      //hBmp := WndBitmap( hWnd )
      //fErase(cImgFile)
      //hDib := DibFromBitmap( hBmp )
      //DibWrite( cImgFile, hDib )
      //WaitRun( "nconvert -out jpeg -q 100 -D "+cImgFile, 0 )
...
Rochinha
 
Posts: 310
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo

Postby Ehab Samir Aziz » Sat Mar 03, 2007 1:35 pm

Enrico where to put your static function in the main program ?
Ehab Samir Aziz
 
Posts: 334
Joined: Fri Oct 14, 2005 1:54 pm

Postby Enrico Maria Giordano » Sat Mar 03, 2007 6:38 pm

Just remove STATIC and put it anywhere.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby areang » Sun Mar 04, 2007 9:21 am

Hello Mr. Enrico !
I tested this but not work

Code: Select all  Expand view
GETWINDOWTEXT( hWnd ) == "Program Manager"


Is "Program Manager" the title of Windows from this :
DEFINE DIALOG oDlg FROM 1,1 TO 200,200 TITLE "Program Manager"

I have 2 windows set to title "Dialog1" and "Dialog2"
but not work to close with this source code :

Code: Select all  Expand view

WHILE hWnd != 0
        IF GETWINDOW( hWnd, GW_OWNER ) = 0 .AND.;
           ISWINDOWVISIBLE( hWnd ) .AND.;
           hWnd != hMWnd .AND.;
           !EMPTY( GETWINDOWTEXT( hWnd ) ) .AND.;
           !( GETWINDOWTEXT( hWnd ) == "Program Manager" )

            AADD( ahWnd, hWnd )
        ENDIF

        hWnd = GETWINDOW( hWnd, GW_HWNDNEXT )
    ENDDO

    FOR i = 1 TO LEN( ahWnd )
        POSTMESSAGE( ahWnd[ i ], WM_CLOSE, 0, 0 )
    NEXT



Regards
Areang
areang
 
Posts: 128
Joined: Mon Jul 31, 2006 3:23 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 60 guests