/define:
A
[,
B
]
: Provides a means for performing optional conversions specified by #ifdef
structures within a
.RESTEXT
(text) file.
@
➤
➤
file
: Specifies the name of a response file to use for additional command line options. You
can only provide one response file for any given session.
Creating the Media Player Form Code
As normal, the example relies on two files to hold the form and the client code. Because we’re using
a COM component for this example, the form requires a number of special configuration steps.
Listing 9-1 shows the form code.
LISTINg 9-1:
Creating a Windows Forms application with a COM component
# Set up the path to the .NET Framework.
import sys
sys.path.append(‘C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727’)
# Make clr accessible.
import clr
# Add any required references.
548592c09.indd 182
2/24/10 12:48:22 PM
www.finebook.ir
Defining an Interop DLL
❘
183
clr.AddReference(‘System.Windows.Forms.DLL’)
clr.AddReference(‘System.Drawing.DLL’)
clr.AddReference(‘AxWMPLib.DLL’)
# Import the .NET assemblies.
import System
import System.Windows.Forms
import System.Drawing.Point
import AxWMPLib
class frmUseWMP(System.Windows.Forms.Form):
# This function performs all of the required initialization.
def InitializeComponent(self):
# Create a Component Resource Manager
self.resources = System.ComponentModel.ComponentResourceManager.
CreateFileBasedResourceManager(
‘frmUseWMP’, ‘C:/0255 - Source Code/Chapter09’, None)
# Configure Windows Media Player
self.MP = AxWMPLib.AxWindowsMediaPlayer()
self.MP.Dock = System.Windows.Forms.DockStyle.Fill
self.MP.Enabled = True
self.MP.Location = System.Drawing.Point(0, 0)
self.MP.Name = “MP”
self.MP.Size = System.Drawing.Size(292, 266)
self.MP.OcxState = self.resources.GetObject(“MP.OcxState”)
# Configure the form.
self.ClientSize = System.Drawing.Size(350, 200)
self.Text = ‘Simple Windows Media Player Example’
# Add the controls to the form.
self.Controls.Add(self.MP)
The code begins with the normal steps of adding the .NET Framework path, making
clr
accessible,
importing the required DLLs, and importing the required assemblies. Notice that the example uses
the
AxWMPLib.DLL
file and
AxWMPLib
assembly. Remember that the Ax versions of the files provide
wrapping around the ActiveX controls to make them usable as a managed control.
The code begins by creating a
ComponentResourceManager
from a file, using the
CreateFileBasedResourceManager()
method. Normally, a managed application would
create the
ComponentResourceManager
directly from the data stored as part of the form.
This is a special step for IronPython that could cause you grief later if you forget about it.
Even though Listing 9-1 shows the
CreateFileBasedResourceManager()
method call on multiple lines, it appears on a single line in the actual source
code. The IronPython call won’t work if you place it on multiple lines because
IronPython lacks a line continuation character (or methodology).
548592c09.indd 183
2/24/10 12:48:22 PM
www.finebook.ir
Do'stlaringiz bilan baham: |