Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: ClientToScreen && DrawFocusRect - Someone is telling fibs.



Permlink Replies: 2 - Last Post: Feb 23, 2016 4:55 PM Last Post By: Dave Newell
Dave Newell

Posts: 3
Registered: 3/23/16
ClientToScreen && DrawFocusRect - Someone is telling fibs.
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 23, 2016 2:28 PM
Hi guys,

I do a click and drag operation in my windows application.

I map the TPanel I'm clicking and dragging to screen pixel coordinates using ClientToScreen, I grab the screen handle using GetDC(0), then I draw the focus rect using DrawFocusRect.

This works if the scaling of each screen is 100%, on high dpi displays (like my mac - running win8) the focus rect is offset and scaled down accordingly, ClientToScreen maps to the scaled screen size not the true screen size.

Essentially the problem is that ClientToScreen maps to the scaled window, whereas DrawFocusRect, given the screen DC, maps to the entire unscaled screen.

Is there another DC I can draw on? I'm told there's a DC for the application that windows uses for the live thumbnail when you hover your mouse over the application on the taskbar?

What about a way to find the scaling or the true monitor dimensions?

I'm using VCL on C++ Builder XE7.

Thanks guys!
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: ClientToScreen && DrawFocusRect - Someone is telling fibs.
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 23, 2016 3:19 PM   in response to: Dave Newell in response to: Dave Newell
Dave wrote:

This works if the scaling of each screen is 100%, on high dpi displays
(like my mac - running win8) the focus rect is offset and scaled down
accordingly, ClientToScreen maps to the scaled screen size not the
true screen size.

Makes sense. If your app is not High-DPI aware, Windows has to "lie" to
your app regarding monitor resolutions and such, so as not to break old APIs
and legacy code that does not handle High-DPI.

Is there another DC I can draw on?

No.

I'm told there's a DC for the application that windows uses for the live
thumbnail when you hover your mouse over the application on the taskbar?

When Windows needs to display a preview or live thumbnail, it sends a message
to the app asking for the image. The app calls DwmSetIconicLivePreviewBitmap()
or DwmSetIconicThumbnail() accordingly to provide Windows with an HBITMAP
handle for the image, which Windows then renders however it wants. You do
not have access to any HDC or HWND that is used for displaying the image
to the user.

What about a way to find the scaling or the true monitor dimensions?

You app has to be marked as High-DPI aware in order to get that information.

Writing DPI-Aware Desktop and Win32 Applications
https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266.aspx

--
Remy Lebeau (TeamB)
Dave Newell

Posts: 3
Registered: 3/23/16
Re: ClientToScreen && DrawFocusRect - Someone is telling fibs.
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 23, 2016 4:55 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
You app has to be marked as High-DPI aware in order to get that information.

Writing DPI-Aware Desktop and Win32 Applications
https://msdn.microsoft.com/en-us/library/windows/desktop/dn469266.aspx

--
Remy Lebeau (TeamB)

I also found this link too:
https://community.embarcadero.com/blogs/entry/how-to-guide-upgrading-your-delphi-vcl-applications-to-support-4k-displays

It's technically for delphi but it seems relevant and the windows explanation is relevant.

Oh well, better crack on with it then. Thanks for your time Remy.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02