FindWindow() function

Post Reply
User avatar
Rimantas
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

FindWindow() function

Post 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 .
Rimantas U.
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: FindWindow() function

Post 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
User avatar
Rimantas
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: FindWindow() function

Post 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 !
Rimantas U.
Post Reply