无法获取句柄(TWinControl..............奇怪的事)(12分)

  • 主题发起人 主题发起人 dafu2
  • 开始时间 开始时间
D

dafu2

Unregistered / Unconfirmed
GUEST, unregistred user!
TVideoPlayer = class(TWincontrol)
private
count:integer;
PlayState: TPlayState;
........................
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Play;
procedure Pause;
procedure Stop;
procedure Close;
end;
var
Graph: IGraphBuilder;
VideoWindow: IVideoWindow;
MediaControl: IMediaControl;
MediaEvent: IMediaEventEx;
RenderEngine: IRenderEngine;
GraphBuilder: IGraphBuilder;
MediaSeeking: IMediaSeeking;

constructor TVideoPlayer.Create(AOwner: TComponent);
begin
inherited ;
CoInitialize(nil);
end;


procedure TVideoPlayer.Play;
var
evCode: Integer;
videoFile: PWideChar;
VideoLongth, mPos: int64;
begin
videoFile := StringToOleStr('text750.avi');
CoCreateInstance(CLSID_FilterGraph, nil, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, Graph);
Graph.RenderFile(VideoFile, nil);
Graph.QueryInterface(IID_IVideoWindow, VideoWindow);
VideoWindow.put_Owner(Panel.Handle);
VideoWindow.put_WindowStyle(WS_Child or WS_CLIPCHILDREN); // WS_Clipsiblings
VideoWindow.SetWindowPosition(0, 0, 300, 300);

Graph.QueryInterface(IID_IMediaEventEx, MediaEvent);
MediaEvent.SetNotifyWindow(self.Handle, WM_GraphNotify, 0); //错误has not parent windows
//第一个是确定哪个窗体将得到消息,第二个是传递什么消息.第三个无所谓.
Graph.QueryInterface(IID_IMediaControl, MediaControl);
Graph.QueryInterface(IID_IMediaSeeking, MediaSeeking);
MediaControl.Stop();
MediaControl.Run;
end;




MediaEvent.SetNotifyWindow(self.Handle, WM_GraphNotify, 0);
//错误has not parent windows
难道TWinControl在内部不可以传消息的吗?郁闷!啊
 
不应该从TWinControl继承,
这样如果Self.Parent=nil的时候,就会出错!

要做成控件,从TComponent继承就行了。
至于接受消息的句柄。。。简单:
fHandle := Classes.AllocateHWnd(WndProc);
。。。
 
TWinControl本身好像无句柄,它的句柄实际上是父类的Handle,所以必须设置Parent,如果不要设置Parent,就从TWidgetControl的派生类继承
 
没说清楚:
TWincontrol的派生有2类,一类自己包含句柄,另一类需要有父类Parent才可用,因此它使用的是父类的Handle
 
改了 还是不能获取播放结束消息(EC_Complete )

constructor TVideoPlayer.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FHandle := AllocateHWnd(WndProc);
end;


procedure TVideoPlayer.WndProc(var Msg: TMessage);
begin
try
with Msg do
if Msg = EC_Complete then
Application.MessageBox('播放完毕!', '提示', MB_OK)
else
Result := DefWindowProc(FHandle, Msg, wParam, lParam);
//ShowMessage(inttostr(Msg.Msg));
except
Application.HandleException(Self);
end;
end;

发消息:
MediaEvent.SetNotifyWindow(self.FHandle, WM_GraphNotify, 0);




这个到底是咋回事啊?郁闷!
 
都是我的错,问题解决了。
帖出来说不定对别人有用!
谢谢lovecathy和risingsoft


procedure TVideoPlayer.WndProc(var Msg: TMessage);
var
evCode: Integer;
lParam1, lParam2: Integer;
i: integer;
begin
try
while pMediaEvent.GetEvent(evCode, lParam1, lParam2, 0) = S_OK do
begin
pMediaEvent.FreeEventParams(evCode, lParam1, lParam2);
if evCode = EC_Complete then
begin
Application.MessageBox('pMediaEvent[1]播放完毕!', '提示', MB_OK);
end;
end;
{ with Msg do
if Msg = EC_Complete then
Application.MessageBox('播放完毕!', '提示', MB_OK)
else
Result := DefWindowProc(FHandle, Msg, wParam, lParam);
//ShowMessage(inttostr(Msg.Msg)); }
except
Application.HandleException(Self);
end;
end;
 
多人接受答案了。
 
后退
顶部