我有一个程序,我关机窗口发出声音。到目前为止一切都很棒。但是当我隐藏窗口控制台时,程序不会发出声音。这有什么解决方案吗?
#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");
}