[SOLVED] Scale on Win10 screws up fade function

Just starting out? Need help? Post your questions and find answers here.
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

[SOLVED] Scale on Win10 screws up fade function

Post by StarWarsFan »

I am obviously missing something and doing something wrong, but can you tell me what?

For the sake of the argument let us assume Win10 with a resolution of 1920x1080 and a scaling set to 125%

I am trying to get some API-function with a fading effect working, but it will not work "centered", it always shows a bit moved to the right.
As soon though as I set the scaling on Win10 to 100% it will appear as intended, in the center of the screen.
But again, as soon as a user has the Win10 default settings running (which is often >100%) it gets screwed up.


This is my code

Code: Select all

ExamineDesktops()
SystemParametersInfo_(#SPI_GETWORKAREA, 0, @r.RECT, 0)
WW = r\right - r\left
WH = r\bottom - r\top
bs=OpenWindow(#PB_Any,0,0,DesktopWidth(0),DesktopHeight(0),"",#PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Screen_WaitSynchronization)
SetWindowColor(bs,0)
HideWindow    (bs,#True)
CreateImage(0,WW,WH)
hDC = StartDrawing(ImageOutput(0))
BitBlt_(hDC,0,0,WW,WH,GetDC_(GetDesktopWindow_()), r\left,r\top, #SRCCOPY)
StopDrawing()  
myBrush = CreatePatternBrush_(ImageID(0))
SetClassLongPtr_(WindowID(bs), #GCL_HBRBACKGROUND, myBrush)
InvalidateRect_(WindowID (bs),0,1)
FreeImage(0)
AnimateWindow_(WindowID  (bs),700,#AW_CENTER|#AW_ACTIVATE)
How can I fix this issue so that it runs in the center of the screen DESPITE of what Win10 sets as scale?

// Moved from "Tricks 'n' Tips" (Kiffi)
Last edited by StarWarsFan on Mon Oct 11, 2021 9:52 am, edited 1 time in total.
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4635
Joined: Sun Apr 12, 2009 6:27 am

Re: Scale on Win10 screws up fade function

Post by RASHAD »

Hi

Code: Select all

h.WINDOWPLACEMENT
GetWindowPlacement_(GetDesktopWindow_(),@h)
x = h\rcNormalPosition\left
y = h\rcNormalPosition\top
WW = h\rcNormalPosition\right - h\rcNormalPosition\left
WH = h\rcNormalPosition\bottom - h\rcNormalPosition\top
bs=OpenWindow(#PB_Any,0,0,WW,WH,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Screen_WaitSynchronization)
SetWindowColor(bs,0)
HideWindow    (bs,#True)
CreateImage(0,WW,WH)
hDC = StartDrawing(ImageOutput(0))
BitBlt_(hDC,0,0,WW,WH,GetDC_(GetDesktopWindow_()), x,y, #SRCCOPY)
StopDrawing()  
myBrush = CreatePatternBrush_(ImageID(0))
SetClassLongPtr_(WindowID(bs), #GCL_HBRBACKGROUND, myBrush)
InvalidateRect_(WindowID (bs),0,1)
FreeImage(0)
AnimateWindow_(WindowID  (bs),700,#AW_CENTER|#AW_ACTIVATE)

Egypt my love
StarWarsFan
Enthusiast
Enthusiast
Posts: 169
Joined: Sat Mar 14, 2015 11:53 am

Re: Scale on Win10 screws up fade function

Post by StarWarsFan »

Fantastic, RASHAD! Thank you

One remark. Are X and Y not always 0 and 0 on fullscreen?
In that case this could be left out:
x = h\rcNormalPosition\left
y = h\rcNormalPosition\top

Correct?
Image - There is usually a lot of "try this, maybe do that" but ONLY an example that one can test for themself and get an immediate result actually brings people forward.
Post Reply