?
Solved

Transfer text from Explorer to Notepad

Posted on 1998-11-06
2
Medium Priority
?
172 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
[X]
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
  • 2
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 800 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

777 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