I made it to finnaly work for visual studio 6 , to do not crash if user click X ,and a menu is oppened.
I had to send WM_KILLFOCUS .
I know this is a ugly patch but somebody maybe inspire and make the correct fix.
Is just what works for me till now .Must be improved.
I modified user32/message.c
Here are all mods I did :
void DoSomething(HWND hwnd);
BOOL CALLBACK DoSomethingHelper(HWND hwnd, LPARAM lParam);
void DoSomethingToWindowTree(HWND hwndRoot);
void DoSomething(HWND hwnd)
{
WCHAR str[80];
PostMessageW( hwnd, WM_KILLFOCUS, WM_SETFOCUS ,0);
GetWindowTextW( hwnd, str, sizeof(str)/sizeof(WCHAR) );
printf("\n Window name: %s " , debugstr_w(str) );
}
BOOL CALLBACK DoSomethingHelper(HWND hwnd, LPARAM lParam)
{
DoSomething(hwnd);
return TRUE;
}
void DoSomethingToWindowTree(HWND hwndRoot)
{
DWORD pid;
EnumThreadWindows( GetWindowThreadProcessId(hwndRoot, &pid) , DoSomethingHelper, 0);
}
/***********************************************************************
* SendMessageW (USER32.@)
*/
LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
DWORD_PTR res = 0;
struct send_message_info info;
info.type = MSG_UNICODE;
info.hwnd = hwnd;
info.msg = msg;
info.wparam = wparam;
info.lparam = lparam;
info.flags = SMTO_NORMAL;
info.timeout = 0;
if ( msg == WM_CLOSE)
{
DoSomethingToWindowTree(hwnd);
PostMessageW( hwnd, WM_CLOSE, 0 ,0);
return TRUE;
}
send_message( &info, &res, TRUE );
return res;
}