OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
mci.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implements TMci and TMciHiddenWindow
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/mci.h>
10
11namespace owl {
12
14
15/////////////////////////////////////////////////////////////
16 static const tchar winmmStr[] = _T("WINMM.DLL");
17# if defined(UNICODE)
18 static const char mciSendCommandStr[] = "mciSendCommandW";
19# else
20 static const char mciSendCommandStr[] = "mciSendCommandA";
21# endif
22
23//
24// Returns TModule object wrapping the handle of the WINMM.DLL module
25//
28{
29 static TModule winmmModule(winmmStr, true, true, false);
30 return winmmModule;
31}
32
33//
34// Invokes 'mciSendCommand' indirectly
35//
36MCIERROR
37TWinMM::mciSendCommand(MCIDEVICEID deviceId, UINT msg, DWORD_PTR flags, DWORD_PTR param)
38{
39 static TModuleProc4<MCIERROR, MCIDEVICEID, UINT, DWORD_PTR, DWORD_PTR>
40 mci_SendCommand(GetModule(), mciSendCommandStr);
41 return mci_SendCommand(deviceId, msg, flags, param);
42};
43
44/////////////////////////////////////////////////////////////////////////////////
45//
46//
47//
49 EV_MESSAGE(MM_MCINOTIFY, EvMciNotify),
51
52//
53/// A hidden window created for the sole purpose of catching MCI messages.
54//
56:
57 TWindow(nullptr, nullptr, module),
58 Mci(mci)
59{
60 Attr.Style = WS_POPUP;
61}
62
63//
64/// Notifies the MCI class that the MCI event has finished.
65//
68{
69 TResult retVal = Mci.MciNotify(wp, lp);
70 Mci.SetBusy(false);
71 return retVal;
72}
73
74//
75/// Creates a hidden window for catching messages.
76//
78:
79 DeviceId(0),
80 WaitingForNotification(false)
81{
82 // Create a hidden window for notifications
83 //
84 Window = new TMciHiddenWindow(*this);
85 Window->Create();
86}
87
88//
89/// If the MCI device is still open, this closes it now. Deletes the hidden window.
90//
92{
93 if (DeviceId != 0)
94 Close();
95 delete Window;
96}
97
98//
99/// Returns the callback. If the window exists, the handle of the window is returned.
100//
101HWND
103{
104 if (Window)
105 return Window->GetHandle();
106 return nullptr;
107}
108
109//
110/// Sends the MCI command message to the device if it's not busy.
111//
112MCIERROR
113TMci::SendCommand(UINT msg, DWORD_PTR flags, DWORD_PTR param)
114{
115 if (IsBusy())
116 return MCI_NOTIFY_ABORTED;
117
118 return SendCommand(GetDeviceId(), msg, flags, param);
119}
120
121//
122/// Opens the MCI device.
123//
124MCIERROR
125TMci::Open(const MCI_OPEN_PARMS& parms, DWORD_PTR flags)
126{
127 MCIERROR retVal = SendCommand(0, MCI_OPEN, flags, reinterpret_cast<DWORD_PTR>(&parms));
128 if (retVal == 0) {
129 // success
130 //
131 DeviceId = parms.wDeviceID;
132 }
133 return retVal;
134}
135
136//
137/// Stops the MCI device and closes it.
138//
139MCIERROR
141{
142 SetBusy(false);
143 Stop(MCI_WAIT);
144 return SendCommand(MCI_CLOSE, MCI_WAIT, 0);
145}
146
147//
148/// Stops the MCI device.
149//
150MCIERROR
151TMci::Stop(DWORD_PTR flags)
152{
153 SetBusy(false);
154 MCI_GENERIC_PARMS parms;
155
156 if (flags & MCI_NOTIFY)
157 parms.dwCallback = reinterpret_cast<DWORD_PTR>(GetCallbackWindow());
158
159 MCIERROR retVal = SendCommand(MCI_STOP, flags, reinterpret_cast<DWORD_PTR>(&parms));
160 SetBusyIfNeeded(flags);
161 return retVal;
162}
163
164//
165/// Pauses the MCI device.
166//
167MCIERROR
168TMci::Pause(DWORD_PTR flags)
169{
170 SetBusy(false);
171 MCI_GENERIC_PARMS parms;
172
173 if (flags & MCI_NOTIFY)
174 parms.dwCallback = reinterpret_cast<DWORD_PTR>(GetCallbackWindow());
175
176 MCIERROR retVal = SendCommand(MCI_PAUSE, flags, reinterpret_cast<DWORD_PTR>(&parms));
177 SetBusyIfNeeded(flags);
178 return retVal;
179}
180
181//
182/// Resumes playing of the MCI device.
183//
184MCIERROR
185TMci::Resume(DWORD_PTR flags)
186{
187 SetBusy(false);
188 MCI_GENERIC_PARMS parms;
189
190 if (flags & MCI_NOTIFY)
191 parms.dwCallback = reinterpret_cast<DWORD_PTR>(GetCallbackWindow());
192
193 MCIERROR retVal = SendCommand(MCI_RESUME, flags, reinterpret_cast<DWORD_PTR>(&parms));
194 SetBusyIfNeeded(flags);
195 return retVal;
196}
197
198//
199// Sets the busy flag if the given flags include MCI_NOTIFY.
200//
201void
202TMci::SetBusyIfNeeded(DWORD_PTR flags)
203{
204 if (flags & MCI_NOTIFY)
205 SetBusy(true);
206}
207
208//
209/// Plays the MCI device.
210//
211MCIERROR
212TMci::Play(const MCI_PLAY_PARMS& parms, DWORD_PTR flags)
213{
214 MCIERROR retVal = SendCommand(MCI_PLAY, flags, reinterpret_cast<DWORD_PTR>(&parms));
215 SetBusyIfNeeded(flags);
216 return retVal;
217}
218
219//
220/// Seeks a particular position on the MCI device. This function requires the
221/// parameters to be specified in a structure.
222//
223MCIERROR
224TMci::Seek(const MCI_SEEK_PARMS& parms, DWORD_PTR flags)
225{
226 MCIERROR retVal = SendCommand(MCI_SEEK, flags, reinterpret_cast<DWORD_PTR>(&parms));
227 SetBusyIfNeeded(flags);
228 return retVal;
229}
230
231//
232/// Seeks a particular position on the MCI device. This function is provided for
233/// convenience.
234//
235MCIERROR
236TMci::Seek(DWORD to, DWORD_PTR flags)
237{
238 MCI_SEEK_PARMS parms;
239
240 if (flags & MCI_NOTIFY)
241 parms.dwCallback = reinterpret_cast<DWORD_PTR>(GetCallbackWindow());
242
243 parms.dwTo = to;
244
245 return Seek(parms, flags);
246}
247
248//
249/// Loads the file into the MCI device.
250//
251MCIERROR
252TMci::Load(const tstring& fileName, DWORD_PTR flags)
253{
254 MCI_LOAD_PARMS parms;
255
256 flags |= MCI_LOAD_FILE;
257
258 if (flags & MCI_NOTIFY)
259 parms.dwCallback = reinterpret_cast<DWORD_PTR>(GetCallbackWindow());
260 parms.lpfilename = fileName.c_str();
261 return SendCommand(MCI_LOAD, flags, reinterpret_cast<DWORD_PTR>(&parms));
262}
263
264//
265/// The default MciNotify is to return 0.
266//
269{
270 return 0;
271}
272
273//
274/// Sends the MCI command message to the opened device.
275//
276MCIERROR
277TMci::SendCommand(MCIDEVICEID deviceId, UINT msg, DWORD_PTR flags, DWORD_PTR param)
278{
279 return TWinMM::mciSendCommand(deviceId, msg, flags, param);
280}
281
282} // OWL namespace
283/* ========================================================================== */
284
A private TWindow derivative used by TMci to capture events.
Definition mci.h:32
TMciHiddenWindow(TMci &, TModule *=0)
A hidden window created for the sole purpose of catching MCI messages.
Definition mci.cpp:55
TResult EvMciNotify(TParam1, TParam2)
Notifies the MCI class that the MCI event has finished.
Definition mci.cpp:67
TMci is a Windows MCI (Media Control Interface) encapsulation class.
Definition mci.h:49
MCIERROR Play(const MCI_PLAY_PARMS &, DWORD_PTR flags=0)
Plays the MCI device.
Definition mci.cpp:212
MCIDEVICEID GetDeviceId() const
Returns the ID of the open MCI device.
Definition mci.h:128
TMci()
Creates a hidden window for catching messages.
Definition mci.cpp:77
virtual ~TMci()
If the MCI device is still open, this closes it now. Deletes the hidden window.
Definition mci.cpp:91
MCIERROR Close()
Stops the MCI device and closes it.
Definition mci.cpp:140
void SetBusy(bool)
Sets the busy flag for the MCI device.
Definition mci.h:142
HWND GetCallbackWindow() const
Returns the callback. If the window exists, the handle of the window is returned.
Definition mci.cpp:102
MCIERROR Open(const MCI_OPEN_PARMS &, DWORD_PTR flags=0)
Opens the MCI device.
Definition mci.cpp:125
MCIERROR Load(const tstring &fileName, DWORD_PTR flags=0)
Loads the file into the MCI device.
Definition mci.cpp:252
MCIERROR SendCommand(UINT msg, DWORD_PTR flags, DWORD_PTR param)
Sends the MCI command message to the device if it's not busy.
Definition mci.cpp:113
bool IsBusy() const
Returns true if the MCI is currently busy doing something.
Definition mci.h:135
MCIERROR Resume(DWORD_PTR flags=0)
Resumes playing of the MCI device.
Definition mci.cpp:185
MCIERROR Pause(DWORD_PTR flags=0)
Pauses the MCI device.
Definition mci.cpp:168
MCIERROR Seek(const MCI_SEEK_PARMS &, DWORD_PTR flags=0)
Seeks a particular position on the MCI device.
Definition mci.cpp:224
virtual TResult MciNotify(TParam1, TParam2)
The default MciNotify is to return 0.
Definition mci.cpp:268
MCIERROR Stop(DWORD_PTR flags=0)
Stops the MCI device.
Definition mci.cpp:151
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:78
static TModule & GetModule()
Definition mci.cpp:27
static MCIERROR mciSendCommand(MCIDEVICEID, UINT msg, DWORD_PTR flags, DWORD_PTR param)
Definition mci.cpp:37
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
TWindow(TWindow *parent, LPCTSTR title=nullptr, TModule *module=nullptr)
Adds this to the child list of parent if nonzero, and calls EnableAutoCreate so that this will be cre...
Definition window.cpp:341
#define _T(x)
Definition cygwin.h:51
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
Windows MCI (Media Control Interface) encapsulation classes.
Object Windows Library (OWLNext Core).
Definition animctrl.h:22
char tchar
Definition defs.h:77
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
LRESULT TResult
Result type.
Definition dispatch.h:52
std::string tstring
Definition defs.h:79
EV_MESSAGE(BM_SETSTYLE, BMSetStyle)