AutoHotkey Community

It is currently May 26th, 2012, 9:13 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: July 4th, 2009, 6:54 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Lexikos: I tried to test the flicker with your function above, with this script:
Code:
OnMessage(0x14, "WM_ERASEBKGND")

splash = 28
SetTimer Animate, 50
Gui +ToolWindow
Gui add, pic, h100 w100, %splash%.gif
Gui Show,,Lunar Phase

Animate:
   GuiControl,,Static1, % "*w100 *h100 " (splash := mod(splash,28)+1) ".gif"
   WinSetTitle Lunar Phase,,Lunar Phase - %splash%
   GuiControl,,Static1, *w100 *h100 %splash%.gif
Return

WM_ERASEBKGND(wParam) {
    if (A_Gui = 1) {
        Gui, +LastFound
        hwnd := WinExist()
       
        GuiControlGet, pic, Pos, Static1
        ; these are sometimes 0 when the background is erased!
        ; (it seems to be erased while the picture is changing)
        picW := 100
        picH := 100
       
        hdc := DllCall("GetDC", "uint", hwnd)
       
        ; Exclude the picture control from the clipping region.
        DllCall("ExcludeClipRect", "uint", hdc
            , "int", picX, "int", picY, "int", picX+picW, "int", picY+picH)
       
        ; Draw a black rectangle over the whole GUI.
        VarSetCapacity(rect, 16)
        DllCall("GetClientRect", "uint", hwnd, "uint", &rect)
        DllCall("FillRect", "uint", hdc
            , "uint", &rect
            , "uint", DllCall("GetStockObject", "int", 0x4))
       
        DllCall("ReleaseDC", "uint", hwnd, "uint", hdc)
        return 1
    }
}

GuiClose:
ExitApp
For some reason, in the Animate timer I have to update the picture twice (best seen with a timer period of 500 or larger), otherwise only every other picture is shown. However, I see absolutely no flicker in my Vista32 system. Could we modify WM_ERASEBKGND() such that this double update will not be necessary?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2009, 7:57 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
I spent an hour figuring out how to get rid of the flicker more easily. It turned out that in my Vista32 PC it is enough to have OnMessage(0x14, "WM_ERASEBKGND") with a WM_ERASEBKGND function, which just returns 0, or anything non-blank. Maybe the little added delay of calling an AHK function is enough for Windows to draw the picture properly?
Code:
OnMessage(0x14, "WM_ERASEBKGND")

splash = 28
SetTimer Animate, 50
Gui +ToolWindow
Gui add, pic, h100 w100, %splash%.gif
Gui Show,,Lunar Phase

Animate:
   WinSetTitle Lunar Phase,,% "Lunar Phase - " (splash := mod(splash,28)+1)
   GuiControl,,Static1, *w100 *h100 %splash%.gif
Return

WM_ERASEBKGND() {
   return 0
}

GuiClose:
ExitApp
In this case Windows seems to cache all pictures, because after a few seconds there is no measurable CPU load, the moon phases just roll smoothly. I wonder if these are true on Win7 or XP.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2009, 5:46 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Laszlo wrote:
For some reason, in the Animate timer I have to update the picture twice (best seen with a timer period of 500 or larger), otherwise only every other picture is shown.
I see that on my Win7-64 system with both our scripts. I wouldn't have noticed had you not pointed it out.
Quote:
Could we modify WM_ERASEBKGND() such that this double update will not be necessary?
After a bit more testing, I found that referencing A_Gui within WM_ERASEBKGND() causes GuiControl to fail every second call. For instance,
Code:
; OK:
WM_ERASEBKGND(wParam) {
    return 0
}

; FAIL:
WM_ERASEBKGND(wParam) {
    g := A_Gui
    return 0
}
Btw, simply returning/disabling WM_ERASEBKGND is not sufficient if there are margins around the picture control and desktop composition is not enabled/available (i.e. Win7 or WinVista with Classic theme, or WinXP with any theme).

Edit: :shock: :shock: :shock: :shock: :shock:
OK, now I'm sure there's a bug:
Code:
WM_ERASEBKGND(wParam) {
    wtf := A_AhkPath
    return 0
}
On my system, this causes the picture control to CHANGE TO THE AHK ICON.
Edit2: Changes to Explorer's icon:
Code:
WM_ERASEBKGND(wParam) {
    ErrorLevel := "C:\Windows\explorer.exe"
    ErrorLevel := ErrorLevel
}

Edit3: I've posted a bug report.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group