Test script below, which should be kept running before and after hibernation, demonstrates the problem.
;===Auto-execute======================================================================== Width := 300, Height := 300 RecreateAndShow: Gui 1: Destroy Gui 1: -Caption +E0x80000 +LastFound +ToolWindow +AlwaysOnTop +OwnDialogs Gui 1: Show, NA hwnd := WinExist() pToken := Gdip_Startup() hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm) G := Gdip_GraphicsFromHDC(hdc), Gdip_SetSmoothingMode(G, 4), Gdip_SetInterpolationMode(G, 7) pBrush := Gdip_CreateLineBrushFromRect(0, 0, Width, Height, 0xee5555ff, 0x555555ff) Gdip_FillEllipse(G, pBrush, 0, 0, Width-1, Height-1) Gdip_DeleteBrush(pBrush) UpdateLayeredWindow(hwnd, hdc, (A_ScreenWidth-Width)/2, (A_ScreenHeight-Height)/2, Width, Height) SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc), Gdip_DeleteGraphics(G) Gdip_Shutdown(pToken) Return ;===Hotkeys============================================================================= F1:: if DllCall("IsWindowVisible", "Ptr", hwnd) Gui 1: Hide else Gui 1: Show, NA return F2::Gui 1: Show, NA F3::Gui 1: Hide F4:: MsgBox,,, % DllCall("IsWindowVisible", "Ptr", hwnd) ? "Window IS visible" : "Window IS NOT visible",1 F5::Gosub, RecreateAndShow ; solution number 2 Esc::ExitApp ;===Functions=========================================================================== #Include Gdip.ahk ; by Tic http://www.autohotkey.com/forum/topic32238.htmlOn Windows XP and Windows Vista, everything works perfectly before and after hibernation - pressing F1 shows and hides blue circle.
On Windows 7, everything works perfectly before hibernation, but not any more after resuming from hibernation - pressing F1 doesn't show/hide blue circle - it's simply never displayed on the screen. Pressing F2, which should explicitly show window, doesn't help too. It's interesting that after pressing F2, and than pressing F4, MsgBox shows "Window IS visible" although window is not displayed on the screen. So window is visible but I can't see it?
Why window isn't displayed although it should be?
Am I doing something wrong?
If not, here are some solutions I figured out myself - monitor "resuming from suspended state" event (monitor WM_POWERBROADCAST = 0x218, wParam=7), and after such event occurs, automatically:
[*:3vcsmctn]reload entire script - good for simple scripts like this, but not for big scripts where one layered window is just one tiny component.
[*:3vcsmctn]don't reload entire script, just recreate and show layered window - effect like pressing F5 hotkey in test script above
[*:3vcsmctn]don't reload entire script, just update and show layered window - effect like pressing F5 hotkey in test script below. Contrary to test script above, which deletes bitmap, device context, graphics, and shuts down GDI+, on Auto-Execute end, this one is doing it on script exit.
;===Auto-execute======================================================================== Width := 300, Height := 300 OnExit, ExitSub Gui 1: -Caption +E0x80000 +LastFound +ToolWindow +AlwaysOnTop +OwnDialogs Gui 1: Show, hide hwnd := WinExist() pToken := Gdip_Startup() hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm) G := Gdip_GraphicsFromHDC(hdc), Gdip_SetSmoothingMode(G, 4), Gdip_SetInterpolationMode(G, 7) pBrush := Gdip_CreateLineBrushFromRect(0, 0, Width, Height, 0xee5555ff, 0x555555ff) Gdip_FillEllipse(G, pBrush, 0, 0, Width-1, Height-1) Gdip_DeleteBrush(pBrush) UpdateAndShow: UpdateLayeredWindow(hwnd, hdc, (A_ScreenWidth-Width)/2, (A_ScreenHeight-Height)/2, Width, Height) Gui 1: Show, NA Return ;===Hotkeys============================================================================= F1:: if DllCall("IsWindowVisible", "Ptr", hwnd) Gui 1: Hide else Gui 1: Show, NA return F2::Gui 1: Show, NA F3::Gui 1: Hide F4:: MsgBox,,, % DllCall("IsWindowVisible", "Ptr", hwnd) ? "Window IS visible" : "Window IS NOT visible",1 F5::Gosub, UpdateAndShow ; solution number 3 Esc::ExitApp ;===Subroutines========================================================================= ExitSub: SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc), Gdip_DeleteGraphics(G) Gdip_Shutdown(pToken) ExitApp ;===Functions=========================================================================== #Include Gdip.ahk ; by Tic http://www.autohotkey.com/forum/topic32238.htmlWhich solution do you recommend? Do you have something better? Other ideas?
Thanks.