FastSound
This is the first in a series, of short C-language programs that can be called by other programs like Basic or
NaaLaa. The idea is to use small .exe files in place of Dlls.
Here is the code:
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
void TestLoop () ;
int Update = 1;
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASSEX wcex;
HWND hwnd;
MSG msg;
BOOL bQuit = FALSE;
/* register window class */
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_OWNDC;
wcex.lpfnWndProc = WindowProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "GLSample";
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&wcex))
return 0;
/* create main window */
hwnd = CreateWindowEx (WS_EX_WINDOWEDGE,
"GLSample",
" http://rb23.yolasite.com ",
WS_ICONIC, // WS_POPUP
0,
0,
4,
4, // 720
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, nCmdShow);
/* program main loop */
while (!bQuit)
{
Sleep (1);
/* check for messages */
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
/* handle or dispatch messages */
if (msg.message == WM_QUIT)
{
bQuit = TRUE;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
// If Update = 1 play sound
if ( Update == 1)
{
Update = 2;
PlaySound ( "snd10.wav" ,NULL, SND_FILENAME ) ;
// TestLoop () ;
// Sleep (1000);
}
}
if( Update == 2)
{break ;}
}
DestroyWindow(hwnd);
return msg.wParam;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CLOSE:
PostQuitMessage(0);
break;
case WM_DESTROY:
return 0;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
Here is the NaaLaa program that calls the code:
visible:
mx = 31; my = 37 ; TheZone = 0
set window 0,0,800,600
set redraw off
set color 255,255,255
proc Setup
Loop = 0
hidden:
proc DrawScreen
do
wait 20
proc Input
until Loop = 10
end
procedure Setup()
a = 0
create zone 1, 200, 200, 50, 50
create zone 2, 300, 200, 50, 50
create zone 3, 400, 200, 50, 50
create zone 4, 500, 200, 50, 50
create zone 5, 600, 200, 50, 50
create zone 6, 200, 300, 50, 50
create zone 7, 300, 300, 50, 50
create zone 8, 400, 300, 50, 50
create zone 9, 500, 300, 50, 50
create zone 10, 600, 300, 50, 50
endproc
procedure Input()
if mousebutton(0,1)
mx = mousex()
my = mousey()
z = zone( mx,my )
TheZone = z
proc DrawScreen
proc OutPut z
endif
endproc
procedure OutPut( z )
if z = 1 then shellexecute "open", "PlaySnd1" , "", "", false
if z = 2 then shellexecute "open", "PlaySnd2" , "", "", false
if z = 3 then shellexecute "open", "PlaySnd3" , "", "", false
if z = 4 then shellexecute "open", "PlaySnd4" , "", "", false
if z = 5 then shellexecute "open", "PlaySnd5" , "", "", false
if z = 6 then shellexecute "open", "PlaySnd6" , "", "", false
if z = 7 then shellexecute "open", "PlaySnd7" , "", "", false
if z = 8 then shellexecute "open", "PlaySnd8" , "", "", false
if z = 9 then shellexecute "open", "PlaySnd9" , "", "", false
if z = 10 then shellexecute "open", "PlaySnd10" , "", "", false
endproc
procedure DrawScreen()
set color 40,50,60
cls
set caret 100,100
set color 255,255,255
wln "CLICK ON A BUTTON TO Play It's SOUND"
rem wln mx
rem wln my
wln TheZone
set color 75,75,180
x = 200 ; y = 200
for a = 1 to 10
set color 75,75,180
draw rect x,y,50,50,1
set color 15,15,19
draw rect x + 2,y + 2, 46, 46
x = x + 100
if a = 5
x = 200 ; y = 300
endif
next
redraw
endproc
end
SndTest.zip Size : 153.183 Kb Type : zip |
|