edit: now the gui position is saved in the registry
Code:
#notrayicon
#singleinstance force
SysGet, MonitorCount, MonitorCount
Loop , %MonitorCount%
{
SysGet, Mon%A_Index% , Monitor , %A_Index%
r := Mon%A_Index%Right
b:= Mon%A_Index%Bottom
right = % Max( right , r )
bottom = % Max( bottom , b )
}
MinX1 := 0
MinY1 := 0
MaxX2 := right
MaxY2 := bottom
RegRead, xpos, HKEY_CURRENT_USER, Software\AutoHotkey\IPGadget, xpos
RegRead, ypos, HKEY_CURRENT_USER, Software\AutoHotkey\IPGadget, ypos
if ErrorLevel
{
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\AutoHotkey\IPGadget, xpos, 0
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\AutoHotkey\IPGadget, ypos, 0
}
;To autostart with windows (optional); RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Run, Gadget IP, %A_ScriptFullPath%
URLDownloadToFile, http://whatismyip.org, ip52362441.txt
FileRead, ip, ip52362441.txt
FileDelete ip52362441.txt
Gui, Color, ff00f0
Gui +LastFound
hwnd := WinExist()
Gui, Add, Text, x120 y0 w10 h10 gclose,
Gui, Add, Text, x108 y0 w10 h10 grefresh,
Gui, Add, Picture, x0 y0 h62 w130 BackgroundTrans, %A_scriptdir%/intern_extern_ip.png
gui, font, s6.5 cFFFFFF, Gauutami
Gui, Add, Text, x46 y30 w77 h13 gLAN BackgroundTrans +Right, %A_IPAddress1%
Gui, Add, Text, x46 y45 w77 h13 gWAN BackgroundTrans +Right, %ip%
Gui -Caption +toolwindow
Gui, Show, x%xpos% y%ypos% h62 w130, Lan/Wan IP
WinSet, TransColor, ff00f0
SetTimer , GetPos , 500
OnMessage(WM_MOVING := 0x0216, "_WM_Moving")
Return
close:
GuiClose:
ExitApp
Refresh:
Reload
Return
WAN:
clipboard = %ip% ; Clicking the ip will copy it.
Return
LAN:
clipboard = %A_IPAddress1%
Return
#d::
WinMinimizeAll
~LButton & ~RButton::
PostMessage, 0xA1, 2,,, A
return
GetPos:
WinGetPos, X, Y, , , ahk_id %hwnd%
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\AutoHotkey\IPGadget, xpos, %X%
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\AutoHotkey\IPGadget, ypos, %Y%
return
Max(x,y)
{
return ( x<=y ? y : x )
}
_WM_Moving(WPARAM, LPARAM) {
Global MinX1, MinY1, MaxX2, MaxY2
Critical
X1 := NumGet(LPARAM+0, 0, "Int")
Y1 := NumGet(LPARAM+4, 0, "Int")
X2 := NumGet(LPARAM+8, 0, "Int")
Y2 := NumGet(LPARAM+12, 0, "Int")
If (X1 < MinX1) {
NumPut(MinX1, LPARAM+0, 0, "Int")
NumPut(X2 + (MinX1 - X1), LPARAM+8, 0, "Int")
}
If (Y1 < MinY1) {
NumPut(MinY1, LPARAM+4, 0, "Int")
NumPut(Y2 + (MinY1 - Y1), LPARAM+12, 0, "Int")
}
If (X2 > MaxX2) {
NumPut(MaxX2, LPARAM+8, 0, "Int")
NumPut(X1 - (X2 - MaxX2), LPARAM+0, 0, "Int")
}
If (Y2 > MaxY2) {
NumPut(MaxY2, LPARAM+12, 0, "Int")
NumPut(Y1 - (Y2 - MaxY2), LPARAM+4, 0, "Int")
}
}