Danh mục

Chương 3: Một số kỹ thuật trong lập trình trên .Net CF

Số trang: 16      Loại file: ppt      Dung lượng: 631.00 KB      Lượt xem: 4      Lượt tải: 0    
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tài liệu tham khảo của ThS. Trần Minh Triết, trường Đại học khoa học tự nhiên, đại học quốc gia TP.Hồ Chí Minh - Khoa Công nghệ thông tin
Nội dung trích xuất từ tài liệu:
Chương 3: Một số kỹ thuật trong lập trình trên .Net CFĐại học Khoa học Tự nhiên, ĐHQG-HCM Khoa Công Nghệ Thông Tin Chương 3: Một số kỹ thuậttrong lập trình trên .Net CF ThS. Trần Minh Triết 1 1Xác định đường dẫn của Ứng dụng Lấy danh sách các Assembly Xác định tự động đường dẫn của ứng dụng (runtime)m_startuppath= Trọn vẹn tên vàSystem.Reflection.Assembly.GetExecutingAssembly(). của đường dẫn moduleGetModules()[0].FullyQualifiedName;m_startuppath=m_startuppath.Replace( Xóa tên file,System.Reflection.Assembly.GetExecutingAssembly(). giữ lại chỉ đường dẫnGetModules()[0].Name,);m_BmBanCo=newBitmap Tên của module(m_startuppath+BanCoPocketPC.jpg);m_BmQuanCo=newBitmap(m_startuppath+QuanCoPocKetPC.bmp);m_BmChonCo=newBitmap(m_startuppath+ChonQuanPocketPC.bmp); 2 2 Xác định đường dẫn của Ứ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) sẽ chứa chương trình thực thipublicclassConstant{ publicstaticintLEFT=24; publicstaticintTOP=24; publicstaticstringAppPath=@\ProgramFiles\MummyMaze\; publicstaticstringImagesPath=@\ProgramFiles\MummyMaze\;} 3 3 Load ảnh từ file Có thể load các ả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…)BitmapRedMummyBmp=newBitmap(Constant.ImagesPath+redmummy.bmp);BitmapHelloBmp=newBitmap(Constant.ImagesPath+hello.jpg); 4 4 Sử dụng Timer (1) Khai báo biến thuộc kiểu System.Windows.Forms.TimerprivateSystem.Windows.Forms.TimerMyTimer; Khởi tạo biến TimerprivatevoidInitializeComponent(){this.MyTimer=newSystem.Windows.Forms.Timer(); this.MyTimer.Interval=300;//300ms this.MyTimer.Tick+=newSystem.EventHandler(this.MyTimer_Func);} Tên hàm xử lý Timer 5 5Sử dụng Timer (2) Hàm xử lý mỗi khi xảy ra biến cố timerprivatevoidMyTimer_Func(objectsender,System.EventArgse){ flag=1flag; pictureBox1.Image=CompleteBmp[flag]; pictureBox1.Refresh();} 6 6 Sử dụng Timer (3) Kích hoạt timerMyTimer.Enabled=true; Tạm dừng timerMyTimer.Enabled=false; Hủy bỏ timerMyTimer.Dispose(); 7 7Sử dụng GraphicspublicvoidDraw(Graphicsg){ ImageAttributesimgatt=newImageAttributes(); imgatt.SetColorKey (Constant.BkColor,Constant.BkColor); g.DrawImage( HumanBmp, newRectangle(left,top,width,height), Bmp_x*Constant.WidthSquare_pixel, Bmp_y*Constant.WidthSquare_pixel, Constant.WidthSquare_pixel, Constant.WidthSquare_pixel, GraphicsUnit.Pixel,imgatt);} 8 8 Sử dụng Thread Khai báo biến kiểu ThreadprivateThreadSoundThread; Tên hàm xử lý chính Tạo thread và khởi động thread của ThreadprivatevoidPlaySound(){ SoundThread= newThread(newThreadStart(PlaySoundFunc)); SoundThread.Priority=ThreadPriority.Highest; SoundThread.Start();// Bắt đầu thread} Hàm xử lý chính của ThreadprivatevoidPlaySoundFunc(){ Sound.PlayMusic(Constant.AppPath+music.wav);} 9 9 Xử lý Âm thanh (1)publicclassSound{ [DllImport(WinMM.dll, EntryPoint=PlaySound,CharSet=CharSet.Auto)] privatestaticexternintPlaySoundWin32 (stringpszSound,inthmod,intfdwSound); [DllImport(CoreDll.dll, EntryPoint=PlaySound,CharSet=CharSet.Auto)] privatestaticexternintPlaySoundWinCE (stringpszSound,inthmod,intfdwSound);......... 10 10 Xử lý Âm thanh (2)privateenumSND{ SND_SYNC =0x0000, /*playsynchronously(default)*/ SND_ASYNC =0x0001, /*playasynchronously*/ SND_NODEFAULT =0x0002, /*silence(!default)ifsoundnotfound*/ SND_MEMORY =0x0004, /*pszSoundpointstoamemoryfile*/ SND_LOOP =0x0008, /*loopthesounduntilnextsndPlaySound*/ 11 ...

Tài liệu được xem nhiều: