SendMessage BN_CLICKED

chidambaram

Well-known member
Joined
Dec 27, 2007
Messages
62
Location
Chennai,India
Programming Experience
Beginner
hi sir,

I got the code suitable for this in c#.

That code is

int hwnd=0;
IntPtr hwndChild=IntPtr.Zero;

//Get a handle for the Calculator Application main window
hwnd=FindWindow(null,"Calculator");
if(hwnd == 0)
{
if(MessageBox.Show("Couldn't find the calculator" +
" application. Do you want to start it?",
"TestWinAPI",
MessageBoxButtons.YesNo)== DialogResult.Yes)
{
System.Diagnostics.Process.Start("Calc");
}
}
else
{

//Get a handle for the "1" button
hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","1");

//send BN_CLICKED message
SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero);

//Get a handle for the "+" button
hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","+");

//send BN_CLICKED message
SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero);

//Get a handle for the "2" button
hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","2");

//send BN_CLICKED message
SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero);

//Get a handle for the "=" button
hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","=");

//send BN_CLICKED message
SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero);

}

How can i change this code suitable for me sir. I know little bit only about Findwindow.

Here they did not give the declaration part.

How can i use this code?
 
Here is a translation of the c# code. Gotten from http://www.dotnetspider.com/Convert/Csharp-To-Vb.aspx

VB.NET:
Dim hwnd As Integer = 0 
Dim hwndChild As IntPtr = IntPtr.Zero 
 
'Get a handle for the Calculator Application main window
hwnd=FindWindow(Nothing,"Calculator")
If hwnd = 0 Then
If 
if(MessageBox.Show("Couldn't find the calculator" + Then
System.Diagnostics.Process.Start("Calc")
End If
Else 
 
'Get a handle for the "1" button
hwndChild = FindWindowEx(CType(hwnd,IntPtr.Zero,"Button","1", IntPtr))
 
'send BN_CLICKED message
SendMessage(CType(hwndChild,BN_CLICKED,0,IntPtr.Zer o, Integer))
 
'Get a handle for the "+" button
hwndChild = FindWindowEx(CType(hwnd,IntPtr.Zero,"Button","+", IntPtr))
 
'send BN_CLICKED message
SendMessage(CType(hwndChild,BN_CLICKED,0,IntPtr.Zer o, Integer))
 
'Get a handle for the "2" button
hwndChild = FindWindowEx(CType(hwnd,IntPtr.Zero,"Button","2", IntPtr))
 
'send BN_CLICKED message
SendMessage(CType(hwndChild,BN_CLICKED,0,IntPtr.Zer o, Integer))
 
'Get a handle for the "=" button
hwndChild = FindWindowEx(CType(hwnd,IntPtr.Zero,"Button","=", IntPtr))
 
'send BN_CLICKED message
SendMessage(CType(hwndChild,BN_CLICKED,0,IntPtr.Zer o, Integer))
 
End If

'----------------------------------------------------------------
' Converted from C# to VB .NET using CSharpToVBConverter(1.2).
' Developed by: Kamal Patel (http://www.KamalPatel.net) 
'----------------------------------------------------------------
 
Back
Top