Main Page | Report this Page
.NET DotNet Forum Index  »  VB.NET Forum (Visual Basic .NET)  »  How can I read selected text in another application,...
Page 1 of 2    Goto page 1, 2  Next

How can I read selected text in another application,...

Author Message
ptpwjp...
Posted: Sat Oct 31, 2009 9:59 am
Guest
How can I read selected text in another application, by vb program?

I want read from vb program
same text selected (for example by mouse) in another application (for
example IE, or Word ).
I want to have this text in any string variable, or in any file.
I don't know how many IE or Words or another applications will be opened.
Somebody can selected texts in several application,
in this situation I want to read only last selected text.
How to do it?
 
Family Tree Mike...
Posted: Sat Oct 31, 2009 10:33 am
Guest
ptpwjp wrote:
Quote:
How can I read selected text in another application, by vb program?

I want read from vb program
same text selected (for example by mouse) in another application (for
example IE, or Word ).
I want to have this text in any string variable, or in any file.
I don't know how many IE or Words or another applications will be opened.
Somebody can selected texts in several application,
in this situation I want to read only last selected text.
How to do it?




The newsgroups you have listed are mutually exclusive. Do you want a VB
6 recommendation, or a vb.net recommendation? The vb.general.discussion
group would be for a VB 6 question while the dotnet.languages.vb group
would be for .Net.

After deciding your platform, you need to clarify how this would work.
Do you want a user in your code to initiate a copy of the selected data
somehow? Do you want any selected text in any app captured by your app?

--
Mike
 
Nobody...
Posted: Sat Oct 31, 2009 10:47 am
Guest
You posted to two different groups that cover very different versions of VB.
The earlier versions(VB6 or lower) are not based on dotnet and they don't
have "dotnet" in the group name. The newer version are all based on dotnet
which started with VB 2002, and they have separate groups that either have
"dotnet" or "vsnet" in the group name.

There are many things broken between VB6(Released in 1998), and VB 2002+.
VB6 code almost always produce compilation errors in VB.Net, and may not
work as expected, and usually require a rewrite to make it work properly.

Please repost your question again and include what VB version you are using.

<Question ignored>
 
ptpwjp...
Posted: Sat Oct 31, 2009 11:19 am
Guest
Quote:
The newsgroups you have listed are mutually exclusive. Do you want a VB
6 recommendation, or a vb.net recommendation? The vb.general.discussion
group would be for a VB 6 question while the dotnet.languages.vb group
would be for .Net.
Visual Basic 2008 Express Edition



Quote:
After deciding your platform, you need to clarify how this would work. Do
you want a user in your code to initiate a copy of the selected data
somehow?
I want to transform text selected by user ,

(only if he will want to -only if he push bottom at my application),
and write new version of text to file.
 
Nobody...
Posted: Sat Oct 31, 2009 12:22 pm
Guest
"ptpwjp" <ptpwjp at (no spam) op.pl> wrote in message news:hchrkj$eec$1 at (no spam) news.onet.pl...
Quote:
Visual Basic 2008 Express Edition

Please repost your question in new thread, or remove
microsoft.public.vb.general.discussion from your reply.

Thank you
 
Family Tree Mike...
Posted: Sat Oct 31, 2009 1:45 pm
Guest
ptpwjp wrote:
Quote:
The newsgroups you have listed are mutually exclusive. Do you want a VB
6 recommendation, or a vb.net recommendation? The vb.general.discussion
group would be for a VB 6 question while the dotnet.languages.vb group
would be for .Net.
Visual Basic 2008 Express Edition


After deciding your platform, you need to clarify how this would work. Do
you want a user in your code to initiate a copy of the selected data
somehow?
I want to transform text selected by user ,
(only if he will want to -only if he push bottom at my application),
and write new version of text to file.




You are going to call:
SendMessage(hwndChild, Win32.User.EM_GETSELTEXT, 0, builder)

