Control handles via drag event ?
-
I want to write a program that will allow me to populate TextBox controls on other unknown applications from a Drag/Drop type event. Exmaple: I open a Web page or other Dialog program that contains a TextBox, I would like to drag an Icon from my program over the target TextBox and fill the target TextBox with my own data. Somthing similar was done in the password hacking Reveal program way way back, but rather than revealing passwords, I want to send data to the targeted Control. How do I get/send information from the target control ? Can I use the Drag/Drop event to get the window name, then get the control handle from the window name somehow? Any ideas out there ?
-
I want to write a program that will allow me to populate TextBox controls on other unknown applications from a Drag/Drop type event. Exmaple: I open a Web page or other Dialog program that contains a TextBox, I would like to drag an Icon from my program over the target TextBox and fill the target TextBox with my own data. Somthing similar was done in the password hacking Reveal program way way back, but rather than revealing passwords, I want to send data to the targeted Control. How do I get/send information from the target control ? Can I use the Drag/Drop event to get the window name, then get the control handle from the window name somehow? Any ideas out there ?
If you want to paste data into a textbox, you will need to get the handle to the window (i.e., textbox) you want to access and then send the appropriate message. I did something similar the other day in C++ with Outlook so I can get the count of the items within the Outlook address book. Here is an example of what I did:
HWND hwnd; CString text, msg; text = "Address Book"; hwnd = ::FindWindow(NULL, text); if(hwnd != NULL) { HWND hwnd2; hwnd2 = ::FindWindowEx(hwnd, NULL, "OUTEXVLB", NULL); if(hwnd2 != NULL) { LRESULT num; num = ::SendMessage(hwnd2, LB\_GETCOUNT, (WPARAM)0, (LPARAM)0); if(num == 1) msg.Format("Results: %i entry.", num); else if(num > 1) msg.Format("Results: %i entries.", num); else msg.Format("Results: No results."); SetDlgItemText(IDC\_Results, msg); } else { msg.Format("Results: No results."); SetDlgItemText(IDC\_Results, msg); } } else { msg.Format("No results."); SetDlgItemText(IDC\_Results, msg); }
- Nick Parker
My Blog | My Articles -
If you want to paste data into a textbox, you will need to get the handle to the window (i.e., textbox) you want to access and then send the appropriate message. I did something similar the other day in C++ with Outlook so I can get the count of the items within the Outlook address book. Here is an example of what I did:
HWND hwnd; CString text, msg; text = "Address Book"; hwnd = ::FindWindow(NULL, text); if(hwnd != NULL) { HWND hwnd2; hwnd2 = ::FindWindowEx(hwnd, NULL, "OUTEXVLB", NULL); if(hwnd2 != NULL) { LRESULT num; num = ::SendMessage(hwnd2, LB\_GETCOUNT, (WPARAM)0, (LPARAM)0); if(num == 1) msg.Format("Results: %i entry.", num); else if(num > 1) msg.Format("Results: %i entries.", num); else msg.Format("Results: No results."); SetDlgItemText(IDC\_Results, msg); } else { msg.Format("Results: No results."); SetDlgItemText(IDC\_Results, msg); } } else { msg.Format("No results."); SetDlgItemText(IDC\_Results, msg); }
- Nick Parker
My Blog | My ArticlesFor this methodology, I assume you got the control name ("OUTEXVLB") via spy++ ? I'm looking to get the handle for any TextBox based on the location of the mouse.
-
For this methodology, I assume you got the control name ("OUTEXVLB") via spy++ ? I'm looking to get the handle for any TextBox based on the location of the mouse.
Guinness4Strength wrote: For this methodology, I assume you got the control name ("OUTEXVLB") via spy++ ? Correct, it's actually the registered class name. You might look at Raymond Chen's post How to retrieve text under the cursor (mouse pointer)[^] as a starting concept for what you want to do. - Nick Parker
My Blog | My Articles -
I want to write a program that will allow me to populate TextBox controls on other unknown applications from a Drag/Drop type event. Exmaple: I open a Web page or other Dialog program that contains a TextBox, I would like to drag an Icon from my program over the target TextBox and fill the target TextBox with my own data. Somthing similar was done in the password hacking Reveal program way way back, but rather than revealing passwords, I want to send data to the targeted Control. How do I get/send information from the target control ? Can I use the Drag/Drop event to get the window name, then get the control handle from the window name somehow? Any ideas out there ?
Start with looking up the documentation for
Control.DoDragDrop()
. The complicated part is detecting the start of a Drag-Drop-Operation; you probably already have that. OTOH, the simple part is providing string data for the operation.private void sourceControl_MouseMove(object sender, MouseEventArgs e)
{
/*
code to detect dragging
...
*/// start the drag-drop operation sourceControl.DoDragDrop(someText, DragDropEffects.Copy | DragDropEffects.Move);
}
That's it! You drag something, and drop it over *any* Textbox/RTF-Box (Explorer, Word(pad)...).