Armando Picon wrote:Anserkk
Only it has a disadvantage. If the user has minimized the MDICHILD, the function always will come back .T. If the user is careful he will look on his screen for the minimized window and will activate her. But if he is not careful, the first thing that will do is to protest with regard to the quality of the application.
Armando
You can resolve the abve said problem by adding a line of code
- Code: Select all Expand view
- wndMain():oWndClient:aWnd[i]:Restore()
- Code: Select all Expand view
- *------------------------------------------------------*
Function wndSetFocus(cTitle)
*------------------------------------------------------*
/* Here is a function to prevent opening more than one copy of a MDI child window.
It also brings the window to the top and set the focus to it.
Title/Caption of the window is passed as a parameter
*/
local i:=0,lSuccess:=.f.
cTitle:=upper(cTitle)
For i=1 to len(wndMain():oWndClient:aWnd)
if upper( wndMain():oWndClient:aWnd[i]:cCaption )=cTitle
wndMain():oWndClient:aWnd[i]:setFocus()
wndMain():oWndClient:aWnd[i]:Restore()
lSuccess:=.t.
endif
Next
Return lSuccess
Here is the video demonstrating the same. An MDI child window is minmized and then the user tries to calll a new instance of the same MDI child window. See how the above code finds/locates the MDI child window, set focus to that window and then restore that window back so that multiple instances of the same MDI chaild window is not opened.
Video : http://screencast.com/t/NTE5NDNlNm
Regards
Anser