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 


Imitating Button press c++

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
muji8u
Cheater
Reputation: 0

Joined: 04 Jul 2007
Posts: 40

PostPosted: Sat Jan 03, 2009 7:48 am    Post subject: Imitating Button press c++ Reply with quote

Hi all,
I am trying to imitate pushing a button in c++. so far i have this:
Code:

BOOL CALLBACK FindButttonPush(HWND hWnd, LPARAM lParam)
{
   if(GetDlgCtrlID(hWnd) == 1000)
    {
      *(HWND *)lParam = hWnd;
      return FALSE;
   }
   return TRUE;
}

int click()
{
    int i;
    HWND hWndManager, hWndClick = NULL;
    hWndManager = FindWindow("SWBF2SERVERMANAGER", NULL);
    if(!hWndManager)
    return 0;
    EnumChildWindows(hWndManager, FindButttonPush, (LPARAM)&hWndClick);
   if(!hWndClick)
    return 0;
   SendMessage(hWndClick, BM_CLICK,0,0);
    return 1;
}

int main()
{
   
   
std::cout << click();
   

}




The code compiles fine but it doesn't do what it is suppose to do. The reason why i am using the enumerate is because the button is in a pan and not directly on the window.

p.s i also tried this with calc.exe but it still didn't work Confused

Any help here would be greatly appreciated.
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sat Jan 03, 2009 8:43 am    Post subject: Re: Imitating Button press c++ Reply with quote

I personally never use BM_CLICK message to handle my button controls. Why not send WM_COMMAND with the wParam the handle of the button?
_________________
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Jan 03, 2009 11:52 am    Post subject: Reply with quote

Send WM_KEYDOWN/WM_KEYUP?

wParam being the Key you want to imitate
lParam can be 0

If you want a mouse click

WM_LBUTTONDOWN/WM_LBUTTONUP

_________________
Back to top
View user's profile Send private message
muji8u
Cheater
Reputation: 0

Joined: 04 Jul 2007
Posts: 40

PostPosted: Sat Jan 03, 2009 12:40 pm    Post subject: Reply with quote

i thought this would take care of both of those.

Quote:
Simulates the user clicking a button. This message causes the button to receive the WM_LBUTTONDOWN and WM_LBUTTONUP messages, and the button's parent window to receive a BN_CLICKED notification message.


I thought there was something conceptually wrong with my code. are you sure its the BM_CLICK that causes the problem?
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sat Jan 03, 2009 3:02 pm    Post subject: Reply with quote

I might be wrong but, in your main function, it looks like you are telling it to print "click()" on the screen, not actually go to the "click()" function. But idk im not so good with c++
_________________
Back to top
View user's profile Send private message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Sat Jan 03, 2009 4:26 pm    Post subject: Reply with quote

Code:
if(GetDlgCtrlID(hWnd) == 0x83) // Button 7

Code:
hWndManager = FindWindow("SciCalc", NULL);

Works fine on Calc with these changes. Make sure your Control ID is correct, the values from Spy++ are in hex.

MSDN wrote:
If the button is in a dialog box and the dialog box is not active, the BM_CLICK message might fail. To ensure success in this situation, call the SetActiveWindow function to activate the dialog box before sending the BM_CLICK message to the button.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Jan 03, 2009 10:51 pm    Post subject: Reply with quote

manc wrote:
I might be wrong but, in your main function, it looks like you are telling it to print "click()" on the screen, not actually go to the "click()" function. But idk im not so good with c++


It will print the return of the function click.

It calls the function to get the return.

_________________
Back to top
View user's profile Send private message
muji8u
Cheater
Reputation: 0

Joined: 04 Jul 2007
Posts: 40

PostPosted: Sun Jan 04, 2009 11:06 am    Post subject: Reply with quote

ok so i narrowed it down. there is nothing wrong with my code. it works with all buttons around that one button. Any guesses why this is?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming 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