Week 7 - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

Week 7

Description:

... display a graphic from a bitmap file. A bitmap defines an image as a pattern ... You can use bitmaps of various color depths, including 2, 4, 8, 16, 24, and 32 ... – PowerPoint PPT presentation

Number of Views:84
Avg rating:3.0/5.0
Slides: 23
Provided by: CET
Category:
Tags: bitmap | week

less

Transcript and Presenter's Notes

Title: Week 7


1
Week 7
  • The Windows API
  • Sound and Images

2
Dynamic link library files
  • This is the first example we have come across of
    using pre-defined library functions-in this case
    to play a sound. These are sourced from dynamic
    link libraries (.dll) files in this case the
    winmm.dll.

3
What is the API?
  • The Application Windows Interface (API) is an
    interface to the many routines made available
    through Dynamic Link Libraries (DLLs) containing
    thousands of functions and procedures.
  • These are available for you to use in your
    applications
  • Think of them as a toolbox of extra programming
    tools

4
Adding a .wav file to the application
  • The first tutorial involves calling a pre-defined
    library dll called winmm.dll (Win multimedia)

5
Write the following code to the General
declarations section of the form.
  • Private Declare Function sndPlaySound Lib
    "winmm.dll" Alias "sndPlaySoundA" (ByVal
    lpszSoundName As String, ByVal uFlags As Long) As
    Long
  • ' Play AsynchronouslyConst SND_ASYNC H1

6
Write the following codebehind a command button
  • Private Sub cmdChimes_Click()throw
    sndPlaySound("C\windows\media\chimes.wav",
    SND_ASYNC)End Sub

7
Image control
  • Use the Image control to display a graphic. An
    Image control can display a graphic from a
    bitmap, icon, or metafile, as well as enhanced
    metafile, JPEG, or GIF files.

8
Inserting images
  • We are going to start buy inserting card suit
    shape .ico files from Windows

9
Twips
  • Visual Basic uses a device-independent unit of
    measurement, a twip, for calculating size and
    position. Two properties of the Screen object,
    TwipsPerPixelX and TwipsPerPixelY, can be used to
    determine the size of the display at run time.

10
For example-to adjust an image's location
  • imgShape.Left 0
  • ' Number of twips from left of Form window
  • imgShape.Top 3820
  • ' Number of twips from top of Form window

11
  • The Image control uses fewer system resources and
    repaints faster than a PictureBox control, but it
    supports only a subset of the PictureBox
    properties, events, and methods. Although you can
    place an Image control within a container, an
    Image control can't act as a container.

12
Image Control
  • An Image control can display a graphic from a
    bitmap file. A bitmap defines an image as a
    pattern of dots (pixels). A bitmap has the file
    name extensions .bmp, .dib, or .2bp. You can use
    bitmaps of various color depths, including 2, 4,
    8, 16, 24, and 32-bits, but a bitmap only
    displays correctly if the display device supports
    the color depth used by the bitmap.
  • For example, an 8-bit-per-pixel (256 color)
    bitmap only displays in 16 colors when shown on a
    4-bit-per-pixel (16 color) device.

13
Picture
  • Returns or sets a graphic to be displayed in a
    control.
  • Syntax
  • object.Picture picture
  • The parts of the Picture property syntaxes are
    described in the following table.
  • PartDescriptionpictureA string expression
    specifying a file containing a graphic, as
    described in Settings.

14
Settings
  • The settings for picture are described
  • SettingDescription(None)(Default) No
    picture.BitmapSpecifies a graphic. You can load
    the graphic from the Properties window at design
    time. At run time, you can also set this property
    using the file name of a bitmap.Remarks
  • At run time, the Picture property can be set to
    any other Picture property. Images are always
    specified by file name.
  •  

15
Syntaxobject.Drag action
  • The Drag method syntax has these parts
  • PartDescriptionobjectRequired. An object
    expression that evaluates to an object in the
    Applies To list.
  • If object is omitted, the object whose event
    procedure contains the Drag method is
    assumed.actionOptional. A constant or value that
    specifies the action to perform, as described in
    Settings. If action is omitted, the default is to
    begin dragging the object.Settings
  • The settings for action are
  • ConstantValueDescriptionvbCancel
  • Cancels drag operation
  • vbBeginDrag
  • Begins dragging objectvbEndDrag
  • Ends dragging and drop object

16
The Images Application
  • The form shown uses four image controls, a shape
    control, a picture box, and a command button.
    When the user selects a playing card symbol, the
    shape control highlights the symbol and a
    description is displayed in the picture box. For
    a working version of this example, see Images.frm
    in the Controls.vbp sample application.

17
Image and shape control example
18
The following table lists the property settings
for the objects in the application
19
(No Transcript)
20
Code
  • The code in the image control Click event looks
    like this
  • Private Sub imgHeart_Click()
  • shpCard.Left imgClub.Left
  • picStatus.Cls picStatus.Print "Selected Club"
    shpCard.Visible True
  • End Sub

21
Invoking methods
  • Note that the first line in the Click event code
    assigns a value (the Left property of the image
    control) to the Left property of the shape
    control using the operator. The next two lines
    invoke methods, so no operator is needed. In the
    third line, the value ("Selected Club") is an
    argument to the Print method.

22
  • There is one more line of code in the application
    that is of interest
  • it is in the Form Load event.
  • shpCard.Visible False
  • By setting the Visible property of the shape
    control to False, the shape control is hidden
    until the first image is clicked. The Visible
    property is set to True as the last step in the
    image control Click event.
Write a Comment
User Comments (0)
About PowerShow.com