Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Transfer text from Explorer to Notepad

Posted on 1998-11-06
2
168 Views
Last Modified: 2013-11-20

I want to design a program which can do such things.

In Microsoft Internet Explorer, I make a selection of text.
After I press the Ctrl-C (or other), the text selection be
transfered or insert to Notepad automatically.
That means it does not need me to cut and to paste text from one program to another.
What should I do.

Will it use the hook programming technique?

Thanx in advance
0
Comment
Question by:murphylee
  • 2
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 1324317
Hooking would definitely make life easier, e.g. something like this:

BOOL CALLBACK FindCreatedTask( HWND hwnd, LPARAM lParam);

DWORD   g_dwState;
HWND    g_hwnd;

// This is a WH_GETMESSAGE hook
LRESULT CALLBACK HookProc   (   int     nCode,  // hook code
                                WPARAM  wParam, // removal flag
                                LPARAM  lParam  // address of structure with message
                            )
{
    PMSG    pmsg    =   ( PMSG) lParam;

    if  (   0   >   nCode   ||  PM_NOREMOVE ==  wParam)
        {
            return  (   CallNextHookEx  (   g_hhk,
                                            nCode,
                                            wParam,
                                            lParam
                                        )
                    );
        }

    if  (       WM_KEYDOWN  ==  pmsg->message  
        )
        {
            /* this one is for us, so check key state & app*/
            if  (       !strstr (   GetCommandLine  (), "IEXPLORE.EXE")
                    &&  0x80000000 & GetKeyState    (   VK_CONTROL)
                    &&  0x80000000 & GetKeyState    (   'c') //see winuser.h
                )
                {
                    g_dwState   =   STATE_CTRL_C_PRESSED;

                    PostMessage (   pmsg->hwnd, WM_COPY,    0,  0L);
                }
        }

    if  (       WM_COPY ==  pmsg->message
            &&  STATE_CTRL_C_PRESSED    ==  g_dwState
        )
        {
            g_dwState   =   STATE_WM_COPY_RECEIVED;

            return  (   CallNextHookEx  (   g_hhk,
                                            nCode,
                                            wParam,
                                            lParam
                                        )
                    );
        }

    if  (   STATE_WM_COPY_RECEIVED  ==  g_dwState)
        {
            STARTUPINFO si;
            PROCESS_INFORMATION pi;

            ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

            if  (   CreateProcess   (   "notepad.exe",...)) //  notepad is running
                {
                    g_hwnd  =   NULL;

                    EnumWindows (   FindCreatedTask,    ( LPARAM) pi.dwProcessId));

                    // copy text
                    if  (   g_hwnd)
                            PostMessage (   g_hwnd, WM_PASTE,   0,  0L);

                    g_dwState   =   STATE_INITIAL;
                }
        }

    return  (   CallNextHookEx  (   g_hhk,
                                    nCode,
                                    wParam,
                                    lParam
                                )
            );
}

BOOL CALLBACK FindCreatedTask( HWND hwnd, LPARAM lParam)
{
    DWORD   dwPID2Find  =   ( DWORD) lParam;
    DWORD   dwPID       =   0;

    if  (   GetWindowThreadProcessId    (   hwnd,   &dwPID))
        {
            if  (   dwPID   ==  dwPID2Find)
                {
                    g_hwnd  =   hwnd;

                    return  (   FALSE);
                }
        }

    return  (   TRUE);
}
 

0
 
LVL 86

Expert Comment

by:jkr
ID: 2031985
comment
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
Pressing cancel button with C# UI Automation 3 80
sumDigits challenge 9 170
how to split multiple lines delimiter : 8 109
I could not set window to top 4 20
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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