问题:新建GUI界面,添加DDL后,点击DDL弹出下来菜单后,点击菜单后,如果这时候菜单下有别的控件,神奇的事情发生了!被遮挡的控件可以响应点击!如下例子:
#NoEnv #SingleInstance force Gui, +AlwaysOnTop +E0x08000000 Gui Add, DDL, w55, option 1||option 2|option 3 Gui Add, Picture, w55 h30 +Border hwndPic gtest, Gui Show, AutoSize NoActivate, DDL Click Problem return test: MsgBox, 262144,, % A_ThisLabel, 1 return mouseIsOverControl(__controlID) { MouseGetPos,,,, __outputVarControl, 2 return (__outputVarControl = __controlID) } #If mouseIsOverControl(Pic) ~LButton::ToolTip, test return
解决方案:替换 MouseGetPos为controlgetpos
如下:
#NoEnv #Warn #SingleInstance force ; Windows 8.1 64 bit ; Autohotkey v1.1.27.07 32-bit Unicode Gui, +AlwaysOnTop +E0x08000000 Gui Add, DDL, w85 hwndCID, option 1||option 2|option 3 listHwnd := GUIDropDownList_listGetHwnd(CID) ; retrieve the list HWND and and store it in 'listHwnd' Gui Add, Picture, w65 h30 +Border hwndPic gtest, Gui Show, AutoSize NoActivate, DDL Click Problem return test: MsgBox, 262144,, % A_ThisLabel, 1 return #If (isControlVisible(listHwnd) && mouseisoverControl(listHwnd)) ~LButton:: GuiControlGet, var,, % CID ToolTip, % var, 0, 0 SendInput, {Alt Down}{Esc}{ALt Up} return #If GUIDropDownList_listGetHwnd(__hwnd) { ; https://autohotkey.com/boards/viewtopic.php?f=5&p=187310#post_content187289 VarSetCapacity(COMBOBOXINFO, (cbCOMBOBOXINFO:=(A_PtrSize == 8) ? 64 : 52), 0), NumPut(cbCOMBOBOXINFO, COMBOBOXINFO, 0, "UInt") return (DllCall("GetComboBoxInfo", "Ptr", __hwnd, "Ptr", &COMBOBOXINFO)) ? NumGet(COMBOBOXINFO, cbCOMBOBOXINFO - A_PtrSize, "Ptr") : null } isControlVisible(__controlID) { static WS_VISIBLE := "0x10000000" ControlGet, __style, Style,,, % "ahk_id " . __controlID return (__style & WS_VISIBLE) } ; https://autohotkey.com/board/topic/1555-determine-if-a-window-is-visible/ mouseIsOverControl(__controlHwnd) { __coordMode := A_CoordModeMouse ; A_CoordModeMouse contains the current setting of CoordMode, Mouse CoordMode, Mouse, Window MouseGetPos, __mousex, __mousey ControlGetPos, __x, __y, __w, __h,, % "ahk_id " . __controlHwnd CoordMode, Mouse, % __coordMode ; restore CoordMode, Mouse to its previous setting return (Between(__x, __x+__w, __mousex) && Between(__y, __y+__h, __mousey)) ; is the mouse over the control? } Between(__lowerBound, __upperBound, __var) { ; simple function wrapper for the if between... syntax If __var between %__lowerBound% and %__upperBound% return true return false }
里面创建函数都是较为高级的函数!