当我隐藏窗口时,我的CtrlHandler不起作用

时间:2016-11-30 00:29:42

标签: c++ winapi

我有一个程序,我关机窗口发出声音。到目前为止一切都很棒。但是当我隐藏窗口控制台时,程序不会发出声音。这有什么解决方案吗?

#include <stdio.h> 
#include <iostream>
#include <windows.h>
#include <fstream>
#include <direct.h>
#include <dirent.h>
#include <sstream>

BOOL CtrlHandler(DWORD fdwCtrlType)
{
    switch (fdwCtrlType)
    {

        case CTRL_SHUTDOWN_EVENT:

            Beep(750, 500);

            return FALSE;

        default:

            return FALSE;
    }

}

int main(void)
{

//ShowWindow(GetForegroundWindow(),SW_HIDE);//Hide the window console

    if (SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE))
    {

        while (1)
        {
            Sleep(500);
        }
    }

    else
        printf("\nERROR: Could not set control handler");
}

0 个答案:

没有答案