amitjul

Hi everybody

For some time I have been working on an UI testing application. The application under test was developed in C#, and my application has been developed in C# as well. I do not have a source code of the application under test, so I use Win API messages and methods. I faced the following problem:

The application under test contains a check box:

Class: WindowsForms10.BUTTON
Text: "Some text"
Style: "Some styles"

After I get a handle to the check box ( I am sure I have the correct handle ) I use SendMessage to retrieve the check box state:

ivate const int BM_GETSTATE    = 0x00F2;
private const int BM_GETCHECK    = 0x00F0;
private const int BST_UNCHECKED   = 0x0000;
private const int BST_CHECKED    = 0x0001;

int result;

result = SendMessage(correctHandle, BM_GETSTATE, 0, 0);

or

result = SendMessage(correctHandle, BM_GETCHECK, 0, 0);

My problem is that both SendMessage methods from above always return 0, even if a check box is checked.

Can anybody tell me what is wrong with the code above or is there any other method to get the state and check state of checkbox/radiobutton/button

Thanks in advance.




Re: Visual C# General My problem is related with handling an application by Win API

Peter Ritchie

Are you running under Vista




Re: Visual C# General My problem is related with handling an application by Win API

amitjul

No its Windows XP service pack 2.




Re: Visual C# General My problem is related with handling an application by Win API

amitjul

Please somebody help me...I tried googling by each and every way but i didnt find the perfect solution for that...

(I am trying to develop an application in C#.Net 2003 using API's, which test UI of an already developed application in C#.Net 2003. In Win XP service pack 2)






Re: Visual C# General My problem is related with handling an application by Win API

Martin Xie - MSFT

You can use Spy++ to find window control information.

In System.Windows.Forms namespace in the .NET Framework, there is no class similar to the MessageWindow class as in the Compact Framework. You will need to use p/invoke to call FindWindow to retrieve the window handle then call SendMessage to send the message to it.


Here is just one sample that maybe give you inspiration. when you click on the button on the form, it will send a WM_CLOSE message to your window.

Code Snippet
namespace InputForms
{

public partial class Form1 : Form
{
[DllImport("user32.dll")]private static extern int
SendMessage (int hWnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll",CharSet = CharSet.Auto)]public static extern int FindWindow(string strclassName, string strWindowName);
private const int WM_CLOSE = 0x0010;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int hwnd = FindWindow(null, "TestSendMessage2 - TestSendMessage1");
int result2 =
SendMessage(hwnd, WM_CLOSE, 0, 0);
}

}
}





Re: Visual C# General My problem is related with handling an application by Win API

amitjul

Hi Martin Xie,

Thanks for spending some time for me..but i'm facing the issue specifically with Checkbox status. Before marking it as true or false, i want to know it present status whether its already checked or not . and i already attached one sample code in first question which is not working. WM_CLOSE is working for me.

Thanks in advance.






Re: Visual C# General My problem is related with handling an application by Win API

Martin Xie - MSFT

Look like you have used p/invoke correctly.

SendMessage method can return value, which means that the method has worked correctly.

Please check out the Macro definition of 0x00F2 and 0x00F0, and figure out which messages they stand for.

Thanks!






Re: Visual C# General My problem is related with handling an application by Win API

amitjul

I checked it. Its correct. I saw almost everyone who's working with C# are not able to get/set status using the above code. There is some not acceptable code (for C# language) in that snippet of code.. weird thing is, its working for all other languages other than C#... Can any body help me. Where exctaly it went wrong




Re: Visual C# General My problem is related with handling an application by Win API

lemmyum

What other languages do you have in mind VB.NET, for example

Anyway, I've tried to simulate your problem and couldn't get the state either. I tried sending BM_SETSTATE/BM_SETCHECK but there was no difference. Message was sent (as detected in Spy++), but the state was allways set to UNCHECKED, when BM_GETCHECK/BM_GETSTATE was sent.