Welcome to Dream.In.Code
Getting C++ Help is Easy!

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!




Two Questions - Color and Sound

3 Pages V  1 2 3 >  
Reply to this topicStart new topic

Two Questions - Color and Sound

Thegeneral
1 Apr, 2007 - 03:53 PM
Post #1

New D.I.C Head
*

Joined: 1 Apr, 2007
Posts: 19


My Contributions
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?
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Two Questions - Color And Sound
1 Apr, 2007 - 04:07 PM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
Add color to where? Or what? Is this a GUI application, or console?

Same questions for sound. To what are you trying to add sound? Any particular sound(s), like mp3's, or simply a beeping noise?
User is offlineProfile CardPM
+Quote Post

Thegeneral
RE: Two Questions - Color And Sound
1 Apr, 2007 - 06:01 PM
Post #3

New D.I.C Head
*

Joined: 1 Apr, 2007
Posts: 19


My Contributions
Very sorry, lol.

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.
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Two Questions - Color And Sound
1 Apr, 2007 - 06:14 PM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,226



Thanked: 37 times
Dream Kudos: 25
My Contributions
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?
User is offlineProfile CardPM
+Quote Post

Thegeneral
RE: Two Questions - Color And Sound
2 Apr, 2007 - 03:08 AM
Post #5

New D.I.C Head
*

Joined: 1 Apr, 2007
Posts: 19


My Contributions
Yes, color the output text, that is what I am looking for smile.gif

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.
User is offlineProfile CardPM
+Quote Post

ajwsurfer
RE: Two Questions - Color And Sound
2 Apr, 2007 - 12:30 PM
Post #6

D.I.C Regular
Group Icon

Joined: 24 Oct, 2006
Posts: 292



Thanked: 2 times
Dream Kudos: 50
My Contributions
A lot of color questions today. I can't help you with the sound thing.

If you want to build color into your applications, there are a few libraries that you will need.
http://www.dreamincode.net/forums/showtopic25845.htm
If you are using a OS X or Linux see this one.
http://www.dreamincode.net/forums/showtopic25873.htm

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?



User is offlineProfile CardPM
+Quote Post

Thegeneral
RE: Two Questions - Color And Sound
2 Apr, 2007 - 02:17 PM
Post #7

New D.I.C Head
*

Joined: 1 Apr, 2007
Posts: 19


My Contributions
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.
User is offlineProfile CardPM
+Quote Post

spooky
RE: Two Questions - Color And Sound
2 Apr, 2007 - 03:13 PM
Post #8

New D.I.C Head
*

Joined: 20 Oct, 2006
Posts: 10


My Contributions
QUOTE(Thegeneral @ 2 Apr, 2007 - 03:17 PM) *

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.

use:

=CODE=
HANDLE hConsole;
hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
SetConsoleTextAttribute
(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN |FOREGROUND_INTENSITY);
=CODE=

put this code before your text.

use the main colors such as green red or blue to create a new color wink2.gif

e.x

in this code i use FOREGROUND_BLUE and FOREGROUND_GREEN and i wraped my text into a very light blue color ( i think its called cian)

u can use FOREGROUND_RED and FOREGROUND_GREEN or FOREGROUND_RED and FOREGROUND_BLUE and FOREGROUND_GREEN -three colors- to create a new color:)

happy painting bro!

This post has been edited by spooky: 2 Apr, 2007 - 03:15 PM
User is offlineProfile CardPM
+Quote Post

Thegeneral
RE: Two Questions - Color And Sound
2 Apr, 2007 - 04:33 PM
Post #9

New D.I.C Head
*

Joined: 1 Apr, 2007
Posts: 19


My Contributions
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!

Now, sound, lol.
User is offlineProfile CardPM
+Quote Post

Thegeneral
RE: Two Questions - Color And Sound
4 Apr, 2007 - 02:30 PM
Post #10

New D.I.C Head
*

Joined: 1 Apr, 2007
Posts: 19


My Contributions
Alright, does anyone have any info on the playsound function?
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Two Questions - Color And Sound
5 Apr, 2007 - 09:30 AM
Post #11

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
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.

CODE
#include <iostream>
#include <windows.h>
#pragma comment (lib , "winmm.lib")
using namespace std;

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.

    mciOpenParms.lpstrDeviceType = "waveaudio";
    mciOpenParms.lpstrElementName = "dvorak.wav";

    //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.
    
    //mciPlayParms.dwCallback=(DWORD) hWndNotify;
    //mciPlayParms.dwFrom=0;
    //mciPlayParms.dwTo=0;

    //if (dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY, (DWORD)(LPVOID) &mciPlayParms))
    if (dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, 0, NULL))
    {
        mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
        cout << "no go\n";
        return (dwReturn);
    }

    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
User is offlineProfile CardPM
+Quote Post

Thegeneral
RE: Two Questions - Color And Sound
5 Apr, 2007 - 02:49 PM
Post #12

New D.I.C Head
*

Joined: 1 Apr, 2007
Posts: 19


My Contributions
I'm afraid that didn't work. I got an odd error, although that isn't too uncommon for me, lol. Here is what I am working with:

CODE

#include <cstdio> // getchar()
#include <windows.h> // PlaySound()

using namespace std;

int main()
{
char soundfile[] = "C:\Documents and Settings\NAME\My Documents\My Music\music.mp3";
PlaySound(soundfile,NULL,SND_FILENAME|SND_ASYNC);

getchar(); // wait
return 0;
}


I get the following error:

QUOTE

In function `int main()':

[Warning] passing NULL used for non-pointer converting 1 of `MCIERROR mciSendCommandA(MCIDEVICEID, UINT, DWORD, DWORD)'

[Warning] passing NULL used for non-pointer converting 4 of `MCIERROR mciSendCommandA(MCIDEVICEID, UINT, DWORD, DWORD)'

[Warning] passing NULL used for non-pointer converting 4 of `MCIERROR mciSendCommandA(MCIDEVICEID, UINT, DWORD, DWORD)'

[Warning] passing NULL used for non-pointer converting 4 of `MCIERROR mciSendCommandA(MCIDEVICEID, UINT, DWORD, DWORD)'

`}' at end of input

User is offlineProfile CardPM
+Quote Post

3 Pages V  1 2 3 >
Reply to this topicStart new topic
Time is now: 12/1/08 09:48PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month