Page 1 of 1

FindWindow() function

Posted: Fri Jan 20, 2006 8:08 am
by Rimantas
Hi ! Can be done , that FindWindow will find window with a part of title ? I'm using in titles users names :

Code: Select all

   cMainTitle := "MyApp ." 
   ...
    DEFINE WINDOW oWnd_pagr MDI FROM 10, 10 TO nVerRes / 3.5, ;
    nHorRes / 1.5 TITLE cMainTitle + alltrim( cUserName ) + " . " ;
    MENU BuildMenu() PIXEL
I tried and without users name findwindow( 0, cMainTitle ) works fine . But adding user's name in caption the function can't detect . I think , that Window caption in searchs can be compare with the lenght of search string , something left( cWindCaption, len( alltrim( cSearch ) ) ) == alltrim( cSearch ) . How to do that ?

With best regards ! Rimantas .

Re: FindWindow() function

Posted: Fri Jan 20, 2006 8:28 am
by Enrico Maria Giordano
This is a working sample:

Code: Select all

#include "Fivewin.ch"


#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 SW_NORMAL 1


FUNCTION MAIN()

    LOCAL hWnd := FINDWND( "Excel" )

    IF !EMPTY( hWnd )
        ? GETWINDOWTEXT( hWnd )
        SHOWWINDOW( hWnd, SW_NORMAL )
    ELSE
        ? "Window not found"
    ENDIF

    RETURN 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
EMG

Re: FindWindow() function

Posted: Fri Jan 20, 2006 9:59 am
by Rimantas
EnricoMaria wrote:
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
Thanks ! Works fine ! :D

With best regards !