tags:

views:

201

answers:

1

I have setup a hook on WM_SETTEXT message using WH_CALLWNDPROC.

In hook procedure

CWPSTRUCT* info = (CWPSTRUCT*) lParam;
wchar_t *wsz = NULL;
switch(info->message)
{
case WM_SETTEXT:
wsz = (wchar_t *) info->lParam;
//info->lParam = (LPARAM) L"Hello";
//SendMessage(info->hWnd,WM_SETTEXT,0,(LPARAM)L"HEllo");
//SetWindowText(info->hWnd,L"Hello");


break;
}

Is it possible to change the string as done above in the code. I tried by using APIs like

SendMessage(info->hWnd,WM_SETTEXT,0,(LPARAM)L"HEllo");
SetWindowText(info->hWnd,L"Hello");

But none of them working.Idea here is to hook WM_SETTEXT message and change the string before it reached destination window.

+1  A: 

No, the WH_CALLWNDPROC doesn't allow you to modify messages, the documentation for CallWndProc directly states this.

The WH_GETMESSAGE does allow you to modify the message. See the documentation for GetMsgProc. However, this probably won't work for what you want since it only messages that are retrieved with GetMessage() or PeekMessage() and send messages call the WndProc directly rather than using the message queue.

The way to do what you want is to use the WH_CBT hook and listed for HCBT_CREATEWND events. Then subclass the window as it is created and handle the WM_SETTEXT message.

shf301