Hi,
As I continued to write the application I was working on, where a small part was the Magnifier (which this thread is all about) - I kept revisiting the flicker issue. Even with all the fantastic help that I received - the flicker remained; greatly reduced because of the help, but still noticable.
Funny enough I went back to one of my first solutions / observations - by adding the following two lines of code - the flicker disappeared:
Code: Select all
SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, #WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(0), 0, #Null, #LWA_COLORKEY)
But setting the window to layered / transparent - wasn't a usable option so I quickly moved on...
Rethinking things (after numerous failed solutions - on my part) why couldn't I use it - just change the transparent color to one that would never occur (at least within this context):
Code: Select all
SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, #WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(0), RGB(124, 109, 146), #Null, #LWA_COLORKEY)
Maybe I'm jumping the gun, but in every test so far - no flicker - thought I'd share:
NB*: If this thread is of interest to you, and can help in any way - don't just rely on this last post - some really relevant code form some great scripters (which this example draws from) occurs earlier in the thread, and may be of more use.
Code: Select all
Prototype ptDwmIsCompositionEnabled(*pfEnabled)
Prototype ptDwmFlush()
Global DwmIsCompositionEnabled.ptDwmIsCompositionEnabled
Global DwmFlush.ptDwmFlush
Global DwmResult, hDCin, glassSize
Procedure OpenWindowMagnify()
If OpenWindow(0, 0, 0, glassSize, glassSize, "Magnify", #PB_Window_ScreenCentered | #PB_Window_BorderLess)
SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, #WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(0), RGB(124, 109, 146), #Null, #LWA_COLORKEY)
StickyWindow(0, 1)
winRegion = CreateEllipticRgn_(0, 0, glassSize, glassSize)
SetWindowRgn_(WindowID(0), winRegion, #TRUE)
DeleteObject_(winRegion)
EndIf
EndProcedure
Procedure DrawImg()
hDCout = StartDrawing(WindowOutput(0))
BitBlt_(hDCout, 0, 0, glassSize, glassSize, hDCin, WindowX(0), WindowY(0), #SRCCOPY)
StopDrawing()
EndProcedure
Procedure MoveWindow(void)
Repeat
GetCursorPos_(p.POINT)
xpos = p\x - (glassSize / 2)
ypos = p\y - (glassSize / 2)
SetWindowPos_(WindowID(0), 0, xpos, ypos, glassSize, glassSize, #SWP_NOZORDER | #SWP_NOCOPYBITS)
DrawImg()
If DwmResult : DwmFlush() : EndIf
ForEver
EndProcedure
If OSVersion() >= #PB_OS_Windows_Vista
If OpenLibrary(0, "Dwmapi.dll")
DwmIsCompositionEnabled = GetFunction(0, "DwmIsCompositionEnabled")
DwmFlush = GetFunction(0, "DwmFlush")
If DwmFlush And DwmIsCompositionEnabled : DwmIsCompositionEnabled(@DwmResult) : EndIf
EndIf
EndIf
UseJPEGImageDecoder()
LoadImage(1, "C:\test.jpg")
glassSize = 200
OpenWindowMagnify()
ShowCursor_(0)
hDCin = CreateCompatibleDC_(0)
SelectObject_(hDCin, ImageID(1))
DrawImg()
If DwmResult : DwmFlush() : EndIf
CreateThread(@MoveWindow(), 0)
Repeat
Select WaitWindowEvent()
Case #WM_LBUTTONDBLCLK
DeleteDC_(hDCin)
ShowCursor_(1)
CloseWindow(0)
FreeImage(1)
Break
EndSelect
ForEver