FindWindow() function

FindWindow() function

Postby Rimantas » Fri Jan 20, 2006 8:08 am

Hi ! Can be done , that FindWindow will find window with a part of title ? I'm using in titles users names :

Code: Select all  Expand view
   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
Rimantas
 
Posts: 437
Joined: Fri Oct 07, 2005 12:56 pm
Location: Utena , Lithuania

Re: FindWindow() function

Postby Enrico Maria Giordano » Fri Jan 20, 2006 8:28 am

This is a working sample:

Code: Select all  Expand view
#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
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: FindWindow() function

Postby Rimantas » Fri Jan 20, 2006 9:59 am

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 77 guests