Click here to Skip to main content
15,887,596 members
Home / Discussions / C#
   

C#

 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Luc Pattyn31-May-11 2:55
sitebuilderLuc Pattyn31-May-11 2:55 
GeneralRe: RectanlgeF.Parse(string s) extension method? Pin
BobJanova31-May-11 3:04
BobJanova31-May-11 3:04 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Luc Pattyn31-May-11 4:00
sitebuilderLuc Pattyn31-May-11 4:00 
GeneralRe: RectanlgeF.Parse(string s) extension method? Pin
BobJanova31-May-11 23:09
BobJanova31-May-11 23:09 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Luc Pattyn1-Jun-11 0:17
sitebuilderLuc Pattyn1-Jun-11 0:17 
AnswerRe: RectanlgeF.Parse(string s) extension method? Pin
Shameel31-May-11 3:05
professionalShameel31-May-11 3:05 
GeneralRe: RectanlgeF.Parse(string s) extension method? Pin
Pete O'Hanlon31-May-11 3:39
mvePete O'Hanlon31-May-11 3:39 
QuestionClicking a button with SendMessage [modified] Pin
musefan30-May-11 23:36
musefan30-May-11 23:36 
Hi All,

I am trying to simulate a button click using the SendMessage function of the Win32API. My application is C# WinForms .net 4.0 (the application performing the automation)

EDIT: The application I am trying to automate is not of my own work and I have no control over source code in any way.

First of all I am using FindWindow to get the handle to the window I want, I know this is working as the value of the handle is correct (as found using Spy++)

Next I am getting the handle of the child control (the button I want to click), again I know I am getting the correct value here.

Then I use SetActiveWindow() and pass in the window handle (which appears to work fine)

Then I use SendMessage() to simulate a mouse left button down and a mouse left button up. For now I just want to simulate the "Cancel" button for testing, which when clicked manually will simply close the form. My code however does nothing, the thing that is annoying me thou is that the "Cancel" button actually gets focus (just like it would if it had been clicked manually) but no action is taken.

Does anybody know why this could be happening? Is it possible that the application is question could be detecting I am using the SendMessage function and deciding not to process the relevant code? sort of like a "prevent automation" feature.

Thanks for any help, and the relevant code for SendMessage is as follows (also note, I have tried PostMessage too)

[DllImport("user32.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

uint WM_LBUTTONDOWN = 0x0201;
uint WM_LBUTTONUP = 0x0202;
uint BM_SETSTATE = 0x00F3;
uint BN_CLICKED = 245;

void Function()
{
     //Code to get handles here

     //I have tried all variations of the following (so with some commented etc.)
     SendMessage(hwndButton, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
     SendMessage(hwndButton, WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero);
     SendMessage(hwndButton, BM_SETSTATE, IntPtr.Zero, IntPtr.Zero);
     SendMessage(hwndButton, BN_CLICKED, IntPtr.Zero, IntPtr.Zero);
}

I may or may not be responsible for my own actions
modified on Tuesday, May 31, 2011 11:59 AM

AnswerRe: Clicking a button with SendMessage Pin
Shameel31-May-11 0:15
professionalShameel31-May-11 0:15 
GeneralRe: Clicking a button with SendMessage Pin
musefan31-May-11 0:42
musefan31-May-11 0:42 
GeneralRe: Clicking a button with SendMessage Pin
Shameel31-May-11 0:55
professionalShameel31-May-11 0:55 
GeneralRe: Clicking a button with SendMessage Pin
Shameel31-May-11 0:58
professionalShameel31-May-11 0:58 
GeneralRe: Clicking a button with SendMessage Pin
musefan31-May-11 2:22
musefan31-May-11 2:22 
AnswerRe: Clicking a button with SendMessage Pin
Pete O'Hanlon31-May-11 2:43
mvePete O'Hanlon31-May-11 2:43 
GeneralRe: Clicking a button with SendMessage Pin
musefan31-May-11 5:59
musefan31-May-11 5:59 
AnswerRe: Clicking a button with SendMessage Pin
_Erik_1-Jun-11 4:20
_Erik_1-Jun-11 4:20 
QuestionRectangleF to and back from string? Pin
Chesnokov Yuriy30-May-11 22:49
professionalChesnokov Yuriy30-May-11 22:49 
AnswerRe: RectangleF to and back from string? Pin
Richard MacCutchan30-May-11 23:30
mveRichard MacCutchan30-May-11 23:30 
AnswerRe: RectangleF to and back from string? Pin
Pete O'Hanlon31-May-11 0:32
mvePete O'Hanlon31-May-11 0:32 
QuestionRe: RectangleF to and back from string? Pin
Chesnokov Yuriy31-May-11 0:45
professionalChesnokov Yuriy31-May-11 0:45 
AnswerRe: RectangleF to and back from string? Pin
Pete O'Hanlon31-May-11 1:27
mvePete O'Hanlon31-May-11 1:27 
AnswerRe: RectangleF to and back from string? Pin
Chesnokov Yuriy31-May-11 1:54
professionalChesnokov Yuriy31-May-11 1:54 
GeneralRe: RectangleF to and back from string? Pin
Pete O'Hanlon31-May-11 2:36
mvePete O'Hanlon31-May-11 2:36 
AnswerRe: RectangleF to and back from string? [modified] Pin
DaveyM691-Jun-11 0:35
professionalDaveyM691-Jun-11 0:35 
QuestionSerialcomm dialing voice over modem Pin
Chuck Richards30-May-11 11:17
Chuck Richards30-May-11 11:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.