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
| void refreshBars( HDC hdc, float spectrum[]);
BOOL APIENTRY SpectrumProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
static float *oldSpectrum = NULL, finalSpectrum[BARS_NUMBER] = {0.0};
static HBITMAP BarBmp = (HBITMAP)LoadImage(hInst, "E:/Dune/Untitled2.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
static HRGN region = BmpToRgn(BarBmp,RGB(0,0,0));
static HBITMAP s_hOldBmp = NULL;
static HDC s_hMemDC = NULL;
static HBRUSH s_hBack = NULL;
switch (uMsg)
{
case WM_INITDIALOG:
SetWindowRgn(hDlg,region,TRUE);
RECT r;
HDC hdc = GetDC(NULL);
HBITMAP hBmp = NULL;
GetClientRect(hDlg,&r);
hBmp = CreateCompatibleBitmap(hdc, r.right, r.bottom);
s_hMemDC = CreateCompatibleDC(hdc);
ReleaseDC(NULL, hdc);
s_hOldBmp = SelectObject(s_hMemDC, hBmp);
s_hBack = CreateSolidBrush(RGB(0,0,0));
SetTimer(hDlg, 0, 0, (TIMERPROC)NULL);
break;
case WM_PAINT :
{
RECT r;
GetClientRect(hDlg, &r);
FillRect(s_hMemDC, &r, s_hBack);
refreshBars(s_hMemDC, finalSpectrum);
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hDlg, &ps);
BitBlt(hdc, 0, 0, r.right, r.bottom, s_hMemDC, 0, 0, SRCCOPY);
EndPaint(hDlg, &ps);
}
}
break;
case WM_TIMER:
if(IsWindowVisible(hDlg))
{ oldSpectrum = FSOUND_DSP_GetSpectrum();
adaptSpectrum(oldSpectrum, finalSpectrum);
InvalidateRect(hDlg, NULL, FALSE);
}
break;
case WM_CLOSE:
HBITMAP hBmp = SelectObject(s_hMemDC, s_hOldBmp);
s_hOldBmp = NULL;
DeleteObject(hBmp);
DeleteDC(s_hMemDC), s_hMemDC=NULL;
DeleteObject(s_hBack), s_hBack=NULL;
//ShowWindow (hDlg,SW_HIDE);
PostQuitMessage(0);
break;
default:
return FALSE;
}
return TRUE;
}
void refreshBars( HDC hdc, float spectrum[])
{
static int height[BARS_NUMBER] = {0};
SelectObject(hdc, CreateSolidBrush(RGB(0,180,255)));
for(int i = 0 ; i < BARS_NUMBER ; i++)
{
if(spectrum[i] < height[i])
height[i]-=3;
else if(spectrum[i] > height[i])
{
if(spectrum[i] > 250)
height[i] = 290;
else
height[i] = (int)spectrum[i];
}
}
for(int i = 0 ; i < BARS_NUMBER ; i++)
Rectangle(hdc, (i*BEFORE_NEXT)+17, WINDOW_HEIGHT-height[i], ((i*BEFORE_NEXT)+17)+BAR_WIDTH, WINDOW_HEIGHT);
return;
} |
Partager