0

我试图显示一个ShowWindow在回调函数中使用的窗口,该函数在我隐藏它之后由 a 设置SetTime,但它没有用。请检查以下代码示例。

#define _WIN32_WINNT 0x0500
#include<windows.h>
void CALLBACK f(HWND hwnd, UINT uMsg, UINT timerId, DWORD dwTime)
{
    MessageBoxA(NULL,"Test","test2",MB_OK);
    ShowWindow( hwnd, SW_SHOW );  //This will not show the window :(
    MessageBoxA(NULL,"Is it shown?","test2",MB_OK);
}
int main()
{
    MSG msg;
    ShowWindow( GetConsoleWindow(), SW_HIDE );
    SetTimer(NULL, 0, 1000*3, &f);
    while(GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}

谢谢你。

4

1 回答 1

0

正如@IInspectable 建议的那样,回调函数携带的句柄错误(这是NULL已传递给的句柄SetTimer)。

要更正上面的代码,您应该对showhide使用相同的句柄。

#define _WIN32_WINNT 0x0500
#include<windows.h>
HWND hwnd;
void CALLBACK f(HWND __hwnd__, UINT uMsg, UINT timerId, DWORD dwTime)
{
    MessageBoxA(NULL,"Test","test2",MB_OK);
    ShowWindow( hwnd, SW_SHOW );  //This will not show the window :(
    MessageBoxA(NULL,"Is it shown?","test2",MB_OK);
}
int main()
{
    MSG msg;
    hwnd=GetConsoleWindow();

    ShowWindow(hwnd , SW_HIDE );

    SetTimer(NULL, 0, 1000*3, &f);
    while(GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return 0;
}

谢谢你。

于 2016-04-18T11:37:15.473 回答