1: In the Config.Sys file:
[System]
MultiTask = TRUE ;requires multitasking support
2: In the Main program
#include <Symbol.h>
#include <MyFrame.h>
//Default virtual keyboard function for all windows
void far TransrateKey(CObject* pObject)
{
return(0);
}
int far MyThread1(DWORD dwParam)
{
WORD k = 0;
//The AfxKbhit function is the multitasking version, an upgraded kbhit()
while(!::AfxKbhit())
{
if ((k % 60) == 0)
{
::sound(500);
}
else if ((k % 60) == 30)
{
::nosound();
}
k++;
}
}
void far MyDebugFunction()
{
//Press any key to exit this function
while (!AfxKbhit())
{
}
}
//Main program
int main(int argc, char** argv)
{
//Register the multitasking kernel that comes with WinSail
::AfxRegisterMultitaskEntry(
::KernalInitProcess,
::KernalCloseProcess,
::__MultiTaskDelay);
//Initialize system functions
if (!::InitSystem(argc, argv))
{
::CloseSystem();
::printf("\nInit System Error");
return(0);
}
//At this point, the main program has already become thread 0!
//...
//You can start your own thread here
if ( -1 == ::AfxBeginProcess(MyThread1, NULL, DEFAULT_STACK_SIZE))
{
//Error handling
}
//Your work below
::MyDebugFunction();
//Close the system
::CloseSystem();
//Note: when process 0 closes, all processes will be forcibly closed, dangerous!
return(0);
}