目的是用钩子获得鼠标所在进程中的标题栏
Cap.h文件
#ifdef DLL1_API
#else
#define DLL1_API _declspec(dllimport)
#endif
#include <Windows.h>
DLL1_API bool CaptionHookStart(HWND hwnd);
DLL1_API bool CaptionHookEnd();
Cap.cpp文件
#define DLL1_API _declspec(dllexport)
#include "Cap.h"
HINSTANCE hinst;
HWND wndParent=NULL;
HWND wnd=NULL;
#pragma data_seg("mydata")
HWND m_hwnd=NULL;
char str[100]="wo";
#pragma data_seg()
#pragma comment(linker,"/section:mydata,RWS")
HHOOK hMouse;
BOOL WINAPI DllMain(
HINSTANCE hinstDLL, // handle to the DLL module
DWORD fdwReason, // reason for calling function
LPVOID lpvReserved // reserved
)
{
hinst=hinstDLL;
return true;
}
LRESULT CALLBACK MouseProc(
int nCode, // hook code
WPARAM wParam, // message identifier
LPARAM lParam // mouse coordinates
)
{
wnd=((MOUSEHOOKSTRUCT FAR *) lParam)->hwnd;
wndParent=wnd;
while(NULL!=GetParent(wnd))
{
wndParent=GetParent(wnd);
wnd=wndParent;
}
GetWindowText(wndParent,str,100);
// SetWindowText(m_hwnd,str); //这里出问题
SendMessage(m_hwnd,WM_SETTEXT,0,(LPARAM)(LPCTSTR)str);
return CallNextHookEx(hMouse,nCode,wParam,lParam) ;
}
bool CaptionHookStart(HWND hwnd)
{
m_hwnd=hwnd;
hMouse=SetWindowsHookEx(WH_MOUSE,MouseProc,hinst,0);
return true;
}
上述代码中,兰色代码段中,如果我采用注释掉的SetWindowText就得不到其余进程的标题栏,但为什么采用SendMessage就可以,非常的不解啊