Thema: Delphi zu schnelle reaktion

Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#1

zu schnelle reaktion

  Alt 10. Mär 2007, 09:37
Hallo

Delphi-Quellcode:
function VuBoxW5_Render(This_Mod: PWinAMPVisModule): integer;
var
  LastTime: DWord;
  tr: TRect;
  SongName : PChar;
  PlaylistPos : LongInt;
  
begin
  if Active then
  begin
    LastTime := ElapsedTime;
    ElapsedTime := GetTickCount() - PluginStart;
    ElapsedTime := (LastTime + ElapsedTime) div 2;

    if VisForm.DrawAboutScroll then
      with VisForm.Image1.Canvas, VisForm.Image1 do
      begin
        Brush.Color := clBlack;
        Font.Color := $00CEFFCE;
        Font.Style := [fsBold];
        FillRect(ClipRect);
        SetRect(tr, 0, 0, Width, 0);
        DrawText(Handle, SAboutText, -1, tr,
          DT_CALCRECT or DT_WORDBREAK or DT_CENTER or DT_NOPREFIX);
        tr.Top := VisForm.aboutpos;
        tr.Left := Round((Width - (tr.Right - tr.Left)) / 2);
        tr.Right := tr.Left + tr.Right;
        tr.Bottom := tr.Top + tr.Bottom;
        DrawText(Handle, SAboutText, -1, tr,
          DT_WORDBREAK or DT_CENTER or DT_NOPREFIX);
      end else
    begin

    glDraw(This_Mod);

    // Display Song Name
    PlaylistPos:= SendMessage(This_Mod^.hWNDParent, WM_USER, 0, 125);
    SongName := Pointer(SendMessage(This_Mod^.hWNDParent, WM_USER, PlaylistPos, 212));

    glColor3f(1,1,1);
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glPrintBitmap(10 , 10, SongName, 1);
    glDisable(GL_BLEND);

    if HelpScreen then VuBoxW5HelpScreen();

    SwapBuffers(h_DC);

    end;

    if VisForm.DrawAboutScroll then
      with VisForm.Image1.Canvas, VisForm.Image1 do
      begin
        SetRect(tr, 0, 0, Width, 0);
        DrawText(Handle, SAboutText, -1, tr,
          DT_CALCRECT or DT_WORDBREAK or DT_CENTER or DT_NOPREFIX);

        if (VisForm.aboutpos + (tr.Bottom - tr.Top)) <= 0 then
          VisForm.DrawAboutScroll := False;
        if VisForm.aboutpos > (Height div 2) then
          Dec(VisForm.aboutpos, 4)
        else if VisForm.aboutpos > (Height div 3) then
          Dec(VisForm.aboutpos, 1)
        else
          Dec(VisForm.aboutpos, 4);
      end;

    if (keys[VK_ESCAPE]) then
    begin
      Active := False;
      PostQuitMessage(0);
      Result := 1;
      exit;
    end
    else
      ProcessKeys(This_Mod);
  end;
  Result := 0;
end;
Delphi-Quellcode:
procedure ProcessKeys(This_Mod: PWinAMPVisModule);
begin
  // Jump To Prev Song
  if keys[VK_LEFT] then
    SendMessage(This_Mod^.hWNDParent, WM_COMMAND, 40044, 0);

  // Jump To Next Song
  if keys[VK_RIGHT] then
    SendMessage(This_Mod^.hWNDParent, WM_COMMAND, 40048, 0);

  // Toggle Volume Up
  if keys[VK_UP] then
    SendMessage(This_Mod^.hWNDParent, WM_COMMAND, 40058, 0);

  // Toggle Volume Down
  if keys[VK_DOWN] then
    SendMessage(This_Mod^.hWNDParent, WM_COMMAND, 40059, 0);

  if keys[VK_F2] then
    if HelpScreen then HelpScreen:=False else HelpScreen:=True;

end;
Delphi-Quellcode:
// MAIN WINDOW PROCEDURE
function WndProc(hWnd: HWND; //Handle For The Window
                 Msg: UINT; //Message For This Window
                 wParam: WPARAM; //Additional Message Information
                 lParam: LPARAM): //Additional Message Information
                 LRESULT; stdcall;

begin

  if Msg=WM_SYSCOMMAND then //Intercept System Commands
    begin
      case wParam of //Check System Calls
        SC_SCREENSAVE,SC_MONITORPOWER: //Screensaver Trying To Start, Monitor Trying To Enter Powersave?
          begin
            result:=0; //Prevent This From Happening
            exit; //Exit
          end;
      end;
    end;
  case Msg of
    WM_ACTIVATE:
      begin
        if (Hiword(wParam)=0) then //Check Minimization State
          active:=true //Program Is Active
        else
          active:=false; //Program Is No Longer Active
        Result:=0; //Return To The Message Loop
      end;
    WM_CLOSE: //Did We Get A Close Message
      Begin
        PostQuitMessage(0); //Send A Quit Message
        result:=0 //Return To The Message Loop
      end;
    WM_KEYDOWN: //Is A Key Being Held Down?
      begin
        keys[wParam] := TRUE; //If So, Mark It As True
        sleep(250);
        result:=0;
      end;
    WM_KEYUP: //Is A Key Being Released?
      begin
       keys[wParam] := FALSE; //If So, Mark It As False
        result:=0; //Return To The Message Loop
      end;
    else
      begin
         Result := CallWindowProc(MainWindowProc, hWnd, Msg, wParam, lParam);
      end;
    end;
end;
Mein eigentliches Problem liegt hier!

Delphi-Quellcode:
    WM_KEYDOWN: //Is A Key Being Held Down?
      begin
        keys[wParam] := TRUE; //If So, Mark It As True
        sleep(250);
        result:=0;
      end;
Ohne Sleep(250) ist das ausführen der Key funktionen so schnell das ich mitunter 5 Titel auf einmal überspringe.
Wo liegt das Problem?

gruss Emil
  Mit Zitat antworten Zitat