* Example use:
oWrd = createobject('word.application')
oWrd.height = _screen.height/2
oWrd.width = _screen.width/2
oWrd.top = _screen.height/8
oWrd.left = _screen.width/8
res = takewindow(oWrd.caption)
oWrd.visible = .t.
* Or:
SET HELP TO MyHelp.chm
HELP My Help Topic
res=TakeWindow( "My Help File's Window Title" )
* Author.....: William GC Steinford
* Date.......: Nov 6, 2002
* Abstract...: Place Any window inside any VFP window (main VFP window or DEFINE'd Window)
PROCEDURE TakeWindow
LPARAMETERS pcWindowTitle, pcParentWindow
LOCAL lnWHND, lnVFP, lnRes, lnCNT, lnWinCnt
DECLARE INTEGER FindWindow in win32api as apiFindWindow ;
INTEGER nClass, STRING cName
DECLARE INTEGER FindWindowEx in win32api as apiFindWindowEx ;
INTEGER nParent, INTEGER nChildAfter, ;
INTEGER nClass, STRING cName
* First get the VFP window handle
lnVFP = apiFindWindow( 0, _Screen.Caption )
if lnVFP<=0
RETURN -1
ENDIF
lnWinCnt = lnVFP
lnWHND = apiFindWindow( 0, pcWindowTitle )
* Not outside of VFP... if we have a parent window, check inside VFP
if lnWHND<=0 and vartype(pcParentWindow)='C' and not empty(pcParentWindow)
lnWHND=apiFindWindowEx( lnVFP, 0, 0, pcWindowTitle ) && Look in VFP window
if lnWHND=0 && Not in Main VFP window... This is the case if this window
&& was created by VFP
&& Container windows in VFP have no title
lnCNT = apiFindWindowEx( lnVFP, 0, 0, ' ) && Find in container window
do while lnWHND=0 and lnCNT<>0
lnWHND = apiFindWindowEx( lnCNT, 0, 0, pcWindowTitle ) && Look in container
lnCNT = apiFindWindowEx( lnVFP, lnCNT, 0, ' ) && Find next container window
enddo
endif
endif
if lnWHND<0
RETURN -1
endif
* Find the Parent Window
if vartype(pcParentWindow)='C' and not empty(pcParentWindow)
lnWinCNT=apiFindWindowEx( lnVFP, 0, 0, pcParentWindow ) && Look in container
if lnWinCnt=0 && Not in Main VFP window... This is the case if this window
&& was created by VFP
&& Container windows in VFP have no title
lnCNT = apiFindWindowEx( lnVFP, 0, 0, ' ) && Find in container window
do while lnWinCnt=0 and lnCNT<>0
lnWinCnt = apiFindWindowEx( lnCNT, 0, 0, pcParentWindow ) && Look in container
lnCNT = apiFindWindowEx( lnVFP, lnCNT, 0, ' ) && Find next container window
enddo
if lnWinCNT<=0
RETURN -1 && Couldnt find new parent window
endif
endif
else
if vartype(pcParentWindow)='N'
if pcParentWindow>=0
* Use provide WHND
lcWinCnt = pcParentWindow
else
* <0, indicates make child of main VFP window
* do Nothing (leave lcWinCnt=0)
endif
else
DEFINE WINDOW TakeWindowXoXoX TITLE "TakeWindowXoXoX" AT 0,0 Size 1,1
SHOW WINDOW TakeWindowXoXoX
* Find the empty-caption window inside VFP that contains "TakeWindowXoXoX"
lnWinCNT =0
lnCNT = apiFindWindowEx( lnVFP, 0, 0, ' ) && Find first container window
DO WHILE lnCnt<>0 and lnWinCnt=0
lnWinCNT = apiFindWindowEx( lnCNT, 0, 0, 'TakeWindowXoXoX' ) && Find Marker Window
if lnWinCnt=0
lnCNT = apiFindWindowEx( lnVFP, lnCNT, 0, ' ) && Find next container window
endif
ENDDO
if lnWinCnt<>0
lnWinCnt = lnCnt
endif
RELEASE WINDOW TakeWindowXoXoX
endif
endif
DECLARE INTEGER SetParent in Win32API as apiSetParent ;
INTEGER hWndChild, INTEGER hWndNewParent
if lnWinCnt<>0 && Use proper container window
lnRes = apiSetParent( lnWHND, lnWinCnt )
else
lnRes = apiSetParent( lnWHND, lnVFP )
endif
RETURN lnRes