#include"windows.h"
#include"RESOURCE.H"
#include"mmsystem.h"
#include"stdio.h"
#define WORDLENG 750
//#pragma comment (lib,"winmm.lib")
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
BOOL CALLBACK DialogProc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
HWND hwndlg;
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{ HWND hwnd;
MSG msg;
WNDCLASS wnd;
wnd.cbClsExtra=0;
wnd.cbWndExtra=0;
wnd.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wnd.hCursor=LoadCursor(NULL,IDC_ARROW);
wnd.hIcon=LoadIcon(NULL,IDI_ASTERISK);
wnd.hInstance=hInstance;
wnd.lpfnWndProc=WindowProc;
wnd.lpszClassName="ems";
wnd.lpszMenuName=MAKEINTRESOURCE(IDR_MENU1);
wnd.style=CS_VREDRAW|CS_HREDRAW;
RegisterClass(&wnd);
hwnd=CreateWindow("ems",
"EMASMIC",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
static PWAVEHDR pwavehdr1,pwavehdr2;
static WAVEFORMATEX waveformat;
static PBYTE pbuffer1,pbuffer2,psavebuffer;
static HWAVEIN phwave;
static HWND ctrdig;
unsigned long int t;
static HINSTANCE hinstance;
static HDC dc;
static RECT rect;
static POINT * point;
static HWND hwndscroll,staticbox;
char s[8];
static int rang=0;
switch(uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CREATE:
pwavehdr1=(PWAVEHDR)malloc(sizeof(WAVEHDR));
pwavehdr2=(PWAVEHDR)malloc(sizeof(WAVEHDR));
psavebuffer=(PBYTE)malloc(1);
hinstance=((LPCREATESTRUCT)lParam)->hInstance;
GetClientRect(hwnd,&rect);
break;
case WM_TIMER:
::InvalidateRect(hwnd,NULL,TRUE);
::KillTimer(hwnd,5);
break;
case MM_WIM_OPEN:
EnableMenuItem(GetMenu(hwnd),IDM_ASD,MF_GRAYED);
waveInAddBuffer(phwave,pwavehdr1,sizeof(WAVEHDR));
waveInAddBuffer(phwave,pwavehdr2,sizeof(WAVEHDR));
waveInStart(phwave);
//::MessageBox(hwnd,"open","ok",MB_OK);
break;
case MM_WIM_DATA:
//POINT point[WORDLENG];
unsigned long te;
// int t2;
waveInAddBuffer(phwave,((PWAVEHDR)lParam),sizeof(WAVEHDR));
// HDC dc;
// RECT rect;
te=((PWAVEHDR)lParam)->dwBufferLength;
//::sprintf(s,"%d",rect.bottom);
// ::MessageBox(hwnd,s,NULL,MB_OK);
for( t=0;t<te;t++)
{(*(point+t)).x=t*((unsigned long)rect.right/te);
//t2=atoi(((PWAVEHDR)lParam)->lpData+t);
(*(point+t)).y=rect.bottom/2+40-*(((PWAVEHDR)lParam)->lpData+t)-128;
// point[t].y=rect.bottom-t2;
}
::PolylineTo(dc,point,((PWAVEHDR)lParam)->dwBufferLength);
::SetTimer(hwnd,5,rang+1,NULL);
//::ReleaseDC(hwnd,dc);
break;
case WM_SIZE:
MoveWindow(hwndscroll,0,HIWORD(lParam)-20,200,20,TRUE);
break;
case WM_HSCROLL:
switch(LOWORD(wParam))
{
case SB_LINEDOWN:
if(rang<100)
++rang;
break;
case SB_LINEUP:
if(rang>0)
--rang;
break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
rang=HIWORD(wParam);
break;
}
SetScrollPos(hwndscroll,SB_CTL,rang,TRUE);
::sprintf(s,"%d",rang);
::SetWindowText(staticbox,s);
// ::KillTimer(hwnd,5);
break;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDM_ASD:
pbuffer1=(PBYTE)malloc(WORDLENG);
pbuffer2=(PBYTE)malloc(WORDLENG);
point=(POINT *)malloc(WORDLENG*sizeof(POINT));
memset(pbuffer1,0,WORDLENG);
memset(pbuffer2,0,WORDLENG);
memset(point,0,WORDLENG);
// ::sprintf(s,"%d",*pbuffer1);
// ::MessageBox(hwnd,s,"df",MB_OK);
if(!pbuffer1||!pbuffer2)
{
free(pbuffer1);
free(pbuffer2);
::MessageBox(hwnd,"pp","ok",MB_OK);
}
waveformat.cbSize=0;
waveformat.nAvgBytesPerSec=11025;
waveformat.nBlockAlign=1;
waveformat.nChannels=1;
waveformat.nSamplesPerSec=11025;
waveformat.wBitsPerSample=8;
waveformat.wFormatTag=WAVE_FORMAT_PCM ;
if(waveInOpen(&phwave,WAVE_MAPPER,&waveformat,(DWORD)hwnd,0,CALLBACK_WINDOW ))
{
free(pbuffer1);
free(pbuffer2);
::MessageBox(hwnd,"OPENFALSE","FALSE",MB_OK);
}
pwavehdr1->dwBufferLength=WORDLENG;
pwavehdr1->dwBytesRecorded=0;
pwavehdr1->dwFlags=0;
pwavehdr1->dwLoops=1;
pwavehdr1->dwUser=0;
pwavehdr1->lpData=(char *)pbuffer1;
pwavehdr1->lpNext=NULL;
pwavehdr1->reserved=0;
waveInPrepareHeader(phwave,pwavehdr1,sizeof(WAVEHDR));
pwavehdr2->dwBufferLength=WORDLENG;
pwavehdr2->dwBytesRecorded=0;
pwavehdr2->dwFlags=0;
pwavehdr2->dwLoops=1;
pwavehdr2->dwUser=0;
pwavehdr2->lpData=(char *)pbuffer1;
pwavehdr2->lpNext=NULL;
pwavehdr2->reserved=0;
waveInPrepareHeader(phwave,pwavehdr2,sizeof(WAVEHDR));
GetClientRect(hwnd,&rect);
dc=GetDC(hwnd);
SelectObject(dc,CreatePen(PS_SOLID,0,RGB(255,255,0)));
break;
case IDM_TIMER:
hwndscroll=CreateWindow(TEXT("scrollbar"),NULL,WS_CHILD|WS_VISIBLE|WS_TABSTOP,
rect.left,rect.bottom-20,200 ,20,hwnd,NULL,hinstance,NULL);
::SetScrollRange(hwndscroll,SB_CTL,0,600,FALSE);
::SetScrollPos(hwndscroll,SB_CTL,0,FALSE);
staticbox=CreateWindow(TEXT("static"),NULL,WS_CHILD|WS_VISIBLE,rect.left+200,
rect.bottom-20,22,20,hwnd,NULL,hinstance,NULL);
break;
case IDM_GG:
hwndlg=CreateDialog( hinstance,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,DialogProc);
break;
case IDM_DEF:
char s[8];
ctrdig=GetDlgItem( hwndlg,IDC_LIST1);
for(int t=0;t<WORDLENG;t++)
{ sprintf(s,"%d",*(pbuffer1+t)-128);
SendMessage(ctrdig,LB_ADDSTRING,0,(LPARAM)s);
}
break;
}
}
break;
default: return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
}
BOOL CALLBACK DialogProc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
EndDialog(hwndDlg,0);
return TRUE;
}
return TRUE;
}
return FALSE;
}