#singleinstance, force
#Warn, All, OutputDebug
space::
Gui HUD:New, +AlwaysOnTop +ToolWindow -Caption +HwndMainHwnd, hudWin
Gui HUD:Font,s14,Consolas
Gui, Add, Text,,% Clipboard
GuiControlGet, OutputVar, Pos, Static1
Gui HUD:Show
Return
上面是一个简单的程序,旨在显示剪贴板中的当前文本。这并不重要,我只是用它来了解有关 GUI 的更多信息。我似乎无法弄清楚的一件事是如何在活动监视器而不是主监视器的中心生成 GUI(我有 3 个监视器)
根据文档,
A_ScreenWidth
和A_ScreenHeight
适用于“主”监视器。另外看看SysGet,它主要是关于“主”监视器或监视器2。这没有多大意义。
我想创建动态
x
、y
、width
和 height
值以在 Gui HUD:Show
子命令中使用。这样,GUI 将始终在具有活动窗口或键盘焦点的监视器上生成。
我还假设“主”显示器是指具有任务栏和开始按钮的显示器。
我搜索了很多,令人惊讶的是没有太多关于这方面的内容。我是不是看漏了什么?
任何帮助将不胜感激!
我的解决方案是首先声明一个函数,根据给定的坐标查找监视器信息:
ScreenUtil_GetMonitorInfoAtPoint(x, y, &monitorIndex, &left, &top, &right, &bottom){
Loop MonitorGetCount(){
MonitorGet(A_Index, &_left, &_top, &_right, &_bottom)
if(_left < x && x < _right && _top < y && y < _bottom){
monitorIndex := A_Index
left := _left
top := _top
right := _right
bottom := _bottom
break
}
}
Error("Cannot find a monitor that encloses the point!")
}
然后,取决于您如何定义“主动监视器”:
MonitorInfo_ActiveWindow(){
WinGetPos(&mx, &my, &mw, &mh, "A")
x := mx + mw//2
y := my + mh//2
ScreenUtil_GetMonitorInfoAtPoint(x, y, &monitorIndex, &left, &top, &right, &bottom)
MsgBox("Width: " right - left "`nHeight: " bottom - top)
}
MonitorInfo_MousePointer(){
MouseGetPos(&mx, &my)
ScreenUtil_GetMonitorInfoAtPoint(mx, my, &monitorIndex, &left, &top, &right, &bottom)
MsgBox("Width: " right - left "`nHeight: " bottom - top)
}