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 window height and width function

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
verygood14101
How do I cheat?
Reputation: 0

Joined: 16 Mar 2021
Posts: 3

PostPosted: Sat Apr 24, 2021 1:13 pm    Post subject: Get window height and width function Reply with quote

Can I use CE to get the height and width of the desktop game window?
With the use of lua or method
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Sat Apr 24, 2021 4:15 pm    Post subject: Re: Get window height and width function Reply with quote

verygood14101 wrote:
Can I use CE to get the height and width of the desktop game window?
With the use of lua or method


I guess yes.
I've edited the results reached in CEF searches and I'm sending the result to you.
Note: Some bonuses may come in handy. Wink
Note2: Pay attention to the comments in the code.

For example use, I created a form and tried it.
Window handle title "UDF1".
If you want to get a window handle name, try this;
Bonus1:
Code:
w=getWindow(getForegroundWindow(), GW_HWNDFIRST)

pid=getOpenedProcessID()

while w and (w~=0) do
  if getWindowProcessID(w)==pid then
    print(w..' - '..getWindowCaption(w)..'('..getWindowClassName(w)..')')
  end
  w=getWindow(w,GW_HWNDNEXT)
end


If you found your window name, write it in the code below:
Here is your code:
Code:
x=findWindow(nil,'UDF1') --My window handle header is "UDF1"

m=createMemoryStream()
m.size=16

if executeCodeLocalEx('GetWindowRect',x,m.Memory) then
  m.Position=0
  local lft=(m.readDword())
  local tp=(m.readDword())
  local rgt=(m.readDword())
  local btm=(m.readDword())

--If the window position is negative, let's fix it.
  if lft>4294900000 then lft=lft - 4294967296  end
  if tp>4294900000 then tp=tp - 4294967296  end
--Let's compare the values obtained and reach the result of width and height.
  local wdt=tonumber(rgt) - tonumber(lft)
  local hgt=tonumber(btm) - tonumber(tp)
--There may be some deviations. But the result is approximate.
  print("left= "..lft.."\ntop= "..tp.."\nright= "..rgt.."\nbottom= "..btm.."\nheight= "..hgt.."\nwidth= "..wdt.."\n")
end
m.destroy()


If you want to set the window size yourself, this code will allow you to resize your window.
Bonus2:
(x="UDF1" or your window name)
Code:
local HWND_TOP = 0
local SWP_NOSENDCHANGING = 1024
executeCodeLocalEx("user32.SetWindowPos", x, HWND_TOP, 0, 10, 400, 600, SWP_NOSENDCHANGING)

Result:
Code:
left= 0
top= 10
right= 400
bottom= 610
height= 600
width= 400

Source: CEF

Enjoy it! Cool
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