| View previous topic :: View next topic |
| Author |
Message |
muji8u Cheater
Reputation: 0
Joined: 04 Jul 2007 Posts: 40
|
Posted: Sat Jan 03, 2009 7:48 am Post subject: Imitating Button press c++ |
|
|
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
Any help here would be greatly appreciated.
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sat Jan 03, 2009 8:43 am Post subject: Re: Imitating Button press c++ |
|
|
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 |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Jan 03, 2009 11:52 am Post subject: |
|
|
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 |
|
 |
muji8u Cheater
Reputation: 0
Joined: 04 Jul 2007 Posts: 40
|
Posted: Sat Jan 03, 2009 12:40 pm Post subject: |
|
|
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 |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sat Jan 03, 2009 3:02 pm Post subject: |
|
|
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 |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
Posted: Sat Jan 03, 2009 4:26 pm Post subject: |
|
|
| 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 |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Jan 03, 2009 10:51 pm Post subject: |
|
|
| 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 |
|
 |
muji8u Cheater
Reputation: 0
Joined: 04 Jul 2007 Posts: 40
|
Posted: Sun Jan 04, 2009 11:06 am Post subject: |
|
|
| 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 |
|
 |
|