你必须得得到鼠标所在窗口的句柄,hwnd=WindowFormPoint(MousePoint);
然后用GetWindowsText(hwnd,buffer,maxcount)得到该窗口的标题,
buffer是保存标题的;
你能把你的关于dll文件发给我吗,要源码,不要已生成的dll啊,因为我也正在做一个进程通信的程序,我想研究研究,可以吗?
我的email:[email protected]

解决方案 »

  1.   

    我的这个东西也没有什么神秘的,让大家看看吧
    程序中有些调试用的语句,我就不改了
    ///////////firstdll.h
    #ifdef __cplusplus
    #define EXPORT extern "C" __declspec (dllexport)
    #else
    #define EXPORT __declspec (dllexport)
    #endifEXPORT LRESULT WINAPI MouseProcA(int nCode,WPARAM wparam,LPARAM lparam);
    EXPORT BOOL StartHook(HWND hwnd);
    EXPORT BOOL StopHook();
    #ifdef UNICODE
    #define MouseProc MouseProcW
    #else
    #define MouseProc MouseProcA
    #endif
    //////////.cpp
    #include <windows.h>
    #include "firstdll.h"
    #include <commctrl.h>#define WM_USER_SHOWNAME (WM_USER+100)
    #pragma data_seg ("shared")
    HWND hwndStatBar=NULL;     ////这个不一定是状态栏
    HINSTANCE hInst=NULL;
    HHOOK hHook=NULL;
    HWND glhPrevTarWnd=NULL;
    UINT aaa=0;
    TCHAR szCaption[100]={'\0','\0','\0','\0','\0','\0','\0','\0','\0','\0',
     '\0','\0','\0','\0','\0','\0','\0','\0','\0','\0',
     '\0','\0','\0','\0','\0','\0','\0','\0','\0','\0',
     '\0','\0','\0','\0','\0','\0','\0','\0','\0','\0',
     '\0','\0','\0','\0','\0','\0','\0','\0','\0','\0',
     '\0','\0','\0','\0','\0','\0','\0','\0','\0','\0',
     '\0','\0','\0','\0','\0','\0','\0','\0','\0','\0',
     '\0','\0','\0','\0','\0','\0','\0','\0','\0','\0',
     '\0','\0','\0','\0','\0','\0','\0','\0','\0','\0',
     '\0','\0','\0','\0','\0','\0','\0','\0','\0','\0',
    };
    //const TCHAR *szCaption=szCaption2;
    #pragma data_seg ()
    #pragma comment(linker,"/SECTION:shared,RWS")int WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
    {
    hInst=hInstance;
        return TRUE ;
    }
    EXPORT BOOL StartHook(HWND hwnd)
    {
    if(hwnd==NULL)return false;
    if((hHook=SetWindowsHookEx(WH_MOUSE,MouseProc,hInst,0))==NULL)
    return false;
    hwndStatBar=hwnd;
    return true;
    }
    EXPORT BOOL StopHook()
    {
    if(hHook==NULL)return false;
    if(UnhookWindowsHookEx(hHook))
    {
    hwndStatBar=NULL;
    hHook=NULL;
    HWND glhPrevTarWnd=NULL;
    return true;
    }
    return false;
    }
    EXPORT LRESULT WINAPI MouseProcA(int nCode,WPARAM wparam,LPARAM lparam)
    {
    LPMOUSEHOOKSTRUCT pMouseHook=(MOUSEHOOKSTRUCT FAR *) lparam;
    if(nCode>=0 && nCode==HC_ACTION)
    {
    HWND glhTargetWnd=pMouseHook->hwnd; 
    HWND ParentWnd=glhTargetWnd; 
    while (ParentWnd !=NULL)
    {
    glhTargetWnd=ParentWnd; 
    ParentWnd=GetParent(glhTargetWnd);
    }
    if(glhTargetWnd!=glhPrevTarWnd)
    {
    TCHAR sztmp[100];
    if(0!=GetWindowText(glhTargetWnd,sztmp,100))
    {
    memcpy(szCaption,sztmp,100);
    HDC hdc=GetDC(HWND_DESKTOP);
    TextOut(hdc,0,0,szCaption,lstrlen(szCaption));
    if(aaa==(UINT)szCaption)
    TextOut(hdc,0,30,"dengyu",6);
    else
    TextOut(hdc,0,30,"budeng",6);
    ReleaseDC(HWND_DESKTOP,hdc);
    // GLOBALHANDLE hGlobal;
    // hGlobal=GlobalAlloc(GMEM_ZEROINIT|GMEM_MOVEABLE|GMEM_SHARE,100);
    // BYTE* pGlobal=(BYTE*)GlobalLock(hGlobal);
    // memcpy(pGlobal,szCaption,100);
    // GlobalUnlock(hGlobal);
    if(IsWindow(hwndStatBar))
    SendMessage(hwndStatBar,WM_USER_SHOWNAME,(WPARAM)szCaption,0);
    glhPrevTarWnd=glhTargetWnd;
    // GlobalFree(hGlobal);
    aaa=(UINT)szCaption;
    }
    }
    }
    return CallNextHookEx(hHook,nCode,wparam,lparam);
    }