lw_frame = lw_parent
do while IsValid (lw_frame)
if lw_frame.windowtype = mdi! or lw_frame.windowtype = mdihelp! then
lb_frame = true
exit
else
lw_frame = lw_frame.ParentWindow()
end if
loop
if lb_frame then
// If MDI frame window is available, use it as the reference point for the popup menu for sheets (windows opened with OpenSheet function) or child windows
if lw_parent.windowtype = child! then
lw_parent = lw_frame
else
lw_sheet = lw_frame.GetFirstSheet()
if IsValid (lw_sheet) then
do
// Use frame reference for popup menu if the parentwindow is a sheet
if lw_sheet = lw_parent then
lw_parent = lw_frame
exit
end if
lw_sheet = lw_frame.GetNextSheet (lw_sheet)
loop until IsNull(lw_sheet) Or not IsValid (lw_sheet)
end if
end if
else
// SDI application. All windows except for child windows will use the parent window of the control as the reference point for the popmenu
if lw_parent.windowtype = child! then
lw_childparent = lw_parent.ParentWindow()
if IsValid (lw_childparent) then lw_parent = lw_childparent
end if
end if