Hi, I think I have found a bug in AHK (1.0.48.5), but as I'm reasonably new I thought I'd try here first, just in case. EDIT - seems not to be AHK.
I wrote the WinPosFix code below, and it works well.
However, while it is active, and the first time I select 'Open' from another AHK tray icon (script b), the resulting window is badly positioned;
ie on my screen @ X Y W H = 0 998 160 26,
(actually 80 998 160 26 after WinPosFix changes it)
This is at the bottom of the screen & the height of the titlebar.
Without WinPosFix running it doesn't happen.
However, this bit points to the AHK Bug.
If I size the script b window nicely, it works on subsequent 'Open's, even if I move it off screen a bit and close it so WinPosFix moves it on re-'Open', but if I do a 'Reload this Script' then 'Open' (for script b, not for WinPosFix) it parks script b's window at the bottom again.
Hence the first 'Open' is the issue
Same happens for script c so it is not related to a particular script.
Now as you can see below I did some debugging, this shows that WinPosFix is not to blame, the trayline1 shows that the bad position is the initial size of the window Opened by AHK, not WinPosFix.
Can anyone see what may be going on?
Thanks
Michael
Code:
; WinPosFix - If a window is created which intrudes on
; - a Start/Task Bar at the top of the sceen (for those of us who like it that way),
; - the left part of the screen (My Computer etc icons)
; - the right edge of the screen (v0.5.0) or a smaller margin (v0.6)
; move it and/or resize it.
; - Note it only does this when the window is created, it doesn't get in the way of you moving stuff around.
;
; Minimaly tested by Michael@oz v0.6 2009
; v0.7 - Bug Fix, oops forgot to set wminwidth, a space instead of a comma in winmove
; v0.6 - add Right Margin support
; v0.5 - fix width to stop window going off right of screen (I don't care if it goes off the bottom edge).
;
;
;
; Thanks to Walter 'm00n' Monschein's script for the shellhook method
; -----------------------------------------------
#SingleInstance Force
#Persistent
#NoEnv
; -----------------------------------------------
; Settings
; -----------------------------------------------
WLeftMargin := 80 ; Set to zero if you like
WRightMargin := 1038 ; Set to zero to turn off
WScreenSaver := "Blank Screen Saver" ; Set to your screen saver text if problems occur
; Uncomment line flaged further below to find the right value
WMinWidth := 100
WMinHeight := 100 ; Currently not used
; -----------------------------------------------
; End of Settings
; -----------------------------------------------
SetBatchLines, -1
Process, Priority,, High
FileRead, WinList, winlist.txt
;
Gui +LastFound
hWnd := WinExist()
;
DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return
;-----------------------------------------------
ShellMessage( wParam,lParam )
{
global WScreenSaver, WLeftMargin, WMinWidth, WMinHeight, WRightMargin
global WLastTriggerTitle, trayline1, trayline2 ; Debug
If ( wParam = 1 ) ; HSHELL_WINDOWCREATED
{
SysGet, Mon1, MonitorWorkArea, 1
if WRightMargin Mon1Right := WRightMargin
WinGetPos, X, Y, W, H, ahk_id %lParam%
WOldY := Y ;debug
trayline1 = %x% %y% %w% %h% ;debug
; X&Y&W&H straight from the horses mouth pre WinPosFix processing
WinGetTitle, WTitle, ahk_id %lParam%
WTrigger := 0
if (Wtitle <> WScreenSaver)
{
if (Y<Mon1Top)
{
Y := Mon1Top
WTrigger := 1
}
if (X<WLeftMargin)
{
X := WLeftMargin
WTrigger := 1
}
if (X+W>Mon1Right and X < Mon1Right and Y<Mon1Bottom) ; if right edge off screen and left if on screen and top is on screen
{ ; - some programs hide windows off screen
W := Mon1Right-X
if (W < WMinWidth)
{
X := Mon1Right-WMinWidth
W := WMinWidth
}
WTrigger := 1
}
if WTrigger
{
WinMove,%WTitle%,,%X%,%Y%,%W%,%H%
WLastTriggerTitle := WTitle ; Debug Help Trace actions
trayline2 = %x% %y% %w% %h% ;debug
traytip,,%trayline1%`n%trayline2% ;debug
pause ;debug
}
}
}
}
;----------------------------------------------- ;)
