![]() |
|
ArkBlast Countdown - Console Game - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework) +--- Thread: ArkBlast Countdown - Console Game (/Thread-ArkBlast-Countdown-Console-Game) |
RE: ArkBlast Countdown - Console Game - noize - 05-18-2013 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. RE: ArkBlast Countdown - Console Game - ArkPhaze - 05-18-2013 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. RE: ArkBlast Countdown - Console Game - noize - 05-18-2013 Ah, crap. I'll let you know if I find something else. Tomorrow, maybe, as now I'm so tired. RE: ArkBlast Countdown - Console Game - noize - 05-25-2013 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);
}RE: ArkBlast Countdown - Console Game - ArkPhaze - 05-25-2013 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. RE: ArkBlast Countdown - Console Game - noize - 05-25-2013 (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... God, if people's made games with background music *and* game-driven sounds, there will be a way to do that! :headbash: RE: ArkBlast Countdown - Console Game - ArkPhaze - 05-25-2013 (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... Haha, DirectX... 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: |