Control Winamp (Delphi) using Windows messages

xiaoxiao2021-03-06  39

Control WINAMP (Delphi) using Windows Message Control WinAmp (Delphi) -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------- Part 1: Get Winamp's window WINAMP is a 32-bit Windows application. That is, we can use some of 32-bit Windows programming some basic technologies to implement control WinAmp, which is the use of Windows messages. You must get the handle of the WinAmp window before you send a message to Winamp. Here is a method to use external applications (eg, Delphi applications you have written) can meet the requirements. VAR HWNDWINAMP: HWND; hwndwinamp: = FINDWINDOW ('WinAmp v1.x', 0); // Get WinAmp's handle, you may notice a little, why use the class name "WinAmp v1.x" to find FindWindow? Because all versions of WINAMP 1.x and 2.x are used with "Winamp v1.x" Class Name. Part II: Three messages corresponding to WINAMP: WM_USER, WM_COMMAND, and WM_COPYDATA. WM_USER and WM_COPYDATA allow you to perform some advanced controls for WinAMP. WM_COMMAND can do some simple operations such as pause, play, and jump to the next music.

1.Wm_command message:

Previous track button 40044 Next track button 40048 Play button 40045 Pause / Unpause button 40046 Stop button 40047 Fadeout and stop 40147 Stop after current track 40157 Fast-forward 5 seconds 40148 Fast-rewind 5 seconds 40144 Start of playlist 40154 Go to end of playlist 40158 Open file dialog 40029 Open URL dialog 40155 Open file info box 40188 Set time display mode to elapsed 40037 Set time display mode to remaining 40038 Toggle preferences screen 40012 Open visualization options 40190 Open visualization plug-in options 40191 Execute current visualization plug-in 40192 Toggle About Box 40041 Toggle title Autoscrolling 40189 Toggle always on top 40019 Toggle Windowshade 40064 Toggle Playlist Windowshade 40266 Toggle doublesize mode 40165 Toggle EQ 40036 Toggle playlist editor 40040 Toggle main window visible 40258 Toggle minibrowser 40298 Toggle easymove 40186 Raise volume by 1% 40058 Lower volume by 1% 40059 Toggle Repeat 40022 Toggle Shuffle 40023 Open Jump To Time Dialog 40193 Open Jump To File D

ialog 40194 Open skin selector 40219 Configure current visualization plug-in 40221 Reload the current skin 40291 Close Winamp 40001 Moves back 10 tracks in playlist 40197 Show the edit bookmarks 40320 Adds current track as a bookmark 40321 Play audio CD 40323 Load a preset from EQ 40253 Save a preset to EQF 40254 Opens load presets dialog 40172 Opens auto-load presets dialog 40173 Load default preset 40174 Opens save preset dialog 40175 Opens auto-load save preset 40176 Opens delete preset dialog 40178 Opens delete an auto load preset dialog 40180 routines: Control Winamp pause, play, and jump to the next music Unit Unit1; Interface Uses Windows, Messages, Sysutils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls; Co nst IPC_WINAMP_NextTrackButton: integer = 40048; // skip to the next music Const IPC_WINAMP_PlayButton: integer = 40045; // play Const IPC_WINAMP_PauseUnpauseButton: integer = 40046; // pause type TForm1 = class (TForm) Button1: TButton; Button2: TButton; button3: TButton; procedure FormCreate (Sender: TObject); procedure Button1Click (Sender: TObject); procedure Button2Click (Sender: TObject); procedure Button3Click (Sender: TObject); private {Private declarations} public {public declarations} end; var Form1 : Tform1; hwndwinamp: hwnd; // WinAmp window handle Implement {$ r * .dfm} procedure TFORM1.FORMCREATE (Sender: TOBJECT); beginhwndwinamp: = FINDWINDOW ('' WinAmp V1.x ', 0); //// get

Winamp handle If hwndWinamp = 0 Then // determine whether or not to run Winamp begin ShowMessage ( '' start Winamp first! ''); Application.Terminate; endend; procedure TForm1.Button1Click (Sender: TObject); begin // make Winamp jump to the next music SendMessage (hwndWinamp, WM_COMMAND, IPC_WINAMP_NextTrackButton, 0); end; procedure TForm1.Button2Click (Sender: TObject); begin // make Winamp to play the current Mp3SendMessage (hwndWinamp, WM_COMMAND, IPC_WINAMP_PlayButton, 0); end; procedure TForm1 .Button3Click (Sender: TObject);. begin // make Winamp pause the current Mp3SendMessage (hwndWinamp, WM_COMMAND, IPC_WINAMP_PauseUnpauseButton, 0); end; end 2.WM_USER message: routine: get Winamp version unit Unit1; interface uses Windows, messages , SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, StrUtils; // use StrUtils to use LeftStr, RightStr, MidStr other functions Const WA_GETVERSION: integer = 0; // Winamp version type TForm1 = class (TForm Button1: tbutton; procedure formcreate; procedure button1click (sender: TOBJECT); private {private declarations} public {public decla rations} end; var Form1: TForm1; hwndWinamp: HWND; Handle implementation {$ R // Winamp window * .dfm} procedure TForm1.FormCreate (Sender: TObject); beginhwndWinamp: = FindWindow ( '' Winamp v1.x '' , 0); // Get Winamp's handle if hwndwinamp = 0 THEN / / Decision WINAMP Run Begin ShowMessage ('' Please start Winamp first! ''); Application.Terminate; endend; procedure TForm1.Button1Click (Sender: TObject); var VersionNum: integer; ReturnVersion: String; beginVersionNum: = SendMessage (hwndWinamp, WM_USER, 0, WA_GETVERSION); If Length (IntToHex (VersionNum, 4))> 3 Thenbegin Returnversion: = Leftstr (INTTOHEX (VersionNum, 4), 1) '' '' '; Returnversi

转载请注明原文地址:https://www.9cbs.com/read-61964.html

New Post(0)