Bài giảng Một số kỹ thuật trong lập trình trên .Net Compact FrameWork (CF)

101 35 0
Bài giảng Một số kỹ thuật trong lập trình trên .Net Compact FrameWork (CF)

Đ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

Bài giảng Một số kỹ thuật trong lập trình trên .Net Compact FrameWork (CF) trình bày tổng quan về .NET Compact FrameWork; các thư viện lớp đối tượng được hỗ trợ; những khác biệt chính với .Net FrameWork; Smart Device Extensions; vai trò của trình giả lập Pocket PC và một số nội dung khác.

Một số kỹ thuật lập trình Net Compact FrameWork (CF) Tổng quan NET Compact FrameWork Các thư viện lớp đối tượng hỗ trợ Những khác biệt với Net FrameWork Các thư viện lớp đối tượng hỗ trợ Những khác biệt với Net FrameWork Giới thiệu Smart Device Extensions Lựa chọn target platform Vai trị trình giả lập Pocket PC Vai trị trình giả lập Pocket PC Cung cấp máy tính ảo chạy máy tính cá nhân thơng thường Tạo phần cứng (ảo) chạy Mircosoft Windows CE máy tính Sử dụng hệ điều hành Windows CE component Pocket PC Đảm bảo tương đồng thiết bị PocketPC thật thiết bị giả lập Xác định đường dẫn Ứng dụng  Xác định tự động đường dẫn ứng dụng (runtime) m_startuppath = Trọn vẹn tên System.Reflection.Assembly.GetExecutingAssembly() GetModules()[0].FullyQualifiedName; m_startuppath = m_startuppath.Replace( đường dẫn module Xóa tên file, System.Reflection.Assembly.GetExecutingAssembly() giữ lại GetModules()[0].Name, "" ); m_BmBanCo =new Bitmap đường dẫn Tên module (m_startuppath+"BanCoPocketPC.jpg"); m_BmQuanCo=new Bitmap (m_startuppath+"QuanCoPocKetPC.bmp"); m_BmChonCo=new Bitmap Xác định đường dẫn Ứng dụng  Sử dụng đường dẫn tuyệt đối (hard-code)!!!  Phải biết trước đường dẫn (tuyệt đối) chứa chương trình thực thi public class Constant { public static int LEFT = 24; public static int TOP = 24; public static string AppPath = @"\Program Files\MummyMaze\"; public static string ImagesPath = @"\Program Files\MummyMaze\"; Load ảnh từ file  Có thể load ảnh từ file vào đối tượng kiểu Bitmap  Các định dạng ảnh thông dụng mà WinCE hỗ trợ (BMP, JPG, PNG…) Bitmap RedMummyBmp = new Bitmap(Constant.ImagesPath+"redmummy.bmp"); Bitmap HelloBmp = new Bitmap(Constant.ImagesPath+"hello.jpg"); Sử dụng Timer (1)  Khai báo biến thuộc kiểu System.Windows.Forms.Timer  Khởi tạo biến Timer private System.Windows.Forms.Timer MyTimer; private void InitializeComponent() { this.MyTimer = new System.Windows.Forms.Timer(); this.MyTimer.Interval = 300; // 300 ms this.MyTimer.Tick += new System.EventHandler(this.MyTimer_Func); } Tên hàm xử lý Timer Các bước sử dụng Microsoft.WindowsMobile.PocketOutlook  Tạo session Outlook mới: OutlookSession aSession = new OutlookSession();  Truy cập đối tượng PIM: Các property cho phép gửi e-mail e-mail, SMS message, thao tác liệu PIM:  Appointments  Contacts  Tasks  EmailAccounts  SmsAccount  Chấm dứt session Outlook (bắt buộc khơng thể gabage collector tự động xử lý) aSession.Dispose(); Ví dụ TaskCollection taskItems = aSession.Tasks.Items; foreach (Task t in taskItems) { Messagebox.Show(t.subject); } Tạo email  Tạo session OutlookSession aSession = new OutlookSession();  Chọn sử dụng account email có EmailAccount anEmailAcct = aSession.EmailAccounts[1]; EmailAccount anEmailAcct = aSession.EmailAccounts["IMAP4"]; Tạo email  Xác định người nhận Recipient recv = new Recipient("FirtName LastName", "FLastName@somewhere.com");  Tạo email EmailMessage mesg = new EmailMessage(); mesg.To.Add(recv); mesg.Subject = "Hello"; mesg.BodyText = "Dear readers, we hope you enjoy learning Smartphone programming"; anEmailAcct.Send(mesg); Tạo email có attachment // Create a new Select Picture dialog box SelectPictureDialog picDlg = new SelectPictureDialog(); picDlg.InitialDirectory = @"\Images"; // Do not forward // a Digital Rights Management protected file picDlg.ShowForwardLockedContent = false; // Get the dialog result DialogResult result = picDlg.ShowDialog(); Tạo email có attachment //Create a new email message EmailMessage mesg = new EmailMessage(); mesg.Subject = "Email with Picture Attachment"; mesg.BodyText = "Open the attachment No virus"; //Create and add a new recipient Recipient resv = new Recipient("John Doe","JDoe@somewhere.com"); mesg.To.Add(resv); Tạo email có attachment //Add the picture to the attachment Attachment picture = new Attachment (picDlg.FileName); mesg.Attachments.Add(picture); //Use the default email account EmailAccount myEmail = aSession.EmailAccounts[0]; //Display the email compose form MessagingApplication.DisplayComposeForm(myEmail,mesg); Thao tác với thông tin PIM OutlookSession CalSess = new OutlookSession();  Cách truy cập thông tin Appointment: AppointmentCollection CalCol = CalSess.Appointments.Items;  Cách truy cập thông tin Task: TaskCollection TCol = CalSess.Tasks.Items;  Cách truy cập thơng tin Contact: ContactCollection TCol = CalSess.Contacts.Items; Ví dụ //Establish a new Outlook session OutlookSession CalSess = new OutlookSession(); //Get the collection of appointments by calling outlookSession.Appointments.Items AppointmentCollection CalCol = CalSess.Appointments.Items; Ví dụ //Add each appointment to the ListView foreach (Appointment apt in CalCol) { //Create one new ListView object for each appointment ListViewItem aLVItem = new ListViewItem(); //Make the appointment date the text property of this ListView aLVItem.Text = apt.Start.Date.ToString(); //Make other appointment property as the subitem aLVItem.SubItems.Add(apt.Subject); //You can also add a field for the appointment location aLVItem.SubItems.Add(apt.Location); //Add ListViewItem to the ListView CalView.Items.Add(aLVItem); } Chọn lọc thông tin string query = "[Categories] == wrox"; AppointmentCollection wroxAppt = aOutlookSession.Appointment.Items.restrict(query); Lưu ý: phép so sánh string query = "[Location] Ball State University"; Những appointment item khơng có thông tin Location bị loại bỏ!!! Gửi SMS OutlookSession aSession = new OutlookSession(); SmsMessage sendMsg = new SmsMessage("18664365702", "Vote to Idol #2"); aSession.SmsAccount.Send(sendMsg); aSession.Dispose(); Account nào??? Gửi SMS SmsMessage sendMsg = new SmsMessage(); Recipient recv = new Recipient("18664365702"); sendMsg.Body = "Vote to Idol #2"; sendMsg.To.Add (recv); MessagingApplication.DisplayComposeForm(sendMsg) Nhận SMS using Microsoft.WindowsMobile.PocketOutlook.MessageInterception; msginterceptor = new MessageInterceptor(); msginterceptor.InterceptionAction = InterceptionAction.NotifyAndDelete; // Notify msginterceptor.MessageReceived += new MessageInterceptorEventHandler(msginterceptor_MessageReceived); Nhận SMS //Handling received message void msginterceptor_MessageReceived(object sender, MessageInterceptorEventArgs e) { SmsMessage smsMsg = (SmsMessage)e.Message; string fullText = "Message From: “+smsMsg.From.Name; fullText += (" at "+ smsMsg.Received.TimeOfDay.ToString()); fullText += (" and the message is: "+smsMsg.Body); MessageBox.Show(fullText, "New Text Message !"); } ... } Thao tác đồ họa Net Compact Framework Tham khảo  NET Compact Framework Programming with C#, Paul Yao, David Durant (2004), Prentice Hall PTR  Chương 15 - Net Compact Framework Graphics  Chương... FrameWork Giới thiệu Smart Device Extensions Lựa chọn target platform Vai trò trình giả lập Pocket PC Vai trị trình giả lập Pocket PC Cung cấp máy tính ảo chạy máy tính cá nhân thơng thường Tạo phần...Tổng quan NET Compact FrameWork Các thư viện lớp đối tượng hỗ trợ Những khác biệt với Net FrameWork Các thư viện lớp đối tượng hỗ trợ Những khác biệt với Net FrameWork Giới thiệu Smart

Ngày đăng: 08/05/2021, 16:41

Mục lục

  • Một số kỹ thuật trong lập trình trên .Net Compact FrameWork (CF)

  • Tổng quan về .NET Compact FrameWork

  • Các thư viện lớp đối tượng được hỗ trợ

  • Những khác biệt chính với .Net FrameWork

  • Giới thiệu về Smart Device Extensions

  • Vai trò của trình giả lập Pocket PC

  • Xác định đường dẫn của Ứng dụng

  • Slide 8

  • Load ảnh từ file

  • Sử dụng Timer (1)

  • Sử dụng Timer (2)

  • Sử dụng Timer (3)

  • Sử dụng Graphics

  • Sử dụng Thread

  • Xử lý Âm thanh (1)

  • Xử lý Âm thanh (2)

  • Xử lý Âm thanh (3)

  • Xử lý Âm thanh (4)

  • Xử lý Âm thanh (5)

  • Xử lý Âm thanh (6)

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

Tài liệu liên quan