Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Search for a Windows Application with only part of the name
Message
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
Search for a Windows Application with only part of the name
Divers
Thread ID:
00876975
Message ID:
00876975
Vues:
72
I have spent half a day doing this and thought that others might be interested in the solution.


Initially I did the following to find an application with a static name in Microsoft Windows :

DECLARE INTEGER FindWindow IN user32 ;
STRING lpClassName, STRING lpWindowName
LOCAL lhhwnd
lhhwnd = FindWindow(.NULL., "ABCD Tax")
IF lhhwnd > 0
=Messagebox("ABCD Tax is Active")
RETURN
ENDIF


I was then asked to search for a Window with a variable name.
I started by looking at the EnumWindows API call but VFP cant handle the callback functionality, so I ended up with the following.

DECLARE INTEGER GetDesktopWindow IN Win32API

DECLARE INTEGER GetWindow IN WIN32API ;
INTEGER hwnd, INTEGER wCmd

DECLARE INTEGER GetWindowText IN WIN32API ;
INTEGER hwnd, STRING @lptstr, INTEGER cbmax


LOCAL lcTaxTitle, lcWindowTitle, lcWindowTitleLen

lcTaxTitle = "ABCD TAX"

lcWindowTitle = SPACE(50)
lcWindowTitleLen = LEN(lcWindowTitle)

#DEFINE GW_CHILD 5
#DEFINE GW_HWNDNEXT 2

* Return a handle to the Windows desktop
loDesktopHWnd = GetDesktopWindow()

* Get the First Child
lnHWnd = GetWindow(loDesktopHWnd, GW_CHILD)

* Cycle through the children
DO WHILE lnHWnd <> 0
lnHWnd = GetWindow(lnHWnd, GW_HWNDNEXT)

* Returns text from the window title bar
lcReturn = GetWindowText(lnHWND, @lcWindowTitle, lcWindowTitleLen)

IF UPPER(SUBSTR(lcWindowTitle,1,8)) == lcTaxTitle
* ? lcWindowTitle
RETURN .T.
ENDIF

ENDDO

RETURN .F.


I hope this saves you some time and effort.

(Thanks to Advisor Magazine and UT Messages for parts of the solution)
Wayne Williams
Developer VFP
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform