Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Get display scale

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Antoshick
Advanced Cheater
Reputation: 0

Joined: 02 Nov 2018
Posts: 56

PostPosted: Sat Aug 29, 2020 3:42 am    Post subject: Get display scale Reply with quote

Hi there,
Can i with CE get display scale factor in Windows 10? Like 100%, or 175%, or 200%.
I just have a problem with 4K monitor and lua function 'setMousePos'. I use desktop scale 200% and desktop display resolution 4K, so when i try to set mouse cursor to center of game window

Code:

local x = game window resolution x / 2 + game window diff from left
local y = game window resolution y / 2 + game window diff from up
setMousePos(x,y)

i have wrong position (not centre). But if i use desktop scale 100% and desktop display resolution 4K, setMousePos(x,y) work fine (every time in centre of game window)
So i want to use scale factor for correct lua calculation

***************************************************
Update

Found that scale factor can be gain from windows registry, if know id of monitor.
Also found that
Code:
call user32.SetPhysicalCursorPos
called from asm from game will be use resolution for set mouse position without scale factor
But
Code:
setMousePos
called from lua engine will be use display resolution for set mouse position with scale factor.
So i use
Code:
call user32.SetPhysicalCursorPos


Thank
Back to top
View user's profile Send private message
blankTM
Cheater
Reputation: 1

Joined: 03 May 2020
Posts: 49

PostPosted: Sat Aug 29, 2020 12:14 pm    Post subject: Re: Get display scale Reply with quote

Code:

function Zoom()
local DC =executeCodeLocalEx('GetDC',0)
local DPIX=executeCodeLocalEx('GetDeviceCaps',DC,118)/executeCodeLocalEx('GetDeviceCaps',DC,8)
--local DPIY=getScreenHeight()/executeCodeLocalEx('GetDeviceCaps',DC,10)
executeCodeLocalEx('ReleaseDC',0,DC)
return DPIX
end
print(Zoom())


or
Use GetWindowRect to get the window rectangle

Code:

function GetWindowRect(hWnd)
local My = createMemoryStream()
My.Size= 16
executeCodeLocalEx('user32.GetWindowRect',hWnd,My.Memory)
local left= My.readDword()
if left > 0xffffff then
left= -0xfffffffe~left
end
local RECT ={
left=left,
top=My.readDword(),
right=My.readDword(),
bottom=My.readDword()
}
My.destroy()
return RECT
end
Back to top
View user's profile Send private message
Antoshick
Advanced Cheater
Reputation: 0

Joined: 02 Nov 2018
Posts: 56

PostPosted: Sat Aug 29, 2020 12:41 pm    Post subject: Re: Get display scale Reply with quote

blankTM wrote:
Code:

function Zoom()
local DC =executeCodeLocalEx('GetDC',0)
local DPIX=executeCodeLocalEx('GetDeviceCaps',DC,118)/executeCodeLocalEx('GetDeviceCaps',DC,8)
--local DPIY=getScreenHeight()/executeCodeLocalEx('GetDeviceCaps',DC,10)
executeCodeLocalEx('ReleaseDC',0,DC)
return DPIX
end
print(Zoom())


or
Use GetWindowRect to get the window rectangle

Code:

function GetWindowRect(hWnd)
local My = createMemoryStream()
My.Size= 16
executeCodeLocalEx('user32.GetWindowRect',hWnd,My.Memory)
local left= My.readDword()
if left > 0xffffff then
left= -0xfffffffe~left
end
local RECT ={
left=left,
top=My.readDword(),
right=My.readDword(),
bottom=My.readDword()
}
My.destroy()
return RECT
end


Thanks a lot!
Back to top
View user's profile Send private message
Antoshick
Advanced Cheater
Reputation: 0

Joined: 02 Nov 2018
Posts: 56

PostPosted: Sat Aug 29, 2020 11:36 pm    Post subject: Re: Get display scale Reply with quote

blankTM wrote:
Code:
local DPIX=executeCodeLocalEx('GetDeviceCaps',DC,118)


Tell me please where you get index value, like 118 or 8.
On MSDN and other sites i see only string parametres, like for example HORZSIZE or VERTSIZE and others same.
Back to top
View user's profile Send private message
blankTM
Cheater
Reputation: 1

Joined: 03 May 2020
Posts: 49

PostPosted: Sun Aug 30, 2020 1:04 am    Post subject: Re: Get display scale Reply with quote

Use C++ console to output parameters

