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