ByTransient Expert Cheater Reputation: 5
Joined: 05 Sep 2020 Posts: 240
|
Posted: Sat Apr 24, 2021 4:15 pm Post subject: Re: Get window height and width function |
|
|
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.
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!
|
|