1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
// playSoundShell.cpp
// basic playSound functions included here
#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.
|