Visual Basic 6 Black Book phần 7 pps

112 466 0
Visual Basic 6 Black Book phần 7 pps

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

MsgID Gets string identifier of current message. MsgIndex Sets index number of current message. MsgNoteText Text of current message. MsgOrigAddress Gets email address of originator of current message. MsgOrigDisplayName Gets originator’s name for current message. MsgRead True or False depending on whether message has been read. MsgReceiptRequested Indicates if return receipt is requested for message. MsgSent Indicates if message has been sent to mail server. MsgSubject Message’s subject. MsgType Sets type of current message. Sending Email From Visual Basic Now that you’ve added the MAPISession and MAPIMessages control to your program (see the previous topic), how do you use them to send email? Let’s see an example. Create a new standard EXE project, and add the MAPISession and MAPIMessages controls MAPISession1 and MAPIMessages1. Next add two command buttons, Command1 and Command2, with the captions “Send email” and “Read email”. We’ll enable Command1, the Send Email button, in this topic, and Command2, the Read Email button, in the next topic. In addition, we’ll need some place to display the email we’ve read, so add a text box, Text1, to the form, setting its MultiLine property to True and its ScrollBars property to Both (3). When users click Command1, they want to send email, and we let them do so by using the MAPIMessages control’s Compose and Send methods. Our first task, however, is to start a new MAPI session, and we do that with the MAPISession control’s SignOn method, after indicating that we don’t want to download email by setting its DownLoadMail property to False: Private Sub Command1_Click() MAPISession1.DownLoadMail = False MAPISession1.SignOn After signing on to the Microsoft Exchange email system, we set the MAPIMessages control’s SessionID to the MAPISession control’s SessionID property to initialize MAPIMessages1: Private Sub Command1_Click() MAPISession1.DownLoadMail = False MAPISession1.SignOn MAPIMessages1.SessionID = MAPISession1.SessionID Visual Basic 6 Black Book:Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML http://24.19.55.56:8080/temp/ch21\719-723.html (2 of 4) [3/14/2001 2:00:43 AM] Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com To compose a new email message, we have to set the MAPIMessages1 control’s MsgIndex property to -1 and call its Compose method: Private Sub Command1_Click() MAPISession1.DownLoadMail = False MAPISession1.SignOn MAPIMessages1.SessionID = MAPISession1.SessionID MAPIMessages1.MsgIndex = -1 MAPIMessages1.Compose This code displays the Compose dialog box, as shown in Figure 21.12. Users can enter the email text and address they want to use in that dialog box and click the Send button (the Send button displays an envelope in Figure 21.12) to send their email. Figure 21.12 Composing an email message. When the user is done composing the email, we send it with the MAPIMessages1 control’s Send method and sign off the MAPI session using the MAPISession1 control’s SignOff method: Private Sub Command1_Click() MAPISession1.DownLoadMail = False MAPISession1.SignOn MAPIMessages1.SessionID = MAPISession1.SessionID MAPIMessages1.MsgIndex = -1 MAPIMessages1.Compose MAPIMessages1.Send True MAPISession1.SignOff End Sub That’s it—we’ve sent our email. What actually happens is that the program sends the new email message to the user’s Outbox (which is also opened when you open the Inbox), and the Outbox is usually set to send email automatically. In fact, that’s the way the Microsoft Exchange usually works: by logging into the mail server you’ve specified at regular intervals. When it logs in, it sends the mail waiting in the Outbox and reads any waiting email, placing it in the Inbox. (In fact, now that we’ve sent email, we’ll see how to read that email in the next topic.) The code for this example, email.frm version 1 (version 2, which is located on this book’s accompanying CD-ROM, will let the user read email as well), appears in Listing 21.3. Visual Basic 6 Black Book:Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML http://24.19.55.56:8080/temp/ch21\719-723.html (3 of 4) [3/14/2001 2:00:43 AM] Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Visual Basic 6 Black Book:Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML http://24.19.55.56:8080/temp/ch21\719-723.html (4 of 4) [3/14/2001 2:00:43 AM] Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Listing 21.3 email.frm version 1 VERSION 6.00 Object = "{20C62CAE-15DA-101B-B9A8-444553540000}#1.1#0"; "MSMAPI32.OCX" Begin VB.Form Form1 Caption = "Form1" ClientHeight = 3405 ClientLeft = 60 ClientTop = 345 ClientWidth = 5970 LinkTopic = "Form1" ScaleHeight = 3405 ScaleWidth = 5970 StartUpPosition = 3 'Windows Default Begin VB.TextBox Text1 Height = 2175 Left = 240 MultiLine = -1 'True ScrollBars = 3 'Both TabIndex = 2 Top = 120 Width = 5415 End Begin VB.CommandButton Command2 Caption = "Read email" Height = 495 Left = 360 TabIndex = 1 Top = 2520 Width = 1215 End Begin MSMAPI.MAPISession MAPISession1 Left = 1440 Top = 1920 _ExtentX = 1005 _ExtentY = 1005 _Version = 393216 DownloadMail = -1 'True LogonUI = -1 'True NewSession = 0 'False End Begin MSMAPI.MAPIMessages MAPIMessages1 Left = 2640 Top = 1920 _ExtentX = 1005 _ExtentY = 1005 Visual Basic 6 Black Book:Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML http://24.19.55.56:8080/temp/ch21\723-727.html (1 of 4) [3/14/2001 2:00:48 AM] Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com _Version = 393216 AddressEditFieldCount= 1 AddressModifiable= 0 'False AddressResolveUI= 0 'False FetchSorted = 0 'False FetchUnreadOnly = 0 'False End Begin VB.CommandButton Command1 Caption = "Send email" Height = 495 Left = 4320 TabIndex = 0 Top = 2520 Width = 1215 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Sub Command1_Click() MAPISession1.DownLoadMail = False MAPISession1.SignOn MAPIMessages1.SessionID = MAPISession1.SessionID MAPIMessages1.MsgIndex = -1 MAPIMessages1.Compose MAPIMessages1.Send True MAPISession1.SignOff End Sub Private Sub Command2_Click() MAPISession1.DownLoadMail = True MAPISession1.SignOn MAPIMessages1.SessionID = MAPISession1.SessionID MAPIMessages1.Fetch MAPIMessages1.MsgIndex = 0 Text1.Text = MAPIMessages1.MsgNoteText MAPISession1.SignOff End Sub Visual Basic 6 Black Book:Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML http://24.19.55.56:8080/temp/ch21\723-727.html (2 of 4) [3/14/2001 2:00:48 AM] Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Reading Email In Visual Basic Now that we’ve seen how to send email (see the previous topic), how do you read email? You set the MAPISession control’s DownLoadMail property to True. Let’s see an example. In this case, we’ll download any waiting email into the user’s Inbox and then display the first message in a text box. We’ll use the program we started in the previous topic and add the code we need to the Read Email button’s event handler. First, we set the MAPISession control’s DownLoadMail property to True, then we use that control’s SignOn method to start the MAPI session and download any waiting email into the Inbox: Private Sub Command2_Click() MAPISession1.DownLoadMail = True MAPISession1.SignOn Now that the email is in the Inbox, how do we reach it? We use the MAPIMessages control’s Fetch method to create a message set (you can find out how many messages are in the set with the MsgCount property). To do that, we first set the MAPIMessages control’s SessionID property to the MAPISession control’s SessionID property and then use Fetch: Private Sub Command2_Click() MAPISession1.DownLoadMail = True MAPISession1.SignOn MAPIMessages1.SessionID = MAPISession1.SessionID MAPIMessages1.Fetch Next, we display the text of the first email message now in the Inbox by setting the MAPIMessages control’s MsgIndex to 0 and using the MsgNoteText property. (Note that in a real email program, you should check to make sure there really are messages waiting here, but in this case we assume there are because we just sent one using the Send Email button—note that if your system takes significant time to deliver email messages, you might have to alter this code.) Finally we sign off the MAPI session: Private Sub Command2_Click() MAPISession1.DownLoadMail = True MAPISession1.SignOn MAPIMessages1.SessionID = MAPISession1.SessionID MAPIMessages1.Fetch MAPIMessages1.MsgIndex = 0 Text1.Text = MAPIMessages1.MsgNoteText MAPISession1.SignOff Visual Basic 6 Black Book:Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML http://24.19.55.56:8080/temp/ch21\723-727.html (3 of 4) [3/14/2001 2:00:48 AM] Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com End Sub And that’s it—we can now receive email, as you see in Figure 21.13. Now we’re sending and receiving email with Visual Basic. Figure 21.13 Receiving email. The code for this example is located in the email folder on this book’s accompanying CD-ROM. Visual Basic 6 Black Book:Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML http://24.19.55.56:8080/temp/ch21\723-727.html (4 of 4) [3/14/2001 2:00:48 AM] Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Using The Internet Transfer Control For FTP And HTTP Operations You use the Microsoft Internet transfer control to handle FTP and HTTP operations in Visual Basic. Using the HTTP protocol, you can connect to World Wide Web servers to retrieve HTML documents. With the FTP protocol, you can log on to FTP servers to download and upload files. The UserName and Password properties allow you to log on to private servers that require authentication. Otherwise, you can connect to public FTP servers and download files. The common FTP commands, such as CD and GET, are supported through the Execute method. You can keep track of the Internet transfer control’s operations with the StillExecuting property. If this property is True, the control is working on a transfer and will not respond to other actions. The Internet transfer control performs asynchronous Internet transfers, so besides the StillExecuting property, Microsoft has given the control a StateChanged event. In this event’s handler procedure, you are kept up-to-date on what’s going on with the Internet transfer control: Private Sub object_StateChanged(ByVal State As Integer) End Sub The State argument can take these values: • icNone—0; no state to report. • icHostResolvingHost—1; the control is looking up the IP address of the specified host computer. • icHostResolved—2; the control successfully found the IP address of the specified host computer. • icConnecting—3; the control is connecting to the host computer. • icConnected—4; the control successfully connected to the host computer. • icRequesting—5; the control is sending a request to the host computer. • icRequestSent—6; the control successfully sent the request. • icReceivingResponse—7; the control is receiving a response from the host computer. • icResponseReceived—8; the control successfully received a response from the host computer. • icDisconnecting—9; the control is disconnecting from the host computer. • icDisconnected—10; the control successfully disconnected from the host computer. • icError—11; an error occurred in communicating with the host computer. • icResponseCompleted—12; the request has completed and all data has been received. Note that when a request is finished, the State argument in the StateChanged event will be set to icResponseCompleted, and it’s safe to execute another command with the Internet transfer control. To add an Internet transfer control to a program, follow these steps: 1. Select the Project|Components menu item. 2. Click the Controls tab in the Components dialog box that opens. Visual Basic 6 Black Book:Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML http://24.19.55.56:8080/temp/ch21\727-729.html (1 of 3) [3/14/2001 2:00:55 AM] Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 3. Select the entry labeled Microsoft Internet Transfer Control. 4. Click on OK to close the Components dialog box to add the Microsoft Internet Transfer Control tool to the toolbox. 5. Double-click the Microsoft Internet Transfer Control tool to the toolbox and add that control to your form. This control is invisible at runtime, so its size and location are not important. 6. Add the code you want to use with the control to your program. When you start an FTP or HTTP operation with the Internet transfer control, the control will connect to the Internet (using the user’s system defaults) if the computer is not already connected. TIP: For a complete FTP file upload example, including using the StateChanged event, see our online application registration example in Chapter 30. Now that we’ve added an Internet transfer control to a program, we’ll put that control to work in the next few topics. Handling FTP Operations In Visual Basic There are two ways of handling FTP operations with the Microsoft Internet transfer control: using the OpenUrl method and using the Execute method. The OpenUrl method lets you download files and uses the FTP protocol if the URL you specify begins with ftp:// (for example, “ftp://ftp.microsoft.com/file.txt”); here’s how you use OpenUrl: InetControl.OpenUrl url [, datatype] The datatype argument can either be icString (the default) for text data or icByteArray for binary data. If you use icString, OpenUrl returns a string; if you use icByteArray, OpenUrl returns a byte array. The Execute method can execute FTP commands. Here’s how you use Execute: InetControl.Execute url, operation, data, requestHeaders Here’s what the arguments to Execute mean: • url—String that specifies the URL to which the control should connect. If no URL is specified here, the URL specified in the URL property will be used. • operation—String that specifies the type of operation to be executed. • data—String that specifies the data for operations. • requestHeaders—String that specifies additional headers to be sent from the remote server. The format for these is header name: header value vbCrLf. The FTP commands that you can use with the Internet transfer control and what they do appear in Table 21.3. Visual Basic 6 Black Book:Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML http://24.19.55.56:8080/temp/ch21\727-729.html (2 of 3) [3/14/2001 2:00:55 AM] Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Visual Basic 6 Black Book:Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML http://24.19.55.56:8080/temp/ch21\727-729.html (3 of 3) [3/14/2001 2:00:55 AM] Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com [...]... Figure 21. 16 When you click the Read HTML button, the program downloads the Microsoft Visual Basic Web page and displays it in the text box, as shown in Figure 21. 16 When you click the Read Binary button, the program downloads the home.gif file onto disk Our http program is a success http://24.19.55. 56: 8080/temp/ch21 \73 4 -73 8.html (2 of 3) [3/14/2001 2:00:58 AM] Visual Basic 6 Black Book :Visual Basic And... http://24.19.55. 56: 8080/temp/ch22 \75 0 -75 3.html (3 of 4) [3/14/2001 2:01:15 AM] Visual Basic 6 Black Book: Multimedia command before closing the control to save the recorded data to disk (in the file whose name you’ve specified in the FileName Split Unregistered Version - http://www.simpopdf.com Simpo PDF Merge and property) http://24.19.55. 56: 8080/temp/ch22 \75 0 -75 3.html (4 of 4) [3/14/2001 2:01:15 AM] Visual Basic 6. .. Playing WAV files from Visual Basic The code for this example is located in the wavplayer folder on this book s accompanying CD-ROM http://24.19.55. 56: 8080/temp/ch22 \75 3 -75 7.html (4 of 4) [3/14/2001 2:01:23 AM] Visual Basic 6 Black Book: Multimedia Playing MID Files Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Can you play MID format sound files from Visual Basic? You sure can,... HTML”, and Command2, with the caption “Read binary” http://24.19.55. 56: 8080/temp/ch21 \73 4 -73 8.html (1 of 3) [3/14/2001 2:00:58 AM] Visual Basic 6 Black Book :Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML When the user clicks Command1, the Read HTML button, we just download the raw HTML of the Microsoft Visual Basic Web pageUnregistered it in the - http://www.simpopdf.com OpenURL... it—now run the program as shown in Figure 22 .6 As you can see in that figure, the program plays the AVI in the picture box Our multimedia animation example is a success http://24.19.55. 56: 8080/temp/ch22 \75 7- 76 1 .html (3 of 4) [3/14/2001 2:01:33 AM] Visual Basic 6 Black Book: Multimedia Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Figure 22 .6 Playing AVI files with the multimedia... http://www.simpopdf.com Figure 22 .6 Playing AVI files with the multimedia control The code for this example is located in the aviplayer folder on this book s accompanying CD-ROM http://24.19.55. 56: 8080/temp/ch22 \75 7- 76 1 .html (4 of 4) [3/14/2001 2:01:33 AM] Visual Basic 6 Black Book: Multimedia Playing MPG Files Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com The Testing Department is calling... Package and Deployment Wizard included with Visual Basic (see Chapter 30) provides tools to help you write setup programs that install your applications correctly That’s it for the overview of multimedia for the moment It’s time to turn to our Immediate Solutions http://24.19.55. 56: 8080/temp/ch22 \73 9 -74 2.html (2 of 3) [3/14/2001 2:01:02 AM] Visual Basic 6 Black Book: Multimedia Simpo PDF Merge and Split... = "Seeking." Case mciModePlay strMode = "Playing." Case mciModeRecord strMode = "Recording." Case mciModePause strMode = "Paused." End Select http://24.19.55. 56: 8080/temp/ch22 \75 7- 76 1 .html (1 of 4) [3/14/2001 2:01:33 AM] Visual Basic 6 Black Book: Multimedia Label1.Caption = strMode Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com End Sub Finally, we stop playback (if it hasn’t... Sub Form_Load() MMControl1.FileName = "C:\windows\help\scroll.avi" MMControl1.hWndDisplay = Picture1.hWnd MMControl1.Command = "Open" End Sub http://24.19.55. 56: 8080/temp/ch22 \75 7- 76 1 .html (2 of 4) [3/14/2001 2:01:33 AM] Visual Basic 6 Black Book: Multimedia Now when users click the buttons in the multimedia control, they can play, stop, and restart the AVI file as they like The animation appears in... Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com http://24.19.55. 56: 8080/temp/ch22 \73 9 -74 2.html (3 of 3) [3/14/2001 2:01:02 AM] Visual Basic 6 Black Book: Multimedia Immediate Solutions Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com Using The Animation Control Visual Basic comes with an animation control, and we’ll start our multimedia operations by taking . 264 0 Top = 1920 _ExtentX = 1005 _ExtentY = 1005 Visual Basic 6 Black Book :Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML http://24.19.55. 56: 8080/temp/ch21 72 3 -72 7.html. MAPISession1.SignOff End Sub Visual Basic 6 Black Book :Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML http://24.19.55. 56: 8080/temp/ch21 72 3 -72 7.html (2 of 4) [3/14/2001. MAPIMessages1.MsgNoteText MAPISession1.SignOff Visual Basic 6 Black Book :Visual Basic And The Internet: Web Browsing, Email, HTTP, FTP, And DHTML http://24.19.55. 56: 8080/temp/ch21 72 3 -72 7.html (3 of 4) [3/14/2001

Ngày đăng: 14/08/2014, 01:20

Từ khóa liên quan

Mục lục

  • Visual Basic 6 Black Book

    • Table of Contents

    • Introduction

    • Whats on the CD-Rom

    • About the Author

    • Chapter 1 - Visual Basic Overview

      • Chapter 1 - Continued

      • Chapter 1 - Continued

      • Chapter 1 - Continued

      • Chapter 1 - Continued

      • Chapter 1 - Continued

      • Chapter 1 - Continued

      • Chapter 1 - Continued

      • Chapter 2 - The Visual Basic Development Environment

        • Chapter 2 - Continued

        • Chapter 2 - Continued

        • Chapter 2 - Continued

        • Chapter 2 - Continued

        • Chapter 2 - Continued

        • Chapter 2 - Continued

        • Chapter 2 - Continued

        • Chapter 3 - The Visual Basic Language

          • Chapter 3 - Continued

          • Chapter 3 - Continued

Tài liệu cùng người dùng

Tài liệu liên quan