First off, GetTopWindow only returns child window handles, not parents. This might be able to be used in an MDI application (not sure, haven't tested).
Second, as Joe suggested, use the GetForegroundWindow function. As long as the function is called in or after the Activet of the form, then the foreground window and the form window handle should be the same.
HTH.
>Public Declare Function GetTopWindow Lib "user32" (ByVal hWnd As Long) As Long
>
>For Click Event of form write this code:
>Private Sub Form_Click()
> Dim n As Long
> n = GetTopWindow(0) 'or n=GetToWindow(GetDesktopWindow())
> if n<>me.hwnd then
> msgbox "!="
> else
> msgbox "="
> end if
>End Sub
>
>while when i click on form n<>me.hwnd?
Larry Miller
MCSD
LWMiller3@verizon.netAccumulate learning by study, understand what you learn by questioning. -- Mingjiao