I've got some VB code (below) which I'll convert to C#. However, it just gives me the window name and nothing else.
Is it possible for user32.dll (or some other library) to be utilised, which will allow me to see the controls on the screen - so I can read the text associated with specific controls?
Thanks for any suggestions,
Mark
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Security
Imports System.Security.Principal.WindowsIdentity
Public Class Form1
Private Shared Function GetForegroundWindow() As Integer
End Function
Private Shared Function GetWindowText(ByVal hWnd As Integer, ByVal text As StringBuilder, ByVal count As Integer) As Integer
End Function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
GetActiveWindow()
End Sub
Dim curtime As DateTime
Private Sub GetActiveWindow()
Const nChars As Integer = 256
Dim handle As Integer = 0
Dim Buff As New StringBuilder(nChars)
handle = GetForegroundWindow()
Dim winname As String = ""
If GetWindowText(handle, Buff, nChars) > 0 Then
Me.richtextbox1.Text = Buff.ToString()
Me.RichTextBox2.Text = handle.ToString()
End If
End Sub
Public Sub New()
InitializeComponent()
curtime = DateTime.Now
End Sub
End Class
MarkPosted Aug 13, 2009, 3:50 PM
Master BillaPosted Aug 13, 2009, 4:06 AM
i will post full code again here.
thank you
MarkPosted Aug 13, 2009, 3:44 AM
Are you able to give me any guidance on what function to use in the DLL?
Thanks, Mark
Master BillaPosted Aug 12, 2009, 10:19 PM
thank you
MarkPosted Aug 12, 2009, 1:32 PM
Master BillaPosted Aug 12, 2009, 12:07 PM
Yes your vb.net code is correct, here C# code to that
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Principal.WindowsIdentity;
public class Form1
{
[DllImport("user32.dll")]
private static extern int GetForegroundWindow();
[DllImport("user32.dll")]
private static extern int GetWindowText(int hWnd, StringBuilder text, int count);
private void Timer1_Tick(System.Object sender, System.EventArgs e)
{
GetActiveWindow();
}
DateTime curtime;
private void GetActiveWindow()
{
const int nChars = 256;
int handle = 0;
StringBuilder Buff = new StringBuilder(nChars);
handle = GetForegroundWindow();
string winname = "";
if (GetWindowText(handle, Buff, nChars) > 0)
{
this.richtextbox1.Text = Buff.ToString();
this.RichTextBox2.Text = handle.ToString();
}
}
public Form1()
{
InitializeComponent();
curtime = DateTime.Now;
}
}
Thank you