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
Goto page 1, 2  Next
 
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: Tue Jan 07, 2020 12: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 game window, also position of the game window on the desktop?
With using lua or another ways.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25864
Location: The netherlands

PostPosted: Tue Jan 07, 2020 12:25 pm    Post subject: Reply with quote

if you can get the window handle yes

this code prints out the position of the windows calculator:
Code:

x=findWindow(nil,'Calculator')

m=createMemoryStream()
m.size=16

if executeCodeLocalEx('GetWindowRect',x,m.Memory) then
  m.Position=0
  print("left="..m.readDword())
  print("top="..m.readDword())
  print("right="..m.readDword())
  print("bottom="..m.readDword())
end
m.destroy()

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Antoshick
Advanced Cheater
Reputation: 0

Joined: 02 Nov 2018
Posts: 56

PostPosted: Wed Jan 08, 2020 1:10 am    Post subject: Reply with quote

Dark Byte wrote:
if you can get the window handle yes

this code prints out the position of the windows calculator:
Code:

x=findWindow(nil,'Calculator')

m=createMemoryStream()
m.size=16

if executeCodeLocalEx('GetWindowRect',x,m.Memory) then
  m.Position=0
  print("left="..m.readDword())
  print("top="..m.readDword())
  print("right="..m.readDword())
  print("bottom="..m.readDword())
end
m.destroy()


With this code i see this result (Calculator is running)
Code:

left=139390200
top=0
right=259625016
bottom=0


Also with the game the same result
Only with Notepad I see the correct values.

What am i doing wrong?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25864
Location: The netherlands

PostPosted: Wed Jan 08, 2020 2:42 am    Post subject: Reply with quote

Not using CE 7.0 ?

findWindow not finding the correct window? (could be an invisible window somewhere else with that name)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Antoshick
Advanced Cheater
Reputation: 0

Joined: 02 Nov 2018
Posts: 56

PostPosted: Wed Jan 08, 2020 4:47 am    Post subject: Reply with quote

Dark Byte wrote:
Not using CE 7.0 ?

findWindow not finding the correct window? (could be an invisible window somewhere else with that name)


I am using CE 7.0, reinstalled it today from url - https://github.com/cheat-engine/cheat-engine/releases/tag/7.0 - CheatEngine70.exe 17 MB.
Also Windows 10 1909 Rus language, intel i5.

How can i check if findWindow not finding the correct window? What script?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25864
Location: The netherlands

PostPosted: Wed Jan 08, 2020 9:18 am    Post subject: Reply with quote

In CE there is a "tools->dissect windows"

the value in front of the windows are window handles, check if they match up

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Antoshick
Advanced Cheater
Reputation: 0

Joined: 02 Nov 2018
Posts: 56

PostPosted: Wed Jan 08, 2020 1:05 pm    Post subject: Reply with quote

Dark Byte wrote:
In CE there is a "tools->dissect windows"

the value in front of the windows are window handles, check if they match up


i atached calculator.exe to CE by processes and then opened "tools->dissect windows", but for calculator i don't see any values, i see only this
Code:
000B0856 - MSCTFIME UI - (MSCTFIME UI) (Invis)
001001CA - Default IME - (IME) (Invis)


for other programms i see third string. for example for notepad and for games.
Only calculator won't work.

Also, if i get handle for some game from "tools->dissect windows" and use it instead
Code:
x=findWindow(nil,'grid')


for example
Code:
x=0x000B0856

script work fine and shows correct values.

Maybe i use incorrect name of game window (nil,'grid')?
How to get correct name of window, is it have the same name as exe process?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25864
Location: The netherlands

PostPosted: Wed Jan 08, 2020 1:50 pm    Post subject: Reply with quote

Look at the window list when attached to the target (e.g grid)

Check the windows that do not have the (invis) tag

Then note down the caption

If there is more than one or a common name, then also use the classname (the first entry between round brackets () )

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Antoshick
Advanced Cheater
Reputation: 0

Joined: 02 Nov 2018
Posts: 56

PostPosted: Thu Jan 09, 2020 12:06 am    Post subject: Reply with quote

Dark Byte wrote:

Then note down the caption


Now work fine, with caption from "tools->dissect windows", tested for 2 games, but third game has specific caption
Code:
000C08D4-Need for Speed? Rivals - (Need for Speed? Rivals)

and script not work if i use
Code:
x=findWindow(nil,'Need for Speed? Rivals')

also not work if i use
Code:
x=findWindow(Need for Speed? Rivals,'Need for Speed? Rivals')


This third game window has this title


Can i get handle from another way, with using lua script and game process name? or another.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25864
Location: The netherlands

PostPosted: Thu Jan 09, 2020 2:05 am    Post subject: Reply with quote

this code will return a similar result which is more easily copy/pasted
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

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Antoshick
Advanced Cheater
Reputation: 0

Joined: 02 Nov 2018
Posts: 56

PostPosted: Thu Jan 09, 2020 5:04 am    Post subject: Reply with quote

Dark Byte wrote:
this code will return a similar result which is more easily copy/pasted
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


With caption 'Need for Speed? Rivals', which i copy/past, script still not work correct. Anyway now with this last i can get correct values of window

Code:
w=getWindow(getForegroundWindow(), GW_HWNDFIRST)
pid=getOpenedProcessID()
game_window_handle = 0

while w and (w~=0) do
  if getWindowProcessID(w)==pid then
  game_window_handle = w
  end
  w=getWindow(w,GW_HWNDNEXT)
end


m=createMemoryStream()
m.size=16

if executeCodeLocalEx('GetWindowRect',game_window_handle,m.Memory) then
  m.Position=0
  print("left="..m.readDword())
  print("top="..m.readDword())
  print("right="..m.readDword())
  print("bottom="..m.readDword())
end
m.destroy()


Thank for your help.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1543

PostPosted: Thu Jan 09, 2020 8:24 pm    Post subject: Reply with quote

Code:
x=findWindow(nil,'Need for Speed™ Rivals')

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Antoshick
Advanced Cheater
Reputation: 0

Joined: 02 Nov 2018
Posts: 56

PostPosted: Fri Jan 10, 2020 12:02 am    Post subject: Reply with quote

Aylin wrote:
Code:
x=findWindow(nil,'Need for Speed™ Rivals')


Thank, but with this string, the script does not show the correct values.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 37

Joined: 16 Feb 2017
Posts: 1543

PostPosted: Fri Jan 10, 2020 1:38 am    Post subject: Reply with quote

Antoshick wrote:
Aylin wrote:
Code:
x=findWindow(nil,'Need for Speed™ Rivals')


Thank, but with this string, the script does not show the correct values.


Use the name given by the application to Windows.
Look in: Open Windows Task Manager.
See the first section in Task Manager (Applications)
There you will see the full name of the game window.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Antoshick
Advanced Cheater
Reputation: 0

Joined: 02 Nov 2018
Posts: 56

PostPosted: Fri Jan 10, 2020 4:08 am    Post subject: Reply with quote

Quote:
Use the name given by the application to Windows.
Look in: Open Windows Task Manager.
See the first section in Task Manager (Applications)
There you will see the full name of the game window.


The same effect, incorrect values
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
Goto page 1, 2  Next
Page 1 of 2

 
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