 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Michael@oz
Joined: 08 Nov 2009 Posts: 123 Location: Canberra oz
|
Posted: Sun Nov 15, 2009 4:11 am Post subject: Bug in AHK or my code? tray menu open = window badly pos'n |
|
|
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
}
}
}
}
;----------------------------------------------- ;)
| 
Last edited by Michael@oz on Sun Nov 15, 2009 9:08 am; edited 1 time in total |
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 1159 Location: San Diego, California
|
Posted: Sun Nov 15, 2009 7:32 am Post subject: |
|
|
I have win_vista 32, with two screens, taskbar and the bottom of the right screen. Must I move my taskbar to test your code ?
I attempted to follow your instruction to replicate the symptoms but cannot. Perhaps it is just me
Can you provide simplified instructions on how to recreate the problem.?
Perhaps a script_b ? |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 4367 Location: Qld, Australia
|
Posted: Sun Nov 15, 2009 8:14 am Post subject: |
|
|
AutoHotkey doesn't explicitly position its window. When the main window is created, it specifies CW_USEDEFAULT for the position and size; the system (i.e. Windows) decides where to put it.
| Quote: | | Code: | if WRightMargin Mon1Right := WRightMargin
WinGetPos, X, Y, W, H, ahk_id %lParam% |
| I suppose you meant this:
| Code: | if WRightMargin
Mon1Right := WRightMargin
WinGetPos, X, Y, W, H, ahk_id %lParam%
| What you actually got was equivalent to this:
| Code: | if (WRightMargin . (Mon1Right := WRightMargin))
WinGetPos, X, Y, W, H, ahk_id %lParam%
| I don't know whether that could cause the problem you described.
| Quote: | | ie on my screen @ X Y W H = 0 998 160 26, | That didn't happen to me. However, minimized windows on my system are reported as 160 x 25. I believe it varies based on visual style, font settings, etc. Perhaps it is also the default size for a window which has been given the (CW_USEDEFAULT) and not yet been made visible.
Edit: AutoHotkey minimizes its main window immediately after creating it if the taskbar was active when the script launched. Comments from the source code explain:
| Code: | // Now that the first call to ShowWindow() is out of the way, minimize the main window so that
// if the script is launched from the Start Menu (and perhaps other places such as the
// Quick-launch toolbar), the window that was active before the Start Menu was displayed will
// become active again. But as of v1.0.25.09, this minimize is done more selectively to prevent
// the launch of a script from knocking the user out of a full-screen game or other application
// that would be disrupted by an SW_MINIMIZE: |
You may detect this before attempting to resize the window by using WinGet, OutputVar, MinMax, WinTitle.
(I reproduced your problem by putting the script in my Start Menu and launching from there.) |
|
| Back to top |
|
 |
Michael@oz
Joined: 08 Nov 2009 Posts: 123 Location: Canberra oz
|
Posted: Sun Nov 15, 2009 9:04 am Post subject: |
|
|
| Quote: |
I have win_vista 32, with two screens, taskbar and the bottom of the right screen. Must I move my taskbar to test your code ?
|
Thanks Leef_me for trying.
I'm on Xp (on this Notebook, have not tried it in my Vista Server), both with single screens. I did forget to comment that as I have single screen, I have not tested on multiple monitors. Feel free to describe how you think it should behave with multiple monitors.
Given it uses SysGet & the default monitor, your main monitor should do. Interestingly I just reread the help for SysGet, it says "the primary monitor is used", I presume primary is the one with the Start Button(?).
However Lexikos's response may make further testing redundant at this time.
No I don't think taskbar at bottom/top should make any difference, UNLESS AHK internally tries to position the 'Open' window taking task bar into consideration?? Update - just moved my task bar to bottom, still happens.
| Quote: |
Can you provide simplified instructions on how to recreate the problem.?
Perhaps a script_b ?
|
Yep.
a. Script b
b. Steps (I just did this after Lexikos's 'if' correction - below)
Run WinPosFix
Run Script-b
RightClick Script-b Tray Icon, Click 'Open'
;Opens Window Normally - I know this is different than described above
Click CloseBox of the new window
RightClick Script-b Tray Icon, Click 'Reload This Script'
RightClick Script-b Tray Icon, Click 'Open'
;New Window Opens at bottom
c.
Thanks Lexikos, I Suspect you are on the right track with the CW_USEDEFAULT aspect.
I fixed the if & still happens.
For immediate productivity I will code a test for the 160x26'ish size and change to something more reasonable. I suppose for broad compatability < x% of 640x480 would be reasonable, I think 50% would do.
Perhaps I may try for first Winactivate rather than first create and see if Windows uses a better size/pos.
Noth'n simple about this stuff....#@$%$# simple fix turns into a project...
I suppose it would be boring if everything worked first time...
Thanks again everyone.
Michael
EDIT Thanks for your update Lexikos makes sense, will try your suggestion. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|