builder is a stringbuilder object to receive the text. hwndChild is the
hwnd to the control to copy the text. Look at
http://www.pinvoke.net/default.aspx/coredll/SendMessage.html to see how
you declare and call this windows function.

You would need to find the hwndChild by first identifying the main
window of the external process. The System.Diagnostic.Process class
will help you find the main window handle to all other processes. You
could copy any text from all of the processes, or you could identify the
process somehow and use the SendMessage function with that hwnd.

BTW, I've dropped the vb6 group from this reply.

--
Mike
 
ptpwjp...
Posted: Sat Oct 31, 2009 1:47 pm
Guest
Quote:
Visual Basic 2008 Express Edition

Please repost your question in new thread, or remove
microsoft.public.vb.general.discussion from your reply.
Why?
 
ptpwjp...
Posted: Sat Oct 31, 2009 2:17 pm
Guest
Thank you very much,

Quote:
You would need to find the hwndChild by first identifying the main window
of the external process. The System.Diagnostic.Process class will help
you find the main window handle to all other processes. You could copy
any text from all of the processes, or you could identify the process
somehow and use the SendMessage function with that hwnd.
but , which of a lot of process is the last process?

I send ALT + TAB from my application, to be in last process,
but in this situation my application lost processor, and don't do next
instruction Smile.
 
Larry Serflaten...
Posted: Sat Oct 31, 2009 2:43 pm
Guest
"ptpwjp" <ptpwjp at (no spam) op.pl> wrote in message news:hci49n$9re$1 at (no spam) news.onet.pl...
Quote:

Visual Basic 2008 Express Edition

Please repost your question in new thread, or remove
microsoft.public.vb.general.discussion from your reply.

Why?

Because you have targeted two distinctly different languages. Specific
answers for one language generally do not apply to the other.

This dotnet group is the more apropreate place for your question. Now
that you know where to ask your .Net questions, you do not need to include
the general discussion group which discusses VB6 and prior versions.

Starting a new thread would allow you to remove the un-needed group....
 
Kev Provance...
Posted: Sat Oct 31, 2009 3:03 pm
Guest
"ptpwjp" <ptpwjp at (no spam) op.pl> wrote in message news:hci49n$9re$1 at (no spam) news.onet.pl...
|
| >> Visual Basic 2008 Express Edition
| >
| > Please repost your question in new thread, or remove
| > microsoft.public.vb.general.discussion from your reply.
| Why?

Because we fncking said so, Bill
 
Mike Williams...
Posted: Sat Oct 31, 2009 3:16 pm
Guest
"ptpwjp" <ptpwjp at (no spam) op.pl> wrote in message news:hci49n$9re$1 at (no spam) news.onet.pl...

Quote:
Visual Basic 2008 Express Edition

Please repost your question in new thread, or remove
microsoft.public.vb.general.discussion from your reply.

Why?

Because your question is about VB.Net and the comp.lang.basic.visual.misc
group is NOT about VB.Net. It is a Classic VB group, which deals with VB6
and earlier versions, and which is completely different from VB.Net. Do you
have a problem with that? Tell you what, if you want to post your stuff to
irrelevant groups then let's add a few more . . . here goes . . .

Mike
 
mayayana...
Posted: Sat Oct 31, 2009 3:31 pm
Guest
Quote:
Visual Basic 2008 Express Edition

Please repost your question in new thread, or remove
microsoft.public.vb.general.discussion from your reply.

Why?


Because you posted your question in two groups
that are for completely different things. VB.Net
is covered by microsoft.public.dotnet.languages.vb.
The other group is for regular VB. (VB6 and lower.)

You're using VB.Net.

The two VBs have very little in common. It's
confusing because they're both often just called "VB",
but the answer to your question would be different in
each.
It's made even more confusing because Microsoft
has created a hodge podge of different names and
versions. VB.Net has a lot of names:
VB7. 8, 9. VB 1, 1.1, 2, 3, 3.5. VB 2003, 2005, 2008.
Those are different versioning systems based on
whether one is referring to the language, the framework
version, or the Visual Studio version. But they're all
VB.Net!

