Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet204/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   200   201   202   203   204   205   206   207   ...   453
186

CHAPTER 9
InteractIng wIth cOM Objects
(continued)
MP = WMPLib.WindowsMediaPlayerClass()
# Assign the media player event.
MP.MediaError += PlayerError
# Assign a sound to the Media Player.
MP.URL = “Bells.WAV”
# Play the sound.
MP.controls.play()
Notice that you start by adding a reference to 
WMPLib.DLL
and importing 
WMPLib
into IronPython, rather than using the Ax versions. The next step appears in 
the 
btnPlay_Click()
event handler. After the code imports the required sup-
port, it instantiates an object (
MP
) of the 
WindowsMediaPlayerClass
, not 
WindowsMediaPlayer
(an interface) as many of the Microsoft examples show.
Now you can perform various tasks with the resulting component. The example 
is simple. All it does is assign a filename to the 
URL
property, and then call on 
controls.play()
to play the file. You can find additional information on using 
this technique at 
http://msdn.microsoft.com/library/dd562692.aspx
.
PERfORMINg LATE BINDINg uSINg ACTIvATOR.CREATEINSTANCE()
The 
Activator.CreateInstance()
method is one of the more powerful ways to work with objects 
of all kinds. In fact, this particular method can give your IronPython applications the same kind of 
support as the Windows scripting engines CScript and WScript.
When working with the 
Activator.CreateInstance()
method, you describe the type of object 
you want to create. The object can be anything. In fact, if you look through the 
HKEY_CLASSES_
ROOT
hive of the registry, you’ll find a number of objects to try on your system.
The example in this section does something a bit mundane, but also interesting — it demonstrates 
how to interact with the 
Shell
objects. You can get a description of the 
Shell
objects at 
http://
msdn.microsoft.com/library/bb774122.aspx
. The main reason to look at the Shell objects is 
that every Windows machine has them and they’re pretty useful for detecting user preferences. 
Listing 9-3 shows the code used for this example.

Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   200   201   202   203   204   205   206   207   ...   453




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish