@@ -132,7 +132,9 @@ Rectangle getBoundsInPixels () {
132
132
if (width == 0 ) {
133
133
int [] buffer = new int [1 ];
134
134
if (OS .SystemParametersInfo (OS .SPI_GETCARETWIDTH , 0 , buffer , 0 )) {
135
- return new Rectangle (getXInPixels (), getYInPixels (), buffer [0 ], getHeightInPixels ());
135
+ int width = DPIUtil .pixelToPoint (buffer [0 ], getPrimaryMonitorZoomAtStartup ());
136
+ int widthInPixels = Win32DPIUtils .pointToPixel (width , getNativeZoom ());
137
+ return new Rectangle (getXInPixels (), getYInPixels (), widthInPixels , getHeightInPixels ());
136
138
}
137
139
}
138
140
return new Rectangle (getXInPixels (), getYInPixels (), getWidthInPixels (), getHeightInPixels ());
@@ -226,7 +228,9 @@ Point getSizeInPixels () {
226
228
if (width == 0 ) {
227
229
int [] buffer = new int [1 ];
228
230
if (OS .SystemParametersInfo (OS .SPI_GETCARETWIDTH , 0 , buffer , 0 )) {
229
- return new Point (buffer [0 ], getHeightInPixels ());
231
+ int width = DPIUtil .pixelToPoint (buffer [0 ], getPrimaryMonitorZoomAtStartup ());
232
+ int widthInPixels = Win32DPIUtils .pointToPixel (width , getNativeZoom ());
233
+ return new Point (widthInPixels , getHeightInPixels ());
230
234
}
231
235
}
232
236
return new Point (getWidthInPixels (), getHeightInPixels ());
@@ -370,7 +374,8 @@ void resize () {
370
374
if (image == null && widthInPixels == 0 ) {
371
375
int [] buffer = new int [1 ];
372
376
if (OS .SystemParametersInfo (OS .SPI_GETCARETWIDTH , 0 , buffer , 0 )) {
373
- widthInPixels = buffer [0 ];
377
+ int width = DPIUtil .pixelToPoint (buffer [0 ], getPrimaryMonitorZoomAtStartup ());
378
+ widthInPixels = Win32DPIUtils .pointToPixel (width , getNativeZoom ());
374
379
}
375
380
}
376
381
OS .CreateCaret (hwnd , hBitmap , widthInPixels , getHeightInPixels ());
@@ -449,7 +454,8 @@ void setFocus () {
449
454
if (image == null && widthInPixels == 0 ) {
450
455
int [] buffer = new int [1 ];
451
456
if (OS .SystemParametersInfo (OS .SPI_GETCARETWIDTH , 0 , buffer , 0 )) {
452
- widthInPixels = buffer [0 ];
457
+ int width = DPIUtil .pixelToPoint (buffer [0 ], getPrimaryMonitorZoomAtStartup ());
458
+ widthInPixels = Win32DPIUtils .pointToPixel (width , getNativeZoom ());
453
459
}
454
460
}
455
461
OS .CreateCaret (hwnd , hBitmap , widthInPixels , getHeightInPixels ());
@@ -646,6 +652,13 @@ public void setVisible (boolean visible) {
646
652
}
647
653
}
648
654
655
+ private int getPrimaryMonitorZoomAtStartup () {
656
+ long hDC = OS .GetDC (0 );
657
+ int dpi = OS .GetDeviceCaps (hDC , OS .LOGPIXELSX );
658
+ OS .ReleaseDC (0 , hDC );
659
+ return DPIUtil .mapDPIToZoom (dpi );
660
+ }
661
+
649
662
/**
650
663
* <b>IMPORTANT:</b> This method is not part of the public
651
664
* API for Image. It is marked public only so that it
0 commit comments