如果获取指定窗口的焦点控件?
在PB中,使用getfocus()函数可以获得应用中当前获得焦点的控件对象。
但是,在已知窗口的情况下,如何获取该窗口当前获得焦点的控件对象呢?
下面是我使用的方法
//**定义函数:SetActiveWindow(long handle) Library "user32.dll"//**假设已知窗口为 window awgraphicobject lgo_objectboolean lb_enabledlb_enabled = aw.enabled //记录窗口的enabled属性,用来处理response类型的窗口if not lb_enabled then aw.enabled = trueSetActiveWindow(handle(aw)) //焦点转移到aw上lgo_object = getfocus() //取得aw的焦点控件if not lb_enabled then aw.enabled = falseSetActiveWindow(handle(当前窗口))if isvalid(lgo_object) then messagebox('', lgo_object.classname())
n_cst_menupfc_messagerouter(as_message)pfc_w_master.event pfc_messageroutergraphicobject lgo_focus// Check argumentIf IsNull (as_message) or Len (Trim (as_message)) = 0 Then Return -1End If// Try sending the message to this window, if successful exit event.If This.TriggerEvent (as_message) = 1 Then Return 1// Try sending the message to the current control, if successful exit event.lgo_focus = GetFocus()If IsValid (lgo_focus) Then If lgo_focus.TriggerEvent (as_message) = 1 Then Return 1End If// Try sending the message to the last active datawindow, if successful exit event.If IsValid (idw_active) Then If idw_active.TriggerEvent (as_message) = 1 Then Return 1End If// No objects recognized the messageReturn 0