• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Doing stuffs in the background

I am building a game, and I would like to run a function in the background.  While the user is playing the game, the user could type the [TAB] key to access a menu list where the user could save, load, quit, etc.  Also, while the user is playing the game, I would like to play a midi file in the background (Different function).  Simply put, when the user presses the [TAB] key on his/her keyboard, the program should run a certain function.  How would I accomplish this?
0
junkyboy
Asked:
junkyboy
  • 4
  • 3
1 Solution
 
KangaRooCommented:
What OS, compiler ar you using?
0
 
junkyboyAuthor Commented:
I'm using MS VisC++ 6.0 on a Win2k machine.
0
 
AlexVirochovskyCommented:
Natural way is: using threads.
About threads you can read in you Windows doc or see
 http://sourceware.cygnus.com/pthreads-win32/ for "pthreads"
If you want, i can send you simple example of using threads (write you EMail).
 
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
junkyboyAuthor Commented:
I'm creating a console program...  Would it still work???  Also, I wanted to try to make this simple and easy to follow...
0
 
AlexVirochovskyCommented:
Why not? You (psevdo)code may be as :
#include <process.h>
void Thread1 (PVOID pvoid)
{
     while (!EndOfThread())
        {
          .....
        }
     _endthread () ;
}
void Thread2 (PVOID pvoid)
{
     while (!EndOfThread())
        {
          .....
        }
     _endthread () ;
}
void Thread3 (PVOID pvoid)
{
     while (!EndOfThread())
        {
          .....
        }
     _endthread () ;
}
void main()
{
   static PARAMS params1 ;
   static PARAMS params2 ;
   static PARAMS params3 ;
   _beginthread (Thread1, 0, &params1) ;
   _beginthread (Thread2, 0, &params2) ;
   _beginthread (Thread3, 0, &params3) ;
}
0
 
junkyboyAuthor Commented:
Can you send me a sample code, and if I could work it out, I'll give you the points: korngerd@yahoo.com

Thanks
0
 
AlexVirochovskyCommented:
I 've sent you simple example.
If you want something more serious, see
http://www.codeguru.com/misc/thread_manager.shtml
If not example, not class from codeguru don't fit you, simple reject my reply.
Alex

0
 
junkyboyAuthor Commented:
I think I could work it out somehow.  Thanks for the sample!
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now