>And found it.  In cs_create_connection() in if_cscope.c there is Windows
>code that creates a new console, waits 40ms for the console to appear,
>before hiding it.  Except under load it may take more than 40 ms, so VIM
>fails to find and hide the console so it remains lying around.  Since it
>is already a nasty hack (as commented) it may be ok to hack it to try up
>to 5 times sleeping 40ms in order to find the window.  I'll have a play
>tonight.

On Windows 2000 and later, you can use the GetConsoleWindow() function to do
what that "nasty hack" is doing. Unfortunately, the nasty hack is necessary
on earlier versions (I can't think of any better way, except that ideally
the GUID would change each time), so you would have to have two code paths.
Maybe something like this would work to use the "reliable" method wherever
possible and the "nasty hack" if that isn't possible:

static HWND
cs_get_console_window()
{
    HWND hConsole = NULL;
    typedef HWND (WINAPI *PFGetConsoleWindow)(void);
    HANDLE hKernel32 = NULL;
    PFGetConsoleWindow pfGetConsoleWindow = NULL;

    hKernel32 = LoadLibrary("kernel32.dll");

    if (hKernel32)
    {
        pfGetConsoleWindow =
(PFGetConsoleWindow)GetProcAddress("GetConsoleWindow");
    }

    if (pfGetConsoleWindow)
    {
        hConsole = pfGetConsoleWindow();
    }
    else
    {
            /* copied from the "nasty hack" */
            char *title;
            title = (char *)alloc(1024);
            if (title == NULL)
                FreeConsole();
            else
            {
                GetConsoleTitle(title, 1024); /* save for future restore */
                SetConsoleTitle(
                    "GVIMCS{5499421B-CBEF-45b0-85EF-38167FDEA5C5}GVIMCS");
                Sleep(40); /* as stated in MS KB we must wait 40 ms */
                hConsole = FindWindow(NULL,
        
"GVIMCS{5499421B-CBEF-45b0-85EF-38167FDEA5C5}GVIMCS");
                SetConsoleTitle(title);
                vim_free(title);
            }
    }

    if (hKernel32)
    {
        FreeLibrary(hKernel32);
    }
}

Then replace the original "nasty hack" with:

if (AllocConsole())
{
    consolewnd = cs_get_console_window();
    if (consolewnd != NULL)
        ShowWindow(consolewnd, SW_HIDE)
}



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui