Easily implement background play with Delphi

zhaozj2021-02-11  163

Delphi's VCL package is very good, it is very convenient, but there is no perfect program in the computer world. This article introduces the TMEDIAPLAY code to play in any window.

Author: testnet

Date: 2002.11.28

TMEDIAPLAY has a Display property, which is TwinControl type, TWINControl is the first VCL class with a Handle, TMEDIAPLAY is played with this Handle Handle window area. If we point Handle to the desktop, which tmediaplay will play on the desktop. Unlike Tcanvas, TwinControl's Handle's attribute is read-only, and the getHandle method is a static method. This shows that we want Handle to point to the desktop.

Modify TwinControl and let Handle write. Create TwinControl subclasses and hide the TwinControl.getHandle method, return to the desktop handle in the new method.

The second method is better.

TsurprisedInsplay = Class (TwinControl) protectedfunction getHenLe: hwnd; virtual; publicproperty handle: hwnd read getHandle; End;

Where GetHandle is defined as Virtual, which makes it easy to inherit. Because this only hides the TwinControl.getHandle method, it will be forced to convert to the parent class when this subclass is assigned to TMEDIAPLAY.DISPLAY, and the GetHandle method is called so that we can not meet our goals. So I made a change in TMEDIAPLay, enhanced its function, and the modified TMEDIAPLAY was completely compatible with the original.

Original code:

{Setting a TWinControl to display video devices' output} procedure TMediaPlayer.SetDisplay (Value: TWinControl); varAWindowParm: TMCI_Anim_Window_Parms; begin if (Value <> nil) and MCIOpened and FHasVideo then begin FFlags: = mci_Wait or mci_Anim_Window_hWnd; AWindowParm.Wnd: = Longint (value.handle);

..............

END;

After modification

{Setting a TWinControl to display video devices' output} procedure TMediaPlayer.SetDisplay (Value: TWinControl); varAWindowParm: TMCI_Anim_Window_Parms; wnd: HWND; beginif (Value <> nil) and MCIOpened and FHasVideo thenbeginFFlags: = mci_Wait or mci_Anim_Window_hWnd; // * *********************************************************** ********* f value is tsurprisedisplay life: = tsurprisedisplay (value) .handleelsewnd: = value.handle; // ****************************************************************************************************************************************************************************************************************************************************** *********************************************************** AWINDOWPARM.WND: = Longint (WND); ..........

END;

Although this modification is not beautiful, it is possible to maximize compatibility. Any modification method is to change TMEDIAPLAY.DISPLAY to the TsurpriseDisplay type, so that security is guaranteed.

Instructions:

Play with desktop

Just return the desktop handle in GetHandle and assign the value to display.

Function Tsurprisedisplay.gethandle: hWnd; BeginResult: = getDesktopWindow; End;

mp.display: = tsurprisedisplay.create (Self);

Play with Notepad

Remember that I declare in Virtual in the getHandle of Tsurprisedisplay, now starting to play its power, write a class inheritance from Tsurprisedisplay, override the getHandle method, and return to the Notepad handle.

TNOTEPADDISPLAY = Class (tsurprisedisplay) privateWnd: hwnd; protected correct geetHandle: hWnd; Override;

Function TNOTEPADISPLAY.GETHANDLE: HWND; Beginif Wnd = 0 Thenbeginwinexec ('Notepad.exe', 1); WND: = FindWindow ('Notepad', 'None Title - Notepad'); End; Result: = WND; END;

mp.display: = TNOTEPADDISPLAY.CREATE (Self);

Various playback methods can also be implemented similarly.

Source code download

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

New Post(0)