or
/* Device Parameters for GetDeviceCaps() */
#define DRIVERVERSION 0 /* Device driver version */
#define TECHNOLOGY 2 /* Device classification */
#define HORZSIZE 4 /* Horizontal size in millimeters */
#define VERTSIZE 6 /* Vertical size in millimeters */
#define HORZRES 8 /* Horizontal width in pixels */
#define VERTRES 10 /* Vertical height in pixels */
#define BITSPIXEL 12 /* Number of bits per pixel */
#define PLANES 14 /* Number of planes */
#define NUMBRUSHES 16 /* Number of brushes the device has */
#define NUMPENS 18 /* Number of pens the device has */
#define NUMMARKERS 20 /* Number of markers the device has */
#define NUMFONTS 22 /* Number of fonts the device has */
#define NUMCOLORS 24 /* Number of colors the device supports */
#define PDEVICESIZE 26 /* Size required for device descriptor */
#define CURVECAPS 28 /* Curve capabilities */
#define LINECAPS 30 /* Line capabilities */
#define POLYGONALCAPS 32 /* Polygonal capabilities */
#define TEXTCAPS 34 /* Text capabilities */
#define CLIPCAPS 36 /* Clipping capabilities */
#define RASTERCAPS 38 /* Bitblt capabilities */
#define ASPECTX 40 /* Length of the X leg */
#define ASPECTY 42 /* Length of the Y leg */
#define ASPECTXY 44 /* Length of the hypotenuse */

#define LOGPIXELSX 88 /* Logical pixels/inch in X */
#define LOGPIXELSY 90 /* Logical pixels/inch in Y */

#define SIZEPALETTE 104 /* Number of entries in physical palette */
#define NUMRESERVED 106 /* Number of reserved entries in palette */
#define COLORRES 108 /* Actual color resolution */

// Printing related DeviceCaps. These replace the appropriate Escapes

#define PHYSICALWIDTH 110 /* Physical Width in device units */
#define PHYSICALHEIGHT 111 /* Physical Height in device units */
#define PHYSICALOFFSETX 112 /* Physical Printable Area x margin */
#define PHYSICALOFFSETY 113 /* Physical Printable Area y margin */
#define SCALINGFACTORX 114 /* Scaling factor x */
#define SCALINGFACTORY 115 /* Scaling factor y */

// Display driver specific

#define VREFRESH 116 /* Current vertical refresh rate of the */
/* display device (for displays only) in Hz*/
#define DESKTOPVERTRES 117 /* Horizontal width of entire desktop in */
/* pixels */
#define DESKTOPHORZRES 118 /* Vertical height of entire desktop in */
/* pixels */
#define BLTALIGNMENT 119 /* Preferred blt alignment */
Back to top
View user's profile Send private message
Antoshick
Advanced Cheater
Reputation: 0

Joined: 02 Nov 2018
Posts: 56

PostPosted: Sun Aug 30, 2020 2:13 am    Post subject: Re: Get display scale Reply with quote

blankTM wrote:
Use C++ console to output parameters

or
/* Device Parameters for GetDeviceCaps() */
#define DRIVERVERSION 0 /* Device driver version */
#define TECHNOLOGY 2 /* Device classification */
#define HORZSIZE 4 /* Horizontal size in millimeters */
#define VERTSIZE 6 /* Vertical size in millimeters */
#define HORZRES 8 /* Horizontal width in pixels */
#define VERTRES 10 /* Vertical height in pixels */
#define BITSPIXEL 12 /* Number of bits per pixel */
#define PLANES 14 /* Number of planes */
#define NUMBRUSHES 16 /* Number of brushes the device has */
#define NUMPENS 18 /* Number of pens the device has */
#define NUMMARKERS 20 /* Number of markers the device has */
#define NUMFONTS 22 /* Number of fonts the device has */
#define NUMCOLORS 24 /* Number of colors the device supports */
#define PDEVICESIZE 26 /* Size required for device descriptor */
#define CURVECAPS 28 /* Curve capabilities */
#define LINECAPS 30 /* Line capabilities */
#define POLYGONALCAPS 32 /* Polygonal capabilities */
#define TEXTCAPS 34 /* Text capabilities */
#define CLIPCAPS 36 /* Clipping capabilities */
#define RASTERCAPS 38 /* Bitblt capabilities */
#define ASPECTX 40 /* Length of the X leg */
#define ASPECTY 42 /* Length of the Y leg */
#define ASPECTXY 44 /* Length of the hypotenuse */

#define LOGPIXELSX 88 /* Logical pixels/inch in X */
#define LOGPIXELSY 90 /* Logical pixels/inch in Y */

#define SIZEPALETTE 104 /* Number of entries in physical palette */
#define NUMRESERVED 106 /* Number of reserved entries in palette */
#define COLORRES 108 /* Actual color resolution */

// Printing related DeviceCaps. These replace the appropriate Escapes

#define PHYSICALWIDTH 110 /* Physical Width in device units */
#define PHYSICALHEIGHT 111 /* Physical Height in device units */
#define PHYSICALOFFSETX 112 /* Physical Printable Area x margin */
#define PHYSICALOFFSETY 113 /* Physical Printable Area y margin */
#define SCALINGFACTORX 114 /* Scaling factor x */
#define SCALINGFACTORY 115 /* Scaling factor y */

// Display driver specific

#define VREFRESH 116 /* Current vertical refresh rate of the */
/* display device (for displays only) in Hz*/
#define DESKTOPVERTRES 117 /* Horizontal width of entire desktop in */
/* pixels */
#define DESKTOPHORZRES 118 /* Vertical height of entire desktop in */
/* pixels */
#define BLTALIGNMENT 119 /* Preferred blt alignment */


Thanks again!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites