0

My main programming device is a laptop. Because this laptop has a high resolution screen, in the display settings in Windows, I have the setting 'Change the size of text, apps and other items' to 200%. I am developing an application that uses the User32 API in .NET, and use the following code to draw on the screen (I have modified the code to just put random colors on the screen, but my actual application uses images):

    <DllImport("User32.dll")>
    Public Shared Function GetDC(hwnd As IntPtr) As IntPtr
    End Function
    <DllImport("User32.dll")>
    Public Shared Sub ReleaseDC(hwnd As IntPtr, dc As IntPtr)
    End Sub
    <DllImport("user32.dll", SetLastError:=False)>
    Private Shared Function GetDesktopWindow() As IntPtr
    End Function
    Sub RandomPixels()
Dim desktopPtr As IntPtr = GetDC(GetDesktopWindow())
        Dim g As Graphics = Graphics.FromHdc(desktopPtr)
        For x = 0 To 1920
            For y = 0 To 1080
                Dim b As New SolidBrush(Color.FromArgb(255, rnd.Next(255), rnd.Next(255), rnd.Next(255)))
                g.FillRectangle(b, New Rectangle(x, y, 100, 100))
            Next

        Next
        g.Dispose()
        ReleaseDC(GetDesktopWindow(), desktopPtr)
End Sub

This, however, only paints in the top left corner of the screen. With experimentation, I have discovered that this only happens when that setting mentioned above is not on 100%.

I have spent hours searching the internet, and have found nothing, so help would be greatly appreciated!

Note: Because this question is basically about the Win32 API, not a specific language, I don't mind what language the answer is in (as long as it is in .NET) :).

William Taylor
  • 691
  • 8
  • 23
  • Your sizes (1920 and 1080) are hardcoded, so what do you expect ? You will have exactly the same problem if you execute your program on any computer with a higher screen resolution independently of the DPI settings. – Jabberwocky May 09 '17 at 10:00
  • No matter what the value is, it is always cropped into that top corner. Shapes or images I draw are also cut off outside of that corner. – William Taylor May 09 '17 at 10:01

0 Answers0