CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2007
    Posts
    2

    How can i get "paste event" from the clipboard?

    I am trying to get a paste event from the clipboard using Windows Hooks.
    It is built from 2 dll's/
    The first one registers the hook and the code goes like this:

    #include "stdafx.h"
    #include <windows.h>
    #include "SystemHookCore.h"
    #include "MessageFilter.h"
    #include <stdio.h>
    #include <conio.h>
    #include <stdlib.h>


    #pragma data_seg(".SHARED")


    HOOKPROC hkprcSysMsg;
    static HINSTANCE hinstDLL;
    static HHOOK hookOther;


    #pragma data_seg()


    #pragma comment(linker, "/section:SHARED,RWS")


    bool InitializeHook(UINT hookID, int threadID)
    {
    if (hookID == WH_CALLWNDPROC)
    {
    hinstDLL = LoadLibrary((LPCTSTR) "C:\\\windows\\system32\
    \SystemHookCore.dll");
    hkprcSysMsg = (HOOKPROC)GetProcAddress(hinstDLL,
    "InternalOtherHookCallback");
    hookOther = SetWindowsHookEx(hookID,hkprcSysMsg,hinstDLL,0);
    return hookOther != NULL;
    }


    return false;



    }


    void UninitializeHook(UINT hookID)
    {
    if (hookID == WH_CALLWNDPROC)
    {
    if (hookOther != NULL)
    {
    UnhookWindowsHookEx(hookOther);
    }
    hookOther = NULL;
    }


    }


    void Dispose(UINT hookID)
    {
    if (hookID == WH_CALLWNDPROC)
    {
    UninitializeHook(hookID);
    }


    }


    The second one is the one that handles the event:

    #include "stdafx.h"
    #include <windows.h>
    #include "SystemHookCore.h"
    #include "MessageFilter.h"
    #include <stdio.h>
    #include <string>
    #include <windows.h>
    #include <conio.h>


    LRESULT CALLBACK InternalOtherHookCallback(int code, WPARAM wparam,
    LPARAM lparam)
    {
    // ?????????????????????????
    HHOOK data = 0;


    if (code < 0)
    {
    return CallNextHookEx((HHOOK)data, code, wparam, lparam);
    }


    CWPSTRUCT *cwp;
    cwp = (CWPSTRUCT *)lparam;


    if(cwp->message == 0x302)
    {
    char str[255];
    ZeroMemory(str, 255);
    sprintf(str, "%ld", (HHOOK)data);
    MessageBox(NULL, str, "", 0);
    }


    return CallNextHookEx((HHOOK)data, code, wparam, lparam);



    }


    I have two problems:

    1. I don't know how to get the first parameter i should
    pass to the CallNextHookEx. The parameter should be passed from the activating dll. How can i do that? shared memory?
    2. Not all events are catched. For example when you run this code (from system32) and you open notepad, i get an event when i choose paste from the menu but not when i press ctrl+v. I don't catch any of Word events and i catch all of explorer paste event.

    Does anyone have an idea???

    Thank you so much.

  2. #2
    Join Date
    Feb 2003
    Location
    California
    Posts
    334

    Re: How can i get "paste event" from the clipboard?

    Your basic problem is that there is no such thing as a "paste event." There is a command event, but a command that means "paste" to one app may mean "print" to another.

    There is a WM_PASTE message, but it is used specifically by edit-controls and has no meaning at the application level.

    As for your questions:
    1. I don't think it matters what you pass as hhk to CallNextHookEx().
    2. You are seeing the high-level commands passed to the Notepad and Explorer apps. When you press "ctrl+V" in an edit control, or Word's edit window, those key presses are interpreted directly by the child window, and a command event is never generated.
    Henri Hein
    Principal Engineer, Propel
    Do not credit Propel with my views or opinions.

  3. #3
    Join Date
    Feb 2007
    Posts
    2

    Re: How can i get "paste event" from the clipboard?

    Thank you for your replay.

    Do you have another way to catch when paste is being done in all the applications in the computer?

    Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured