Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


ArkBlast Countdown - Console Game filter_list
Author
Message
RE: ArkBlast Countdown - Console Game #71
Found this here: http://www.cplusplus.com/forum/windows/29294/ .

Code:
#include <windows.h>
#include <mmsystem.h>
#include <stdlib.h>
#pragma comment(lib, "winmm.lib")

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

// Colors, brushes and fonts used.
COLORREF AquaBlue = RGB(51,255,204), yellow = RGB(255,255,102);
HBRUSH   AquaBluebr = CreateSolidBrush(AquaBlue);

HFONT sysfont=static_cast<HFONT>(GetStockObject(SYSTEM_FONT));

// sound clips used
LPCTSTR soundA = L"AudioClips\\GameOpen.wav";
LPCTSTR soundB = L"AudioClips\\gOneShot.wav";
LPCTSTR soundC = L"AudioClips\\rocketFire.wav";
LPCTSTR soundD = L"AudioClips\\airWrench.wav";
LPCTSTR soundE = L"AudioClips\\levelBK1.wav";
LPCTSTR soundF = L"AudioClips\\levelBK2.wav";
LPCTSTR soundG = L"AudioClips\\levelBK3.wav";

HDC hdc;
static HINSTANCE hInst;

int APIENTRY WinMain(HINSTANCE hinst,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
        HWND hwnd;
    MSG  lpmsg;
    WNDCLASSEX wc = {0};
    static wchar_t szAppName[] = L"playSoundShell.app";
    
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.lpszClassName = szAppName;
    wc.hInstance = hinst;
    wc.lpfnWndProc = WndProc;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
    wc.lpszMenuName = 0;
    wc.hbrBackground =  AquaBluebr;
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    if( !RegisterClassEx (&wc) )
        return 0;

    hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,szAppName,L"playSoundShell",
        WS_OVERLAPPEDWINDOW,200,200,640,// started at 600
        480,NULL,NULL,hinst,NULL );

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    while(GetMessage(&lpmsg,NULL,0,0) )
    {
        TranslateMessage(&lpmsg);
        DispatchMessage(&lpmsg);
    }//End Message Loop.

    return(lpmsg.wParam);
    // TODO: Place code here.
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{    
    PAINTSTRUCT ps;
    
    static POINTS pt,sz={300,300};
    RECT rect;
    char ch;
    int j=0;// for looping.
    
    switch(msg)
    {
        case WM_CREATE:            
            hInst = ((LPCREATESTRUCT) lParam) -> hInstance;
            return 0 ;

        case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);
            ValidateRect(hwnd, NULL);
            GetClientRect (hwnd, &rect) ;
            TextOut(hdc, 100, 100, L"This is a project shell with working playSound calls", 52);
            EndPaint(hwnd, &ps);            
            return 0;
            
        case WM_CHAR:// Handles keyboard events.            
            ch = wParam;
            ch = tolower(ch);

            switch( ch )
            {
                case 'a':// non-looping clips
                    PlaySound((LPCTSTR) soundA, NULL, SND_FILENAME | SND_ASYNC);
                    break;
                case 'b':
                    PlaySound((LPCTSTR) soundB, NULL, SND_FILENAME | SND_ASYNC);
                    break;
                case 'c':
                    PlaySound((LPCTSTR) soundC, NULL, SND_FILENAME | SND_ASYNC);
                    break;
                case 'd':
                    PlaySound((LPCTSTR) soundD, NULL, SND_FILENAME | SND_ASYNC);
                    break;
                case 'e':// looping clips
                    PlaySound((LPCTSTR) soundE, NULL, SND_LOOP | SND_FILENAME | SND_ASYNC);
                    break;
                case 'f':
                    PlaySound((LPCTSTR) soundF, NULL, SND_LOOP | SND_FILENAME | SND_ASYNC);
                    break;
                case 'g':
                    PlaySound((LPCTSTR) soundG, NULL, SND_LOOP | SND_FILENAME | SND_ASYNC);
                    break;
                case 's':
                    PlaySound(NULL, 0, 0);// stops playback of clip
                    break;
                case VK_ESCAPE:// terminate app.                    
                    PostQuitMessage(0);
                    break;
                default:
                    break;
            }
            return 0;        

        case WM_DESTROY:            
            PostQuitMessage(0);
            break;        
        default:
            return( DefWindowProc(hwnd, msg, wParam, lParam) );
            break;
    }//End Switch on msg.
    return(0);
}//End CALLBACK.

I think I would use something like this to make different stubs (one for each audio file) and run it when needed.
My Bitcoin address: 1AtxVsSSG2Z8JfjNy9KNFDUN6haeKr7LiP
Give me money by visiting www.google.com here: http://coin-ads.com/6Ol83U

If you want a Bitcoin URL shortener/advertiser, please, use this referral: http://coin-ads.com/register.php?refid=noize

Reply

RE: ArkBlast Countdown - Console Game #72
The SoundPlayer class already uses the PlaySound function from winnm.dll I believe. Read the comment the guy posted about the code you wrote here.

Quote:Here is a windows program which makes use of the playSound() function. It will play 1 sound at a time only. It is set up for keyboard input.

Doesn't work in my case... This is just a limitation of the PlaySound() function itself, not his code. You can't play more than one sound at a time with that function.

edit: Yep, the class I am using is already a wrapper for PlaySound().
Code:
[DllImport("winmm.dll", CharSet=CharSet.Auto)]
internal static extern bool PlaySound([MarshalAs(UnmanagedType.LPWStr)] string soundName, IntPtr hmod, int soundFlags);

He's just using a basic message loop in C++ to handle windows messages for the keys to play a single sound at a time.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: ArkBlast Countdown - Console Game #73
Ah, crap. I'll let you know if I find something else. Tomorrow, maybe, as now I'm so tired.
My Bitcoin address: 1AtxVsSSG2Z8JfjNy9KNFDUN6haeKr7LiP
Give me money by visiting www.google.com here: http://coin-ads.com/6Ol83U

If you want a Bitcoin URL shortener/advertiser, please, use this referral: http://coin-ads.com/register.php?refid=noize

Reply

RE: ArkBlast Countdown - Console Game #74
How about MCI?

Once again not in C#, though.

Code:
void play_music(HWND hMusic)
{
    char buf[1024] = {0};
    char file[MAX_PATH] = {0};

    if(!find_music_file(file))
        return;

    wsprintf(buf, "open %s type mpegvideo alias music", file);

    mciSendString(buf, NULL, 0, 0);
    mciSendString("play music repeat", NULL, 0, 0);
    SetWindowLongPtr(hMusic, GWL_USERDATA, 1);
}
My Bitcoin address: 1AtxVsSSG2Z8JfjNy9KNFDUN6haeKr7LiP
Give me money by visiting www.google.com here: http://coin-ads.com/6Ol83U

If you want a Bitcoin URL shortener/advertiser, please, use this referral: http://coin-ads.com/register.php?refid=noize

Reply

RE: ArkBlast Countdown - Console Game #75
MciSendString() is an option I came across, but it means WAV format. So encoding to WAV seems to be something of a standard based on everything I've come across so far lol...

And I know how to read that C++ code and make a C# equivalent, so that's no problem. :whistle: It's really the exact same but with P/Invoke and a few minor changes to the types.

No matter what I do though, XM, OGG, MP3, it all seems to rely on decoding and playing in a stream formatted as WAV format with the WAV header and all those parts. Perhaps except MIDI, but that's a little lame. I don't even know what I can do with MIDI, but I'm not interested anyways.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: ArkBlast Countdown - Console Game #76
(05-25-2013, 07:12 PM)ArkPhaze Wrote: MciSendString() is an option I came across, but it means WAV format. So encoding to WAV seems to be something of a standard based on everything I've come across so far lol...

And I know how to read that C++ code and make a C# equivalent, so that's no problem. :whistle: It's really the exact same but with P/Invoke and a few minor changes to the types.

No matter what I do though, XM, OGG, MP3, it all seems to rely on decoding and playing in a stream formatted as WAV format with the WAV header and all those parts. Perhaps except MIDI, but that's a little lame. I don't even know what I can do with MIDI, but I'm not interested anyways.

God, if people's made games with background music *and* game-driven sounds, there will be a way to do that! :headbash:
My Bitcoin address: 1AtxVsSSG2Z8JfjNy9KNFDUN6haeKr7LiP
Give me money by visiting www.google.com here: http://coin-ads.com/6Ol83U

If you want a Bitcoin URL shortener/advertiser, please, use this referral: http://coin-ads.com/register.php?refid=noize

Reply

RE: ArkBlast Countdown - Console Game #77
(05-25-2013, 08:13 PM)noize Wrote:
(05-25-2013, 07:12 PM)ArkPhaze Wrote: MciSendString() is an option I came across, but it means WAV format. So encoding to WAV seems to be something of a standard based on everything I've come across so far lol...

And I know how to read that C++ code and make a C# equivalent, so that's no problem. :whistle: It's really the exact same but with P/Invoke and a few minor changes to the types.

No matter what I do though, XM, OGG, MP3, it all seems to rely on decoding and playing in a stream formatted as WAV format with the WAV header and all those parts. Perhaps except MIDI, but that's a little lame. I don't even know what I can do with MIDI, but I'm not interested anyways.

God, if people's made games with background music *and* game-driven sounds, there will be a way to do that! :headbash:

Haha, DirectX... Smile It's a pain in the ass for C# though. Fine in C++, because you don't have to d*ck around to get it to work. With C#, you need to create some kind of managed wrapper for the native DirectX, so that means a whole bunch more coding to do.

If I wrote this in C++, I would use DirectX without any questions. I've played around with XAudio before, and it is sweeeet... :ok:
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply







Users browsing this thread: 1 Guest(s)