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. Grab Text From Other Window

Grab Text From Other Window

Scheduled Pinned Locked Moved C#
csharpdotnetjsontutorial
3 Posts 2 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.
  • A Offline
    A Offline
    Afief
    wrote on last edited by
    #1

    Hi all, I'm making a little dictionary program in C# for experimenting purposes. everything is coming along fine except how to select the word that is currently under the mouse when the user presses. in VB6 it was done through an API as i remember, but i don't recall which, but this shold be a .net framework program, so better without any win32 api Thanks in advance

    M 1 Reply Last reply
    0
    • A Afief

      Hi all, I'm making a little dictionary program in C# for experimenting purposes. everything is coming along fine except how to select the word that is currently under the mouse when the user presses. in VB6 it was done through an API as i remember, but i don't recall which, but this shold be a .net framework program, so better without any win32 api Thanks in advance

      M Offline
      M Offline
      Mohamad Al Husseiny
      wrote on last edited by
      #2

      If You use RichTextBox you can use GetCharIndexFromPosition to get the word this simple example

      private string GetWordFromPos(Point p)
      {
      	string word;
      	int cIdx=richTextBox1.GetCharIndexFromPosition(p);
      	//go left
      	int startPos;
      	for(startPos=cIdx;startPos>0;startPos--)
      	{
      		string c=richTextBox1.Text.Substring(startPos-1,1);
      		if(c == " ") // add more seperator check here
      			break;
      	}
      	//get the left part
      	word=richTextBox1.Text.Substring(startPos,cIdx-startPos);
      	//go right
      	for(startPos=cIdx;startPos
      

      If you use `TextBox` then `TextBox` didn't have equivalent method or as i know so you need to use `SendMessage` Windows API to Function to send `EM_CHARFROMPOS` to get the index of the Char and Modify the previous function to take to get the text for more inf o look at [EM_CHARFROMPOS Message](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/editcontrols/editcontrolreference/editcontrolmessages/em_charfrompos.asp) [[^](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/editcontrols/editcontrolreference/editcontrolmessages/em_charfrompos.asp "New Window")] MCAD -- modified at 22:30 Tuesday 13th September, 2005

      A 1 Reply Last reply
      0
      • M Mohamad Al Husseiny

        If You use RichTextBox you can use GetCharIndexFromPosition to get the word this simple example

        private string GetWordFromPos(Point p)
        {
        	string word;
        	int cIdx=richTextBox1.GetCharIndexFromPosition(p);
        	//go left
        	int startPos;
        	for(startPos=cIdx;startPos>0;startPos--)
        	{
        		string c=richTextBox1.Text.Substring(startPos-1,1);
        		if(c == " ") // add more seperator check here
        			break;
        	}
        	//get the left part
        	word=richTextBox1.Text.Substring(startPos,cIdx-startPos);
        	//go right
        	for(startPos=cIdx;startPos
        

        If you use `TextBox` then `TextBox` didn't have equivalent method or as i know so you need to use `SendMessage` Windows API to Function to send `EM_CHARFROMPOS` to get the index of the Char and Modify the previous function to take to get the text for more inf o look at [EM_CHARFROMPOS Message](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/editcontrols/editcontrolreference/editcontrolmessages/em_charfrompos.asp) [[^](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/editcontrols/editcontrolreference/editcontrolmessages/em_charfrompos.asp "New Window")] MCAD -- modified at 22:30 Tuesday 13th September, 2005

        A Offline
        A Offline
        Afief
        wrote on last edited by
        #3

        The problem is, I want to use this function on the text in other windows, not in my program. and i can't be sure if it'll be a rich textbox, textbox, label or any other control that will be read. I read the "EM_CHARFROMPOS Message" but it makes little sense to me. high word, low word... it all doesn't sound the c# level. was that in the C++ time?

        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