[Webinar] Streamline your web hosting managementRegister Today


working with selected text by hitting a hotkey

Posted on 2000-01-02
Medium Priority
Last Modified: 2010-04-01
MFC app running: text selected in OTHER application (whatever app) & I hit a hotkey.
How should I work on the selected text?

I just want direction, not full code.
Any of the answers will be considered.

1a. Should I save clipboard, add text to clip, then when done restore it?
1b. If so, please supply pointer to restoring clipboard without corrupting it.
2. Any other way to work with selected text in external app, without working with clipboard at all?
3. Maybe there are ways to work with "multiple clipboards?"

ADVAthnaksNCE Moshe
Question by:mflam
  • 2
  • 2
LVL 22

Expert Comment

ID: 2318936
You probably don't need to use the clipboard.  But where is the text?  Is it in an edit box? an RTF window?  A list box? etc...

If it is in a rich edit control, for example, you can use the EM_GETTEXTRANGE message.  There are other messages for other types of controls/windows.

Author Comment

ID: 2327540
I see I have not been clear.
Of course if I was in my same app it would be easy...
Please give me a week (this is a very full week for me) and I'll fix the question.

Author Comment

ID: 2327754
Edited text of question.
LVL 22

Accepted Solution

nietod earned 80 total points
ID: 2328814
There is not guaranteed way to make it work. The app could be anything an hnow knows how it will work....

Your best bet is to use the clipboard because most apps will use it in responce to WM_CUT and WM_PASTE, but some might not and some will might respond in ways you don't want and some might respond but plae data on the clipboard that is not in a text form....

So what you would need to do is enumerate all the formats on the clipboard (EnumClipboardFormats()) and obtain the data for all the formats (GetClipboardData()) and store it all.  Then send the WM_CUT to the other app.  Then try to get text from the clipbpoard, if it is there, modify it and place it back on the clipboard (Clear the other formats from the clipboard, you don't want the app pulling from one of the unaltered formats.)  Then, whethor or not your got text from the other app, send it a WM_PASTE.  Finally place all the original data back on the clipboard.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question