程序原来是在Form窗口中画图,现在我想改为在PaintBox1中画图,源程序使用API的,有高手帮小弟改下,在PaintBox1中画出同样的效果。源代码(2):
//---------------------------------------------------------
// window procedurefunction SpectrumWindowProc(Wnd : HWND; Msg : Integer; wParam, lParam : Longint): Integer; stdcall;
var
  Ps : TPAINTSTRUCT;
  DC : HDC;
  I : Integer;
begin
  Result := 0;
  
  case Msg of
    WM_CREATE :
    begin
      GetOSInfo;
    
      // initialize BASS
      if not BASS_Init(-1, 44100, 0, Wnd, NIL) then
      begin
            Error('Can''t initialize device');
            Result := -1;
            Exit;
      end;      if not PlayFile(Wnd) then // start a file playing
      begin
          BASS_Free;
          Result := -1;
          Exit;
      end;      // create bitmap to draw spectrum in - 8 bit for easy updating :)
      FillChar(BI, SizeOf(BI), 0);
      with BI.bmiHeader do        // fill structure with parameter bitmap
      begin
        biSize := SizeOf(BI.bmiHeader);
        biWidth := SPECWIDTH;
        biHeight := SPECHEIGHT; // upside down (line 0=bottom)
        biPlanes := 1;
biBitCount := 8;
        biClrImportant := 256;
        biClrUsed := 256;
      end;      // setup palette
      for I := 0 to 127 do
      begin
            pal[I].rgbGreen := 255 - 2 * I;
            pal[I].rgbRed   := 2 * I;
      end;      for I := 0 to 32 do
      begin
            pal[128 + I].rgbBlue       := 8 * I;
            pal[128 + 32 + I].rgbBlue  := 255;
            pal[128 + 32 + I].rgbRed   := 8 * I;
            pal[128 + 64 + I].rgbRed   := 255;
            pal[128 + 64 + I].rgbBlue  := 8 * (31 - I);
            pal[128 + 64 + I].rgbGreen := 8 * I;
            pal[128 + 96 + I].rgbRed   := 255;
            pal[128 + 96 + I].rgbGreen := 255;
            pal[128 + 96 + I].rgbBlue  := 8 * I;
      end;      // create the bitmap
      SpecBmp := CreateDIBSection(0, BI, DIB_RGB_COLORS, SpecBuf, 0, 0);
      SpecDC  := CreateCompatibleDC(0);
      SelectObject(SpecDC, SpecBmp);      // setup update timer (40hz)
      timer := timeSetEvent(25, 25, @UpdateSpectrum, 0, TIME_PERIODIC);
    end;    WM_PAINT :
    if GetUpdateRect(Wnd, PRect(NIL)^, False) then
    begin
      DC := BeginPaint(Wnd, Ps);
      if DC = 0 then
      begin
        Result := 0;
        Exit;
      end;      BitBlt(DC, 0, 0, SPECWIDTH, SPECHEIGHT, SpecDC, 0, 0, SRCCOPY);
      EndPaint(Wnd, Ps);
      Result := 0;
      Exit;
    end;     WM_LBUTTONUP :
    begin
      SpecMode := (SpecMode + 1) mod 4; // swap spectrum mode
      if SpecMode = 2 then
        SpecPos := 0;
      FillChar(SpecBuf^, SPECWIDTH * SPECHEIGHT, 0); // clear display
      Result := 0;
      Exit;
    end;    WM_CLOSE :
    begin
      DestroyWindow(Wnd);
    end;    WM_DESTROY :
    begin
      if timer <> 0 then
        timeKillEvent(timer);
      BASS_Free;
      if SpecDC <> 0 then
        DeleteDC(SpecDC);
      if SpecBmp <> 0 then
        DeleteObject(specbmp);
      PostQuitMessage(0);
      Exit;
    end;
  end;
  Result := DefWindowProc(Wnd, Msg, wParam, lParam);
end;//---------------------------------------------------------procedure WinMain;
begin
  Window := FindWindow(szAppName, NIL);
  if Window <> 0 then
  begin
    if IsIconic(Window) then
      ShowWindow(Window, SW_RESTORE);
    SetForegroundWindow(Window);
    Halt(254);
  end;  // check the correct BASS was loaded
  if HIWORD(BASS_GetVersion) <> BASSVERSION then
  begin
    MessageBox(0, 'An incorrect version of BASS.DLL was loaded', '', MB_ICONERROR);
    Exit;
  end;  // register window class and create the window
  FillChar(WndClass, SizeOf(TWndClassEx), 0);
  WndClass.cbSize        := SizeOf(TWndClassEx);
  WndClass.style         := CS_HREDRAW or CS_VREDRAW;
  WndClass.lpfnWndProc   := @SpectrumWindowProc;
  WndClass.cbClsExtra    := 0;
  WndClass.cbWndExtra    := 0;
  WndClass.hInstance     := hInstance;
  WndClass.hCursor       := LoadCursor(0, IDC_ARROW);
  WndClass.hbrBackGround := GetSysColorBrush(COLOR_BTNFACE);
  WndClass.lpszClassName := szAppName;  if RegisterClassEx(WndClass) = 0 then
    Halt(255);  SizeX := SPECWIDTH  + 2 * GetSystemMetrics(SM_CXDLGFRAME);
  SizeY := SPECHEIGHT + 2 * GetSystemMetrics(SM_CYDLGFRAME) + GetSystemMetrics(SM_CYCAPTION);  PosX := (GetSystemMetrics(SM_CXSCREEN) - SizeX) div 2;
  PosY := (GetSystemMetrics(SM_CYSCREEN) - SizeY) div 2;  Window := CreateWindowEx(0, szAppName, '频谱演示(点击切换频谱演示模式)',
                        WS_POPUPWINDOW or WS_CAPTION,
PosX, PosY, SizeX, SizeY, 0, 0, hInstance, NIL);  ShowWindow(Window, SW_SHOWNORMAL);  while (GetMessage(Msg, 0, 0, 0)) do
  begin
    TranslateMessage(Msg);
    DispatchMessage(Msg);
  end;  Halt(Msg.wParam);
end;begin
  WinMain;
end.
小弟可用真金来换取各位高手的帮助。APIBitmap