Solved

Transfer text from Explorer to Notepad

Posted on 1998-11-06
2
166 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 88
Host to IP 7 77
Separate into files by filename 12 75
ASP.NET C# MessageBox.Show Showing a modal dialog box or form when the application ... 2 104
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now