Solved

Transfer text from Explorer to Notepad

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Strange date stored 22 100
Get filename and folder into excel 7 67
Whole sheet autoscrub still needed 19 44
MaxSpan challenge 9 67
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

746 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

8 Experts available now in Live!

Get 1:1 Help Now