Regular VB (mostly VB 5/6) is a product that produces
compiled software and is COM-centric. VB.Net is Java-like,
producing JIT-compiled "assemblies", using the
..Net Framework, which is similar to the Java VM.

So the only thing shared by the two VBs, besides the
name, is a vague similarity in the appearance of their
code.
 
Family Tree Mike...
Posted: Sat Oct 31, 2009 9:26 pm
Guest
ptpwjp wrote:
Quote:
Thank you very much,

You would need to find the hwndChild by first identifying the main window
of the external process. The System.Diagnostic.Process class will help
you find the main window handle to all other processes. You could copy
any text from all of the processes, or you could identify the process
somehow and use the SendMessage function with that hwnd.
but , which of a lot of process is the last process?
I send ALT + TAB from my application, to be in last process,
but in this situation my application lost processor, and don't do next
instruction Smile.





I was afraid that would be your next question Sad.

I'm not sure how the alt-tab list of processes works.

--
Mike
 
ptpwjp...
Posted: Sun Nov 01, 2009 11:56 am
Guest
Quote:
What you want to do is very complex and
may not be possible. Presumably you want
to find the foreground window to get the
last selection.
Yes.


......
Quote:
Word has an object model.

For IE you want
to get the document.selection ...... but what if the person is
using Firefox?
It is reason why I send ctrl+ins , it is universal method I think.

But I can't get data to variable in my program. Haw can I do it?

Quote:
And even if you work all that out,
I don't understand this, I'm not English.


Quote:
how do you figure out
what the last selection's parent program is?
It isn't interesting for me what parent program is.

I need only selected text.

In old times, sometimes, in newspapers there was same programs which added
new menu to system menu. For example: "change to yellow", near menu copy,
past, cut, delete. But it was always difficult to uninstall, and I don't
like this kind of changes. But the sense of problem is the same.


......
Quote:
Maybe someone will come up with a way to do what
you want. Maybe there's some kind of high-level
functionality that I'm not thinking of. But I'd be surprised
if that's the case.

It sounds like you're trying to
just send key sequences to get the different windows,
but I don't see how that can work. You can't just usurp
the Desktop and set focus to whatever window you like.
 
mayayana...
Posted: Sun Nov 01, 2009 1:08 pm
Guest
Quote:
It is reason why I send ctrl+ins , it is universal method I think.
But I can't get data to variable in my program. Haw can I do it?


That's interesting. I didn't know about that.
I just tried the API keybd_event, sending the
following parameters in succession:

17, 0, 0, 0
45, 0, 0, 0
45, 0, KEYEVENTF_KEYUP, 0
17, 0, KEYEVENTF_KEYUP, 0

It seems to work to get the current selection in
the active window. I can then just retrieve the
clipboard text. I'm running on Win98SE so I don't
know whether there might be security issues on
later systems with automated keystrokes.

Also, if they click a button in your program window
then of course they've changed the active window.
Even if you track changes in the active window, if
you want to catch the selection with keystrokes
then you will always be too late. Once you are
informed of the focus change you can no longer use
keystrokes.

Have you thought of trying a systemwide keyboard
hook? I'm not sure if this would work, but what I'm
thinking is something like the following:


* You set a keyboard hook.

* The person using your program uses a unique key
combination when they want to select current text.

* Your hook watches for that combination and when
it arrives you use the keybd_event method to capture
the current selection.

I don't know the specifics of how to do that in .Net.
Maybe someone else can provide that. And you'll
probably need to write a C++ DLL -- or obtain one --
to get your keyboard hook.
 
 
Page 1 of 2    Goto page 1, 2  Next
All times are GMT - 5 Hours
The time now is Sat Nov 28, 2009 9:21 am