C # Implementation View text box (e.g., * Password box)

Source: Internet
Author: User
Tags modifiers
The text box is idle today, try to write the program in C # to view the Password box (not limited to the password box, should be any text control can be)
code see below.
With C + + to achieve a super simple such dongdong. With C # is very complex, I do not want to use unsafe, I always think with unsafe words, why not simply use C + +.

int length=300;
INTPTR Thandle=apis.getlocalwindow ()//Get the control handle where the current mouse is located
int Address=apis.virtualallocex (process.getcurrentprocess (). HANDLE,0,LENGTH,0X1000,0X04);//Allocate Length of memory within this process
Apis.sendmessage (thandle,0x000d,new IntPtr (255), New INTPTR (address))//Send message to target control, 0x000d is Wm_gettext, 255 means to save the returned value, and new IntPtr (address)
Byte[] Buf=new byte[length];
Apis.readprocessmemory (Process.getcurrentprocess (). handle,address,buf,length,0);/Read what you just saved
MessageBox.Show (Encoding.Default.GetString (BUF))//show out to test.

Where the APIs begin with, I write my own API class library, the relevant statement is as follows:
[DllImport ("user32.dll")]
public static extern IntPtr Windowfrompoint (
Point Lppoint
);

[DllImport ("user32.dll")]
public static extern int GetCursorPos (
Out Point Lppoint
);
public static INTPTR Getlocalwindow ()//This just combined the last two.
{
Point Point;
GetCursorPos (out point);
Return Windowfrompoint (point);
}

Without ex. There's no need for the first handle parameter.
[DllImport ("Kernel32.dll")]
public static extern System.Int32 VirtualAllocEx (
System.IntPtr hprocess,
System.Int32 lpaddress,
System.Int32 dwsize,
System.Int16 Flallocationtype,
System.Int16 Flprotect
);

[DllImport ("User32.dll")]
public static extern IntPtr SendMessage (
IntPtr HWnd,
int MSG,
IntPtr WParam,
IntPtr LParam
);

[DllImport ("Kernel32.dll")]
public static extern int ReadProcessMemory (
System.IntPtr hprocess,
System.Int32 Lpbaseaddress,
Byte[] lpbuffer,
Long Nsize,
Long Lpnumberofbyteswritten
);


*******************************************************************
Because the general to see is the external program, with shortcut key without losing a good method.
The implementation of C # is as follows:
Add the code in the initialization window
Keymodifiers modifiers=keymodifiers.windows;//is defined as a win+ shortcut key, or it can be defined as something else.
RegisterHotKey (Handle, 1001,MODIFIERS,KEYS.V)//Assign ID 1001 to Win+v

Override a little bit WndProc
protected override void WndProc (ref message M)
{
const int wm_hotkey = 0x0312;
Switch (m.msg)
{
Case Wm_hotkey:
Switch (M.wparam.toint32 ())
{
Case 1001:
Onhotkeyv ();
Break
Default:break;
}
Break
}
Base. WndProc (ref m);
}
In the ONHOTKEYV function, write the code that I wrote the first time.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.