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 


SetForegroundWindow for trainer form

 
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: Thu Jan 16, 2020 8:35 am    Post subject: SetForegroundWindow for trainer form Reply with quote

I want to make a hotkey for the set trainer form as SetForegroundWindow.
Because the game always captures the cursor, so this option in the trainer will be useful

But as i found in myself, CE exe trainer won't use SetForegroundWindow for his form, only another windows, like games, notepad. etc.

I tried using
Code:
x=findWindow(nil,'UDF1')
executeCodeLocal('SetForegroundWindow',x)

also
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
executeCodeLocal('SetForegroundWindow',game_window_handle )
 

Nothing works

Maybe CE have default option for make his for as SetForegroundWindow?
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1668

PostPosted: Thu Jan 16, 2020 9:36 am    Post subject: Reply with quote

Maybe (not tested):

Code:
function getAttachedProcessName()
    local m = enumModules();
    if (#m > 0) then
        return m[1].Name;
    end
    return nil;
end

local game = 'solitaire.exe'

function ActivateApp(p)
 p = getAttachedProcessName()
 -- print(p)
 if p ~= game or p == nil then
  showMessage('No process opened')
  return nil
 else
  --executeCodeLocal('LockSetForegroundWindow',p[0])
  x=findWindow(nil,'UDF1')
  executeCodeLocalEx('LockSetForegroundWindow',x)
 end
end

-- example
UDF1.show()
ActivateApp('solitaire.exe')

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Antoshick
Advanced Cheater
Reputation: 0

Joined: 02 Nov 2018
Posts: 56

PostPosted: Thu Jan 16, 2020 11:04 am    Post subject: Reply with quote

Corroder wrote:
Maybe (not tested):

Code:
function getAttachedProcessName()
    local m = enumModules();
    if (#m > 0) then
        return m[1].Name;
    end
    return nil;
end

local game = 'solitaire.exe'

function ActivateApp(p)
 p = getAttachedProcessName()
 -- print(p)
 if p ~= game or p == nil then
  showMessage('No process opened')
  return nil
 else
  --executeCodeLocal('LockSetForegroundWindow',p[0])
  x=findWindow(nil,'UDF1')
  executeCodeLocalEx('LockSetForegroundWindow',x)
 end
end

-- example
UDF1.show()
ActivateApp('solitaire.exe')


Does not work. I put it script on a timer (3 sec) and generate an exe, and run this exe. But the form is still in the background.

Also i tried simple
Code:
x=findWindow(nil,'UDF1')
executeCodeLocal('SetForegroundWindow',x)

in a timer on exe trainer, too doesn't work.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Thu Jan 16, 2020 11:27 am    Post subject: Reply with quote

try
Code:

UDF1.bringToFront()


or try
Code:

UDF1.FormStyle='fsSystemStayOnTop'


also, UDF1.Handle gets you the handle, no need to findWindow

_________________
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 16, 2020 11:59 am    Post subject: Reply with quote

Dark Byte wrote:
try
Code:

UDF1.bringToFront()


or try
Code:

UDF1.FormStyle='fsSystemStayOnTop'


also, UDF1.Handle gets you the handle, no need to findWindow



From this all works only
Code:

function UDF1_CETimer1Timer(sender)
UDF1.FormStyle='fsSystemStayOnTop'
end

But the focus is still on the game window and the mouse cursor is still captured
I thought SetForegroundWindow would switch to the trainer form and make a free cursor, but it not work for me.

***********************************************************
Just tested on CE 6.8.3 this script
Code:
x=findWindow(nil,'UDF1')
executeCodeLocalEx('LockSetForegroundWindow',x)


Works perfectly and the effect is as from
Code:

UDF1.FormStyle='fsSystemStayOnTop'

But focus and cursor still on game window.
Is this a normal effect? Maybe the game shouldn't make the cursor free.
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