How to get the password in the edit box

zhaozj2021-02-16  44

How to get the password edit box Author: Li Andong May 25, 2002 in a number of shareware, there is a relatively small stuff and we may be interested in - "Get password edit box." In fact, its implementation mechanism is simple, and the text in any window is not essentially different. But to get the password in the edit box in another thread, it is a bit troublesome, how is the key to get the handle of the edit box. Here are two ways to refer to friends who are interested in friends. The first method: The key to obtaining this method of mouse fingering method is to obtain the handle of the window pointed to by the current mouse pointer. To get the location of the current mouse pointer using the System Function :: getCursorpos (& POINT), see the function of the Cursor in the MSDN. The implementation steps are as follows: 1. Create a timer (interval 2 second) in the dialog, and do the following: 2, call the system function in the ONTIMER (Uint NidEvent) function :: getcursorpos (& point); 3 Call CWnd :: WindowFromPoint (POINT) Get the pointer W (type CWnd *) of the target window; 5, call the w-> getsafehwnd () get the handle HWnd of the window; 6, call: getclassname () Get the window Class name, determine if its class name is "edit". Call: getWindowlong (hwnd, gwl_style) Determine if its window style is ES_PASSWORD to determine if it is a password; 7, call: SendMessage ((hwnd) hwnd, // handle to destination window wm_gettext, // message to send (WPARAM 55, // Number of Characters to Copy (LPARAM) Sname // Text Buffer; Get the text (password) in the Target window (edit box). Note: Use :: getWindowText () to get the text in the edit box in another thread, you must use SendMessage (). And in vibestate use of SendMessage () or :: getWindowText () is Other Types of Types. The following example features the text (or password) in the window pointed to by the pointer as the mouse pointer is automatically acquired, and the debugged pass.

Void cgetssdlg :: ONTIMER (uint nidEvent) {cpoint point ;: :: getCursorpos (& point); cWnd * w = cwnd :: WindowFromPoint (Point); char SNAME [60]; hwnd hwnd = null; if (w! = null) HWND = W-> getSafehWnd (); if (hwnd! = null) {:: getclassname (hwnd, sname, 55); cstract str (sname); m_strprompt = "This is not a password! (: - <"; if (STR) == "Edit" &&: getWindowlong (hwnd, gwl_style) & es_password) m_strprompt = "Haha, password is found! (:-)"; :: SendMessage ((hwnd) hwnd, // handle to destination window WM_GETTEXT, / /// Number of Characters to copy (lparam) sname // text buffer; m_static_pass = sname;} Updatedata (false); cdialog :: Ontimer (nidevent);}

Second Method: The key to obtaining an input focus method is to obtain a handle of a window with a keyboard input focus: 1. Create a timer (interval 2 seconds) in the dialog box, and do the following operations in the ONTIMER function: 2. If in Windows 95, you can use :: getForeGroup () to get the window handle of the user's current work; 3, call: getWindowThreadProcessID (HWND, NULL) Get the identity of the thread to which the window belongs; 4, call :: getCurrentThreadID () Get the identity of the current thread; 4, call: attachthreadInput () Associate your thread with another thread. According to my feelings in this function call, the two thread identifiers in the parameter table don't matter; 5, call :: getFocus () function to get the current window handle with keyboard input focus; 6, call: : GetClassName () Get the class name of the window to determine if its class name is "Edit". Call: getWindowlong (hwnd, gwl_style) To determine if its window style is ES_PASSWORD to determine if it is a password; 7, if the window class name is "edit", call: SendMessage ((hwnd) hwnd, // handle to Destination Window WM_Gettext, // Message To Send (WPARAM) 55, // Number of Characters To Copy (LPARAM) SNAME // TEXT BUFFER; 8, Call: AttachThReadInput () Unpacking your thread with another thread. If you use :: getGuithReadInfo () to get information on the current active window in the system, such as: thread state, active window handle, window handle with keyboard input focus, currently captured The window handle of the mouse is input, the handle of the window of the active menu, the window handle of the current display, etc. Note: When using this function, you must include Winable.h files, and "#include " instructions should not be placed in stdafx..i, and should be placed directly in the corresponding C file. The sample code is longer, omitted here, see the Appendix section below. Summarizing the above-mentioned methods is characterized by short and delicious, only more than 20 KBs, if you need a friend, please contact. I think the first is better because it is simple. The second method is used in other programs that may be more useful. If you have any good ideas, you may wish to contribute to everyone to share. Appendix: Below is an example code of the ONTIMER function in the second method (Pass): void cgetpassdlg :: ONTIMER (uint nidevent) {char Sname [60] = {0};

// WHEN Used for Windows 98 or Later Environment: #ifdef in_win98_system guithreadinfo info; info.cbsize = sizeof (info);

Bool BL = :: getGuithreadInfo (0, & info); if (bl && info.hwndfocus! = Null) {:: getClassName (Info.hwndfocus, sname, 55); cstring str (sname); m_strPrompt = "This is not a password! (: - <"; if (str ==" edit "&& :: getWindowlong (info.hwndfocus, gwl_style) & es_password) m_strprompt =" Haha, password is found! :-) ";: SendMessage ((hwnd) info .hwndfocus, // Handle to destination window wm_gettext, // message to send (wparam) 55, // Numr of character of character t p; m_static_pass = sname;} #else // used for windows 95 environment: DWORD curID, wID; HWND hWnd = :: GetForegroundWindow (); if (hWnd = NULL!) {curID = :: GetCurrentThreadId (); wID = :: GetWindowThreadProcessId (hWnd, NULL); :: AttachThreadInput (wID , // thread to attach curid, // thread to attach to true // attach or detach; hwnd = :: getFocus (); if (hwnd! = Null) :: getClassName (hwnd, sname, 55); CString Str (SNAME); m_strprompt = "This is not a password!: - <"; if (str == "Edit" && :: getwind Owlong (hwnd, gwl_style) & es_password) m_strprompt = "Haha, password is found! :: SendMessage ((hwnd) hwnd, // handle to decination window wm_gettext, // message to send (wparam) 55, // number of character of character of characters to copy (lparam) Sname // text buffer; m_static_pass = Sname; :: attachthreadinput (wid, // thread to attach to false // attach or detach);} #ENDIF UPDATEDATA (FALSE);

CDIALOG :: ONTIMER (Nidevent);

转载请注明原文地址:https://www.9cbs.com/read-25801.html

New Post(0)