Creating a Simple Direct2D Application: 'ID2D1Factory::GetDesktopDpi': Deprecated. Use...

Dsp 1024 51 Reputation points
2020-11-20T19:13:49.537+00:00

Hi all,
I'm using windows 10 pro with VS2019 comm.

I'm a noob at win32api stuff. I can do more with c# and .net (WPF) but I'm not a software developer. I was trying to follow the example for direct2d in this link:

https://learn.microsoft.com/en-us/windows/win32/direct2d/direct2d-quickstart

After I managed to figure out where to place the code, I compiled it and I get this error:

Error C4996 'ID2D1Factory::GetDesktopDpi': Deprecated. Use DisplayInformation::LogicalDpi for Windows Store Apps or GetDpiForWindow for desktop apps.

at this line: m_pDirect2dFactory->GetDesktopDpi(&dpiX, &dpiY);

I understand the error but I don't understand the suggested solution. This is not for the windows store (I think) so I need to use GetDpiForWindow. Here is the link for GetDpiForWindow:

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdpiforwindow

The arguments are not the same as ID2D1Factory::GetDesktopDpi so I'm baffled. Any help is appreciated.

Thanks

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,678 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 86,151 Reputation points
    2020-11-20T20:09:15.963+00:00

    You can use :

     dpiX = (FLOAT)GetDpiForWindow(GetDesktopWindow());
     dpiY = dpiX;
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.