Join 136,114 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,756 people online right now. Registration is fast and FREE... Join Now!
Well, I'm a fairly new programmer with little experience, and I could use some help. Simply, I just need a short code that adds color. I used to have a code for color, but it was bulky and not very easy to use. I believe there is an easier one out there.
As for sound, I've heard this is considerably more complex. Is it possible someone can run me through a short bit of it a sound code?
I simply wish to color text when I compile. I currently use Dev-C++. As for sound, I can get it to beep, lol, but I am looking for something that could play things like MP3s and other such audio files.
I'm afraid I'm still not clear on the color aspect...I am assuming that you wish to have text colored when the program is run, but could be wrong. Could you provide a verbose description of what you're looking for?
There are a couple of ways to play audio files - the easiest is to spawn an instance of an audio program from your own. Would this be acceptable, or do you wish to play the files directly from your application?
Yes, color the output text, that is what I am looking for
With sound, I would prefer to play the audio directly from the application on run. However, the easier the better, I assume at this point. Baby steps, right now, lol.
If that is not what you a looking for, it sounds like you want a text editor with code hightlighting. Try to Google "notpad++" for something simple.
With the sound, I don't think sound is portable accross operating systems, so we will need to know what operating system you are using and if you want sound at compile time or runtime?
Actually, I just find a very handy color command in one of the given libraries.
To the point of sound, I am using Microsoft XP. I assume that is what you mean by operating system? Lol, you'll have to pardon me, I am not all together with some lingo. And I'd like to find something that would play upon running the program.
Actually, I just find a very handy color command in one of the given libraries.
To the point of sound, I am using Microsoft XP. I assume that is what you mean by operating system? Lol, you'll have to pardon me, I am not all together with some lingo. And I'd like to find something that would play upon running the program.
hi Im a new programmer aswell but i manage to put color in one of my little progs running on CLI.
Yeah, that is the first one I had found. However, at first I couldnt use it well and then I realized it was not precise it where it colored. I recently found another color code, which just needed an updated library. I am having problems linking that library, but thats a question for another time, lol. But thank you, that is very useful!
The windows API has a rather overly complicated interface called MCI. It is supposed to be fairly simple but I have never found it so. I actually have never used it in C (only VB). Here is a small example. This runs in VC++ and I am not sure if it will work on Dev-C++, if SHOULD as long as you can get the linker to understand that the functions are in the winmm.dll.
int main() { UINT wDeviceID; //a device ID so we can keep track of it once we open it. DWORD dwReturn; //a return value.. MCI_OPEN_PARMS mciOpenParms; //Structure for the MCI_OPEN command MCI_PLAY_PARMS mciPlayParms; //Structure for the MCI_PLAY command
// Opens a waveform-audio device by specifying the device and // file name.
//Not the constant MCI_OPEN_TYPE & MCI_OPEN_ELEMENT tell the function which fields of mciOpenParms actually // have something usefull in them. if (dwReturn = mciSendCommand(NULL, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, (DWORD)(LPVOID) &mciOpenParms)) {
cout << "unable to open device.\n"; }
// The device opened successfully; get the device ID. wDeviceID = mciOpenParms.wDeviceID;
// The lines that are commented out would be used to set up a notification for when the // wave file is done, however since we are in the console I removed this bit and went with // a Sleep() to pause until the playback should be over.
Sleep(16000); //Length of the wav file... you just need to make sure your program has enough time // to play the file before it closes the device. Else it will cut it short, or not play at all. mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL); return 0; }
of course maybe all you wanted was a beep?
CODE
// #include <windows.h> Beep(440,1000); //I belive this is an A440 beep for 1 second.
The above code will beep.
This post has been edited by NickDMax: 5 Apr, 2007 - 09:34 AM