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 / C++ / MFC
  4. How to get highlighted text by double click?

How to get highlighted text by double click?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialhelpquestionlearning
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.
  • P Offline
    P Offline
    Pony
    wrote on last edited by
    #1

    Hello, I have a problem with text selection. I want to get the highlighted text that users double click on it (not only in my own application). Do I have to use COleDataObject to implement this? Is this about clipboard? I'm a beginner. Guide me, please.:-O

    T 1 Reply Last reply
    0
    • P Pony

      Hello, I have a problem with text selection. I want to get the highlighted text that users double click on it (not only in my own application). Do I have to use COleDataObject to implement this? Is this about clipboard? I'm a beginner. Guide me, please.:-O

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      Yes, it's about clipboard. This code places the contents of strClipboardText variable in clipboad. You'll probably use CEdit::GetSel and CEdit::GetSel and CEdit::GetWindowText to get this string.

      CString strClipboardText = ...;

      if (!OpenClipboard() || !EmptyClipboard())
      {
      AfxMessageBox("Error: can't open the clipboard.");
      return;
      }
      HGLOBAL hglbText = GlobalAlloc(GMEM_MOVEABLE, 1 + strClipboardText.GetLength());
      char *pData = (char *)GlobalLock(hglbText);
      lstrcpy(pData, strClipboardText);
      GlobalUnlock(hglbText);
      SetClipboardData(CF_TEXT, hglbText);
      CloseClipboard();

      Assuming that you're using CEdit control, there will be a problem with double-clicking - this action highlights the *word* you're clicking on. Previous selection is lost. You may try to override WM_LBUTTONDBLCLK to change this behavior. Tomasz Sowinski -- http://www.shooltz.com

      P 1 Reply Last reply
      0
      • T Tomasz Sowinski

        Yes, it's about clipboard. This code places the contents of strClipboardText variable in clipboad. You'll probably use CEdit::GetSel and CEdit::GetSel and CEdit::GetWindowText to get this string.

        CString strClipboardText = ...;

        if (!OpenClipboard() || !EmptyClipboard())
        {
        AfxMessageBox("Error: can't open the clipboard.");
        return;
        }
        HGLOBAL hglbText = GlobalAlloc(GMEM_MOVEABLE, 1 + strClipboardText.GetLength());
        char *pData = (char *)GlobalLock(hglbText);
        lstrcpy(pData, strClipboardText);
        GlobalUnlock(hglbText);
        SetClipboardData(CF_TEXT, hglbText);
        CloseClipboard();

        Assuming that you're using CEdit control, there will be a problem with double-clicking - this action highlights the *word* you're clicking on. Previous selection is lost. You may try to override WM_LBUTTONDBLCLK to change this behavior. Tomasz Sowinski -- http://www.shooltz.com

        P Offline
        P Offline
        Pony
        wrote on last edited by
        #3

        Thank you very much. But there's a problem. I didn't get highlighted text from edit box but i want to get highlighted text from anywhere on screen (ex. in browser, spreadsheet, notepad, etc.). How can I get it? Guide me, please. :-O

        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