How to control the system volume, but can't call the control panel?

zhaozj2021-02-16  47

You can write a class that controls the volume, and then in the form, add two TrackBar [to left and right channels, min: = 0; max = 255] and two checkbox [for setting whether you mute and two Sound volume synchronization], then write code.

// - [yoyoworks] ------------------------------------------- --------------------- // project name: prjPowerFlashPlayer // software name: iPowerFlashPlayer // units of: Xu Zijian // start date: March 14, 2004 , 14: 31: 16 // Unit function: Class for volume adjustment. / / -------------------------------------------------------------------------------------------- ----------- [Shanghai | China] -

Unit undtvolume; interface users; type TVolume = class (TOBJECT) private fvolume: longint; // stores volume. FISMUTE: Boolean; // Stores the mute value. Procedure SetleftVolume (Volume: Integer); // Set the volume of the left channel. Function GetLeftVolume: Integer; // Get the volume of the left channel. Procedure SetrightVolume (Volume: Integer); // Set the volume of the right channel. Function getrightvolume: integer; // Get the volume of the right channel. Procedure setismute (ismute: boolean); // Set whether you mute.

Public Constructor Create; Destructor Destroy; Override; Published Property LeftVolume: Integer Read GetLeftVolume Write SetLeftVolume; Property RightVolume: Integer Read GetRightVolume Write SetRightVolume; Property Mute: Boolean Read FIsMute Write SetIsMute; End; Implementation // -------- -------------------------------------------------- ------------------- // Process Name: TVOLUME.CREATE / / Parameters: None // Return Value: No // ---------- -------------------------------------------------- ----------------- Constructor TVolume.create; begin inherited create; fivuMe: = 0; FSMUTE: = false; // Initialization Variable WaveoutGetVolume (0, @fvolume); // Get the current volume end; // --------------------------------------------------------------------------------------------------------------------------------- --------------------------------- // Process Name: TVOLUME.DESTROY / / Parameters: None // Return Value: None / / --------------------------------------------- ------------------------------- DEStructor TVolume.destroy; begin inherited destroy; end; // ----- -------------------------------------------------- ----- ----------------- // Process Name: TVOLUME.SETLEFTVOLUME / / Parameters: Volume: Integer // Return Value: None // ---------- -------------------------------------------------- ----------------- procedure tvolume.SetleftVolume (Volume: integer); begin if (Volume <0) or (Volume> 255) Then Raise Exception.create ('Range Error of The Left Channel [0 to 255]. '); // If the "Volume" parameter is not in the range of 0 to 255, the exception is thrown. If FISMUTE = false1 begin Waveoutgetvolume (0, @fvolume); @ 示 指 指 变 v), 意 就 意 就 得 是 是 是 是, 是, 是, 是 时候 到 时候 是 时候 时候 时候 到, 是 时候 时候 时候 时候 的 时候 的 是 的Do not change the right channel.

Fvolume: = fvolume and $ fff0000 or (Volume SHL 8); // Digital Before added $ Represents Hexagle WaveoutSetVolume (0, FVOLUME); END // If not mute, change the volume; else fvolume: = fvolume And $ fff0000 or (Volume SHL 8); / / otherwise only change the variable.

End; // ------------------------------------------------------------------------------------------------------------------------ ------------------------------- // Process Name: TVolume.seRightVolume // Parameters: Volume: Integer // Return Value : No // ----------------------------------------------------------------------------------------------------------- ------------------------------ Procedure TVolume.seRightVolume (Volume: Integer); Begin IF (Volume <0) OR Volume> 255) Then Raise Exception.Create ( 'Range error of the right channel [0 to 255].'); If FIsMute = False Then Begin waveOutGetVolume (0, @FVolume); FVolume: = FVolume And $ 0000FFFF Or (Volume SHL 24); WaveoutSetVolume (0, FVOLUME); ELSE FVOLUME: = FVOLUME AND 0000fffFFFFFFFFF / or; // ------------------- -------------------------------------------------- -------- // Process Name: TVOLUME.SETISMUTE // Parameters: ismute: Boolean // Return Value: None: No // ------------------- -------------------------------------------------- -------- Procedure TVolume.setismute (ismute: boolean); begin fismute: = ismute; if fismute = true the WaveoutSetv Olume (0, 0) else WaveoutSetVolume (0, fvolume); end; // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------- // Function name: TVOLUME.GETLEFTVOLUME / / Parameters: None // Return Value: Inteder // ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------ Function TVolume.getLeftVolume: integer; Begin if fismute = false then WaveoutgetVolume (0, @fvolume); // Get the current volume Result: = Hi (fvolume); // Convert to digital end; // -------------- -------------------------------------------------- ------------- // Function Name: TVolume.GetrightVolume // Parameters: None // Return Value:

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

New Post(0)