I was told that this piece coding to find the es_password state in c# would work but an error message saying hWnd does not exist in the current context
i had fixed up all these other errors but not this one.
if you have any slight of an idea please reply thanks
Code:
internal static class UnsafeNativeMethods
{
public const int GWL_STYLE = -16;
public const int ES_PASSWORD = 0x20;
[DllImport("user32.dll")]
public static extern int GetClassName(HandleRef hWnd, System.Text.StringBuilder lpClassName, int nMaxCount);
[DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)]
public static extern IntPtr GetWindowLong32(System.Runtime.InteropServices.HandleRef hWnd, int nIndex);
}
private void tmrpass_Tick(object sender, EventArgs e)
{
//start timer and espassword code
// root the handle so it doesn't get disposed until were done with it
Object root = new Object();
System.Runtime.InteropServices.HandleRef handleRef = new System.Runtime.InteropServices.HandleRef(root, hWnd);
System.Text.StringBuilder sb = new System.Text.StringBuilder(1024);
// get the class name of the window
UnsafeNativeMethods.GetClassName(new System.Runtime.InteropServices.HandleRef(root, hWnd), sb, sb.Capacity);
// is it an edit box?
if (sb.ToString() == "Edit" || sb.ToString().StartsWith("WindowsForms10.EDIT.app"))
{
// get the window style of the edit box
int style = UnsafeNativeMethods.GetWindowLong32(new System.Runtime.InteropServices.HandleRef(root, hWnd), UnsafeNativeMethods.GWL_STYLE).ToInt32();
// is it a password edit or not?
if ((style & UnsafeNativeMethods.ES_PASSWORD) == UnsafeNativeMethods.ES_PASSWORD)
{
lblkd.Text = "edit is password text box";
}
else
{
lblkd.Text = "edit is not password text box";
}
}
//stop timer and es password code
}
if you have any slight of an idea please reply thanks