Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Control handles via drag event ?

Control handles via drag event ?

Scheduled Pinned Locked Moved C#
question
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Guinness4Strength
    wrote on last edited by
    #1

    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 ?

    N S 2 Replies Last reply
    0
    • G Guinness4Strength

      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 ?

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      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

      G 1 Reply Last reply
      0
      • N Nick Parker

        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

        G Offline
        G Offline
        Guinness4Strength
        wrote on last edited by
        #3

        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.

        N 1 Reply Last reply
        0
        • G Guinness4Strength

          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.

          N Offline
          N Offline
          Nick Parker
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • G Guinness4Strength

            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 ?

            S Offline
            S Offline
            StealthyMark
            wrote on last edited by
            #5

            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)...).

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups