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;
}


On Mon, Oct 10, 2016 at 9:30 PM, Ken Thomases <ken@codeweavers.com> wrote:
On Oct 10, 2016, at 1:15 PM, A B <dianaxxyyzz@gmail.com> wrote:

> Thank you for your response.
> I ' m trying to send WM_QUIT before send WM_CLOSE,when a user click on X ,but only when he close the main window . This is a ugly patch that prevent visual studio 6 to crash if a menu is opened and user click on X .
> That way I need to know if the hwnd from handle_wm_protocols() is the one of the main window or not , cause I need to send WM_QUIT only if user close his main program window.

Rather than sending WM_QUIT, I recommend that you try sending WM_CANCELMODE.  You can send that to any window which the window manager closes without unintended consequences, so you don't need to attempt to determine which is the "main" window.  In fact, this may not even be a hack; it might be the right thing to do.


On Oct 10, 2016, at 1:20 PM, A B <dianaxxyyzz@gmail.com> wrote:

> Thinking from wine perspective , what will be the logic to find out if a hwnd is for the main window of a program ?

There is no logic to find that out because "main window" is not a well-defined concept and means nothing in terms of Wine/Windows internals.  Visual Studio itself may consider one of its windows "main", but that is not exposed to Wine.  The only significance is how VS behaves.

-Ken