检测/挂钩窗口移动/拖动其他外部进程 [英] Detect / Hook Window Move/Drag of other external processes

查看:147
本文介绍了检测/挂钩窗口移动/拖动其他外部进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检测其他进程的窗口移动/拖动的最佳方法是什么?在Windows7 64位系统中

What is the best way to Detect Window Move/Drag of other Processes? In Windows7 64-bit

我目前正在研究使用C ++和DLL的DLL中的Global Hooks. C#.这是一个痛苦,因为它不想正常工作.我在键盘和鼠标挂钩方面获得了一些成功.但是对于窗口消息,我只是不知道怎么了.

I'm currently investigating Global Hooks from a DLL using C++ & C#. It's a pain as it doesn't want to work properly. I've gotten some success with keyboard and mouse hooks. but for window messages I've just got no idea whats wrong.

这是我的.dll文件中的代码

this is the code in my .dll file

#include <windows.h>
#include <iostream>
#include <stdio.h>

HINSTANCE hinst;
#pragma data_seg(".shared")
HHOOK hhk;
WNDPROC realProc;
#pragma data_seg()
//#pragma comment(linker, "/SECTION:.shared,RWS") compiler error in VC++ 2008 express

LRESULT CALLBACK wireKeyboardProc(int code, WPARAM wParam,LPARAM lParam) {  
    //open the standard out stream for writing
    freopen("CONOUT$","w+t", stdout);
    printf("code:%d wparam:%d lparam:%d\n", code, wParam, lParam);

    /*
    if (code < 0) {
        return CallNextHookEx(0, code, wParam, lParam);
    }
    */
    //Beep(1000, 20);

    return CallNextHookEx(hhk, code, wParam, lParam);
}

LRESULT CALLBACK hookProc(HWND h, UINT msg, WPARAM wp, LPARAM lp)
{
    //open the standard out stream for writing
    freopen("CONOUT$","w+t", stdout);
    printf("h:%d msg:%d wp:%d lp:%d\n", h, msg, wp, lp);
    return CallWindowProc(realProc, h, msg, wp, lp);
}

extern "C" __declspec(dllexport) void install(unsigned long threadId, HWND hwnd) {
    //open the standard out stream for writing
    freopen("CONOUT$","w+t", stdout);

    //works for WH_KEYBOARD WH_MOUSE but doesnt work for WH_CALLWNDPROC
    hhk = SetWindowsHookEx(WH_CALLWNDPROC, wireKeyboardProc, hinst, threadId);
    printf("threadId: %d xxx: %d\n", threadId, hhk);

    /*
    //dont know whats wrong the return value of realProc is 0
    realProc = (WNDPROC)SetWindowLongPtr(hwnd, GWL_WNDPROC, (LONG_PTR)hookProc);
    printf("hwnd: %d xxx: %d\n", hwnd, realProc);
    */
}

extern "C" __declspec(dllexport) void uninstall() {
    UnhookWindowsHookEx(hhk); 
}

BOOL WINAPI DllMain(__in HINSTANCE hinstDLL, __in  DWORD fdwReason, __in  LPVOID lpvReserved) {
    hinst = hinstDLL;
    return TRUE;
}

我当时正在考虑制作自己的Aero Snap.这只是为了好玩.

I was thinking of making my own Aero Snap. This is just for fun.

感谢您的帮助.

推荐答案

经过一些额外的搜索之后,我发现了一个开源项目,该项目几乎可以完全满足我的需求.

After some extra googling i found a open source project that does almost exactly what i want.

http://sourceforge.net/projects/powerresizer/

它编译起来也很容易,没有错误.它在代码中显示了它的使用方式

it compiles easy without errors too. it shows in the code that it uses

SetWinEventHook(EVENT_SYSTEM_MOVESIZESTART, EVENT_SYSTEM_MOVESIZEEND,

和用于挂接过程的自定义dll.它还显示了其他一些技巧.从未在其他任何地方看到过SetWinEventHook.如果您学到了什么,请投票.

and a custom dll for the hook procedure. it also shows some other tricks. never seen SetWinEventHook anywhere else. upvote if you learned something.

该死的当然也有一些Windows错误.

damn of course it bugs with some windows too.

这篇关于检测/挂钩窗口移动/拖动其他外部进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