µ±Ç°Î»ÖÃ:Ê×Ò³>>¿ª·¢±à³Ì>>VS.NET>>ÐÂÎÅÄÚÈÝ
΢Èí.NET¾«¼ò¿ò¼Ü(NETCF)×î³£¼ûÎÊÌâ
×÷Õß: ·¢²¼Ê±¼ä:2006-10-21 15:43:03 ÎÄÕÂÀ´Ô´:΢Èí

´ËFAQµÄÄÚÈÝ£¬Ò»²¿·ÖÀ´×Ô net¾«¼ò¿ò¼ÜÐÂÎÅ×é (microsoft.public.dotnet.framework.compactframework)ÕÅÌùºÍ»Ø´ðµÄÎÊÌâ¡£.net¾«¼ò¿ò¼Ü¿ª·¢Ð¡×é¸Ðлÿһλ²ÎÓëÐÂÎÅ×éµÄÈËÊ£¬¸ÐлËûÃǶÔFAQ±àдµÄ»ý¼«²ÎÓëºÍ¶ÔFAQµÄͶ¸å¡£

ÒªÉêÇëÌí¼ÓFAQÏîÄ¿£¬Çë·¢Óʼþµ½ netcffaq@microsoft.com.

1. ¿ª·¢

1.1. ʲôÊÇ΢Èí .net¾«¼ò¿ò¼Ü£¿
1.2. ÎÒÐèҪʲô¹¤¾ß²ÅÄÜ¿ª·¢.net¾«¼ò¿ò¼ÜµÄÓ¦Óã¿
1.3. ÄÄÀï¿ÉÒÔÏÂÔØ×îÐµĹ¤¾ßºÍÏà¹ØÈí¼þ£¿
1.4. .net¾«¼ò¿ò¼ÜÖ§³ÖЩʲôÉ豸£¿
1.5. .net¾«¼ò¿ò¼ÜÒÔºó½«Ö§³ÖʲôÉ豸£¿
1.6. µ÷ÊÔ³ÌÐòʱΪʲô»á³öÏÖ¡°ÓëÄ£ÄâÆ÷½¨Á¢Á¬½Óʧ°Ü¡±µÄ´íÎó(¸Õ¿ªÊ¼Ö´ÐгÌÐòµÄʱºò)£¿
1.7. .net¿ò¼ÜºÍ.net¾«¼ò¿ò¼ÜÖ®¼äÓÐÊ²Ã´Çø±ð£¿
1.8. .net¾«¼ò¿ò¼ÜµÄ²¹¶¡ÓÐʲô¸Ä½ø£¿
1.9. Poclet PCÉϵÄ.net¾«¼ò¿ò¼Ü¿ª·¢ºÍWindows CE .NETÉϵÄ.net¾«¼ò¿ò¼Ü¿ª·¢ÓÐʲô²»Í¬£¿
1.10. ÄÄÀïÓиü¶àµÄ¹ØÓÚ½¨Á¢.net¾«¼ò¿ò¼ÜÉϵÄÓ¦ÓóÌÐòµÄÐÅÏ¢£¿
1.11. .net¾«¼ò¿ò¼ÜµÄÎĵµÔÚÄÄÀ
1.12. ÔõÑùÉèÖòŲ»»áÔÚÿ´Îµ÷ÊÔµÄʱºò°ÑËùÉæ¼°µÄÎļþ¶¼¿½±´µ½É豸ÉÏ£¿
1.13. ÔõÑùÉèÖÃÄ£ÄâÆ÷µÄÊôÐÔ£¿
1.14. Ôõôµ÷ÊÔ.net¾«¼ò¿ò¼ÜµÄÓ¦ÓóÌÐò£¿
1.15. ÔõÑù¿ªÊ¼Ê¹ÓÃVisual Basic .NET¿ª·¢.net¾«¼ò¿ò¼ÜµÄ³ÌÐò£¿
1.16. ÔõÑù²ÅÄܰÑ.net¾«¼ò¿ò¼Ü°²×°µ½×°Å伯ÖÐ(GAC)£¿
1.17. µ±´ÓVisual Studio .NET 2003Öз¢²¼³ÌÐòµ½É豸ÉϵÄʱºò£¬ÔõÑù´¦Àí"Sharing Violation"£¿
1.18. ʲôÊÇcommon language runtime (CLR)?
1.19. ʲôÊÇGlobal Assembly Cache (GAC)?
1.20. ÔÚ.net¾«¼ò¿ò¼ÜÏÂÄÚ´æ¹ÜÀíÊÇÔõÑùµÄ£¿
1.21. µ±ÎÒµÄÍøÂçЭÒéÊý³¬¹ý50¸öµÄʱºò£¬ÎªÊ²Ã´²»ÄÜÏò·¢²¼³ÌÐò£¿
1.22. Ϊʲô»áÓÐ¿çÆ½Ì¨´úÂ룿
1.23. ÕâЩARMÖ¸Áî´ú±íʲô£¿
1.24. ÔõÑùдע²á±í£¿
1.25. How can I prevent .CAB files from being deleted after installation?
1.26. How can I determine the version of the .NET Compact Framework that is installed on a device?
1.27. How do I copy files to the emulator?
1.28. Why does installation of the PocketPC 2002 SDK fail?
1.29. How do I debug a Web service consumed by a Smart Device application?
1.30. What is the footprint of the .NET Compact Framework?
1.31. How do I include imgdecmp.dll in an emulator image?
1.32. How do I programmatically replace Assemblies in the Global Assembly Cache (GAC)?
1.33. How can I display Pocket PC applications on my desktop or laptop without needing any device side configuration?
1.34. How can I allow Activesync to connect to an Emulator session from Visual Studio .NET 2003?
1.35. How can I copy files to the device currently connected to desktop ActiveSync?
1.36. How can I stress test user input?
1.37. Where can I get a UI version of the Platform Builder Target Control Window?
1.38. Where can I get a Command shell for Pocket PC 2003 devices?
1.39. How can I get detailed information about currently running processes?
1.40. How can I remotely start an application on a Pocket PC from my desktop?
1.41. Why can't I load different assemblies with the same name?
1.42. How can I force Visual Studio .NET 2003 to connect to newer versions of the Pocket PC 2003 emulator?
1.43. Why don't my custom controls show up properly in the toolbox?
2. ͼÐÎ
2.1. ÔõÑù½¨Á¢Ò»¸öͼÐζÔÏó£¿
2.2. ÔõÑùÓÅ»¯GDI+£¿
2.3. ÔõÑùÔÚ´°ÌåÉÏ»­Ò»¸öͼ°¸£¿
2.4. ÔõÑù»­Ò»¸ö´øÓÐ͸Ã÷É«µÄͼ°¸£¿
2.5. Ϊʲô´ÓTextBoxÉϵ÷ÓÃCreateGraphics»áʧ°Ü£¿
2.6. ÔõÑù»ñµÃÆÁÄ»ÉÏÎÄ×ֵĴóС£¿
2.7. Can I set the width of a pen?
2.8. How do I zoom an image?
2.9. Why can't I load an image?
3. ·¢²¼
3.1. ÔõÑù½¨Á¢Ò»¸öPocketPCµÄÉèÖóÌÐò£¿
3.2. Äĸö·¢²¼°ü¿ÉÒÔ°üÀ¨ÔÚÎҵݲװ³ÌÐòÖУ¿
3.3. ÔõÑù¿ÉÒÔ½¨Á¢Ò»¸ö²»ÐèÒª.net¿ò¼ÜµÄ°²×°³ÌÐò£¿
3.4. ÔõÑù½¨Á¢²»ÊÜPocketPCÏµÍ³Ô¼ÊøµÄCAB°²×°Îļþ£¿
3.5. Ϊʲô²»Í¬µÄ´¦ÀíÆ÷»áÓв»Í¬µÄCAB°²×°Îļþ£¿
3.6. How do I create a desktop installer that detects the presence of the .NET Compact Framework on the target device and installs it if necessary?
3.7. How do I deploy a .NET Compact Framework Service Pack to the emulator?
3.8. How do I include SQL Server CE with my application installation?
3.9. How do I use GAPI to create a graphics engine?
4. ͼÐÎÓû§½çÃæ(GUI): ´°Ìå
4.1. ÔõÑù½¨Á¢Ò»¸öÈ«ÆÁµÄ´°Ì壿
4.2. ʲôʱºòÓô°ÌåµÄ¹¹ÔìÆ÷£¿Ê²Ã´Ê±ºòÓô°ÌåµÄLoadʼþ£¿
4.3. ÔõÑù°Ñ×îС»¯°´Å¥»»³É¹Ø±Õ°´Å¥£¿
4.4. ÔõÑùÔÚ.net¾«¼ò¿ò¼ÜÉϽ¨Á¢¶à´°Ìåϵͳ½á¹¹£¿
4.5. ÔõÑùÌá¸ß.net¾«¼ò¿ò¼ÜÓ¦ÓóÌÐòµÄÔØÈëËÙ¶È£¿
4.6. ÔËÐÐʱÔõÑùÐ޸Ĵ°ÌåµÄ·ç¸ñ£¿
4.7. ÔõÑù¹ö¶¯´°ÌåµÄÄÚÈÝ£¿
4.8. ÔõÑùÖÆ×÷Ò»¸ö¸¡¶¯µÄ´°Ì壿ºÃÏóËùÓеĴ°Ìå×ÜÊÇÈ«ÆÁ״̬µÄ¡£
4.9. ÔõÑùÇ¿ÆÈÒ»¸ö´°Ìå±ä³É×îС»¯£¿
4.10. ÎÒÓÐÒ»¸ö°üº¬ºÜ¶à¿Ø¼þµÄÖÇÄÜÉ豸´°Ì壬ΪʲôÔËÐеÄʱºò³öÏÖ"NotSupportedException"´íÎó£¿
4.11. ÄĸöÊÇÕýÈ·¹Ø±Õ´°ÌåµÄ·½·¨£ºAppplication.Exit »¹ÊÇ Form.Close £¿
4.12. Why does showing a MessageBox on Windows Mobile 2003 for Smartphone with the Abort, Retry, and Fail set of buttons or the Yes, No, Cancel set of buttons, or the third button as the default button result in a NotSupportedException?
4.13 How do I get an icon in the Pocket PC Start Menu Most Recently Used (MRU) List?
4.14 How do I center a Form on the screen?
4.15 Why can't I show a Form that has been closed?
4.16 How can I enable multiple instances of an application?
5. ͼÐÎÓû§½çÃæ (GUI): ͨÓÃ
5.1. ÔõÑù½¨Á¢Ò»¸ö´øÓÐͼÐλòÖ§³Ö¶àÐеİ´Å¥£¿
5.2. TextBox.AcceptsReturnÔÚ.net¾«¼ò¿ò¼ÜÏÂÊÇÔõÑù¹¤×÷µÄ£¿
5.3. µ±Êý¾ÝÔØÈëComboBoxµÄʱºò£¬ÎªÊ²Ã´SelectedIndexChangedʼþûÓб»´¥·¢£¿
5.4. ShowºÍShowDialogÓÐʲô²»Í¬£¿
5.5. ΪʲôÎÒ²»Äܽ¨Á¢ÓÒ¼ü²Ëµ¥·ÖÀëÆ÷£¿(separator)
5.6. ÔËÐÐʱ°ÑImageList¸³¸øToolBarʱ£¬ÎªÊ²Ã´Í¼Ïó²»³öÏÖ£¿
5.7. ÔõÑù°Ñ¹â±êÉèÖóɵȴý״̬£¿
5.8. ÈçºÎÔڲ˵¥ÏîÖÐÏÔʾ·ûºÅ£º&£¿
5.9. ÈçºÎÖÆ×÷»ùÓÚ.net¾«¼ò¿ò¼ÜµÄ¶¯»­¿Ø¼þ£¿
5.10. ÈçºÎÔÚ.net¾«¼ò¿ò¼ÜÉÏÖÆ×÷×Ô¶¨Òå¿Ø¼þ£¿
5.11. ÈçºÎÖÆ×÷»ùÓÚ.net¾«¼ò¿ò¼ÜµÄ´øÍ¼Æ¬µÄ°´Å¥£¿
5.12. ÈçºÎʹÓÃ.net¾«¼ò¿ò¼ÜϵÄMessageWindowÀà¿â£¿
5.13. ÈçºÎÏòDataGridÖÐÌí¼ÓÐкÍÁУ¿
5.14. ÈçºÎʵÏÖDataGridµÄ±à¼­£¿
5.15. ÔõÑùÉèÖÃDataGridµÄDataSource£¿
5.16. ÔõÑù¶ÔDataGridµÄÁÐÅÅÐò£¿
5.17. ÔõÑù¶ÔListViewÖеÄÄÚÈÝÅÅÐò£¿
5.18. ÈçºÎʹÓà ÊäÈë°å(SIP)¿Ø¼þ£¿
5.19. ÈçºÎ×Ô¶¨Òåʼþ£¿
5.20. ÈçºÎ×öÒ»¸ö owner-drawn List Box?
5.21. ÈçºÎ×öÒ»¸ö¶àÑ¡¿òÅжÏÕæ¼Ù£¿
5.22. ÉèÖÃInputPanel.Enabled = trueµÄʱºòΪʲô³öÏÖÒì³££¿
5.23. Ϊʲô×Ô¶¨Òå¿Ø¼þ²»»á×Ô¶¯¼Ì³Ð¸¸ÀàµÄ×ÖÌ壿
5.24. Ϊʲôµ±ÊäÈë×Ö·ûʱ£¬NumericUpDown ºÍ DomainUpDown ¿Ø¼þ²»»áÒý·¢ ValueChanged ºÍ SelectedItemChanged ʼþ£¿
5.25. ΪʲôNumericUpDown¿Ø¼þÔö³¤µÄÖµ²»ÊÇÉèÖúõÄÖµ£¿
5.26. ΪʲôStatusBar²»ÄÜ·ÅÔÚ´°ÌåµÄÈÎÒâλÖã¿Ò»¶¨ÒªÔڵײ¿£¿
5.27. ΪʲôÎҵĿؼþ×Ô¶¯¼Ì³ÐÁ˸¸¿Ø¼þµÄ±³¾°É«£¿
5.28. ΪʲôNumericUpDown¿Ø¼þÄܽÓÊÜdecimalÀàÐ͵ÄÖµ£¬µ«²»»áÏÔʾ´óÓÚ2^16µÄÖµ£¿
5.29. Ϊʲô²»ÄÜÔÚDomainUpDown ÖÐÊäÈëÎÄ×Ö£¬¶øÒªÑ¡Ôñ£¿
5.30. ΪʲôOpenFileDialog±»ÏÞÖÆÔÚ"My Documents" Îļþ¼ÐÖУ¿
5.31. How can I activate the SIP (InputPanel) without a menu?
5.32. How do I add a subnode to every node in a TreeView?
5.33. How do I determine the number of rows or columns in a DataGrid?
5.34. How do I create a owner drawn Listbox?
5.35. How can I implement Control.GetNextControl under the .NET Compact Framework?
5.36. How do I get notified when the user clicks on a treeview node?
5.37. How do I set the title of a fullscreen multiline edit control window?
5.38. Why don' I see the validItem selected when I set ComboBox.SelectedValue to validItemInCollection?
5.39. How do I detect the location where a 'tap & hold' occurred to bring up a context menu on my custom control?
5.40. Why doesn't the scrollbar value ever get set to the maximum value?
5.41. How do I tab out of a custom control to the previous control?
5.42. How do I add Toolbar buttons with Transparency? 
6. Óë±¾µØ´úÂë(Native Code)Эͬ¹¤×÷
6.1. ÈçºÎµ÷Óñ¾µØÐ´µÄ£Ä£Ì£ÌÖеĺ¯Êý£¿
6.2. ÈçºÎʹÓÃdumpbin.exe°ïÖúÃèÊö P/Invokes?
6.3. ÈçºÎΪ΢Èí.net¾«¼ò¿ò¼Üд·ÇÍйܴúÂ룿
6.4. ÈçºÎµ÷Óà P/Invoke GetTickCount?
6.5. ÈçºÎ»ñµÃϵͳ»¹ÓжàÉÙ¿ÉÓÃÄڴ棿
6.6. ÈçºÎÊÇ´°¿ÚÒ»Ö±±£³Ö×îС»¯£¿
6.7. ÔÚ΢Èí.net¾«¼ò¿ò¼ÜÉϵ÷ÓÃϵͳº¯Êýʱ£¬ÈçºÎ×°ÅäÊý¾ÝÀàÐÍ£¿
6.8. ÈçºÎµÃµ½Ò»¸ö´°Ìå»ò¿Ø¼þµÄ¾ä±ú (HWND) £¿
6.9. ÈçºÎʹÓÃÐÔÄܼÆÊýÆ÷¹¦ÄÜ£¿
6.10. µ÷Óñ¾µØ´úÂëʱ£¬Êý¾ÝÀàÐÍÓÐʲôÏÞÖÆ£¿What are the limitations on marshalling types via P/Invoke?
6.11. µ÷ÓÃGetLastErrorʱ£¬×ÜÊÇ»ñµÃ²»¶¨µÄ´úÂ룿
6.12. µ÷Óñ¾µØ´úÂëʱ£¬ÓÐûÓвÎÊýÊýÁ¿µÄÏÞÖÆ£¿
6.13. µ÷Óñ¾µØ´úÂëʱ£¬ÎªÊ²Ã´µÃµ½"NotSupportedException"Òì³££¿
6.14. ÈçºÎ°Ñ byte[] ת»»³É IntPtr?
6.15. Why do I get a MissingMethodException when I call a function from a native DLL?
6.16. How do I set the system time?
6.17. How do I programmatically soft reset the device?
6.18. How can I put an icon on the title bar regardless of the which form is active?
6.19. How do I disable and capture hardware buttons?
6.20. How do I hide the start icon?
6.21. How do I enumerate, create, and terminate processes?
6.22. Where can I find a centralized library of P/Invoke samples?
6.23. How do I play and record .WAV audio files with the Waveform Audio Inteface? 
7. ͨÓÃ
7.1. ÈçºÎÈ·¶¨Ó¦ÓóÌÐòµÄÖ÷Ŀ¼£¿
7.2. ÈçºÎ¼ÆË㾫ȷµÄʱ¼ä¼ä¸ô£¿
7.3. ÈçºÎ°ÑǶÈëʽ×ÊÔ´µ±×÷Ò»¸öÁ÷(Stream)£¿
7.4. ΪʲôµÃµ½Ò»¸ö"An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in System.dll"µÄ´íÎó£¿
7.5. ÈçºÎʹÓÃÐÔÄܼàÊÓÆ÷£¿
7.6. ÈçºÎÈ¡ÏûÒ»¸ö³ÌÐòµÄ¹Ø±Õ£¿
7.7. ÈçºÎÔÚÎҵijÌÐòÖе÷ÓÃÁíÒ»¸öÓ¦ÓóÌÐò£¿
7.8. .net¾«¼ò¿ò¼ÜµÄÓ¦ÓóÌÐò»á½¨Á¢Ê²Ã´Ị̈߳¿
7.9. ÈçºÎ°ÑbyteÊý×éת»»³É½á¹¹Ì壿
7.10. ÎÒ¿ÉÒÔ½¨Á¢Ò»¸öίÍÐ(delegate)½»¸øInvokeÂð£¿
7.11. ÈçºÎÔÚ΢Èí.net¾«¼ò¿ò¼ÜÉÏʹÓõ绰API£¿
7.12. ÈçºÎÔÚPocket PcÉÏÉú³ÉGUID£¿
7.13. ÈçºÎÈÃÎÒµÄ.net¾«¼ò¿ò¼Ü³ÌÐòºÍPocket OutlookµÄÊý¾Ý½áºÏ£¿
7.14. ÎÒ¿ÉÒÔÅжÏ.net¾«¼ò¿ò¼ÜÖÐÒ»¸öÎļþµÄ°æ±¾Âð£¿
7.15. ΢Èí.net¾«¼ò¿ò¼ÜµÄºǫ́´¦ÀíÓÐʲôÏà¹Ø¼¼Êõ£¿
7.16. ÔÚ΢Èí.net¾«¼ò¿ò¼ÜÉÏʹÓöàÏß³ÌÓÐʲô¼¼ÇÉ£¿
7.17. ÈçºÎÔÚ ÖÇÄÜÉ豸ӦÓà ÖÐʹÓûìÏýÆ÷£¿
7.18. ÈçºÎʹÓÃÃÜÂë·þÎñ¶ÔÊý¾Ý½øÐмÓÃÜ»ò½âÃÜ£¿
7.19. ÈçºÎÔÚ΢Èí.net¾«¼ò¿ò¼ÜÉÏ»ñµÃWindows CEÉ豸µÄΨһºÅÂ룿
7.20. ÈçºÎÔÚ΢Èí.net¾«¼ò¿ò¼ÜµÄÓ¦ÓóÌÐòÉÏ·¢ËͶÌÏûÏ¢£¿
7.21. ²»Ê¹ÓÃControl.Name£¬¿ÉÒÔÅжÏʼþµÄ·¢ËÍÕßÂð£¿
7.22. ÈçºÎÔÚÏß³ÌÖе÷Ó÷½·¨µÄ²ÎÊý£¿
7.23. ÈçºÎ½¨Á¢ÌáÐѳÌÐòºÍ¶¨Ê±³ÌÐò£¿
7.24. ÈçºÎ²¥·ÅÉùÒô£¿
7.25. ÈçºÎʹÓÃÃüÁîÐвÎÊý£¿
7.26. µ±Ê¹ÓÃÒѾ­ÊͷŵĶÔÏóµÄ·½·¨»òÊôÐÔµÄʱºò£¬ÎªÊ²Ã´µÃµ½Ò»¸öÒì³££¿
7.27. ÈçºÎ»ñµÃ"Enter", "TAB", ºÍ "Arrow"°´¼üµÄʼþ£¿
7.28. ÈçºÎɾ³ýÒ»¸öÖ»¶ÁÎļþ£¿
7.29. How do I determine if a member exists at runtime?
7.30. How do I determine the device name programatically?
7.31. How do I build a C# Smart Device project from the command line?
7.32. How do I abort an executing thread?
7.33. Why can't I play a movie on the Pocket PC emulator?
7.34. How do I suppress Form titles from showing in the active applications list?
7.35. How do I access a Control from its instance name?
7.36. How do I detect the hardware directional pad buttons?
7.37. How do I get a double click event when only the Click event is supported?
7.38. How do I get onenter/onleave style notifications?
7.39. How do I use threading in a modal dialog that doesn't hang my app?
7.40. How do I round floating point numbers efficiently?
7.41. Why does Control.Invoke take so long when a modal dialog is displayed?
7.42. Is there a way to retrieve the culture information of an Assembly?
8. ͨѶºÍWeb·þÎñ
8.1. ÈçºÎͨ¹ýTCP SocketÏò×ÀÃæ»ú·¢ËÍÊý¾Ý£¿
8.2. Ϊʲô²»ÄÜ·ÃÎʱ¾»úÉϵÄWeb·þÎñ£¿
8.3. ÈçºÎÔÚ΢Èí.net¾«¼ò¿ò¼ÜÉϵ÷ÓÃWeb·þÎñ
8.4. ÈçºÎͨ¹ý´úÀí·þÎñÆ÷Ìá½»HTTP GETÉêÇ룿
8.5. ÈçºÎʹÓÃWeb·þÎñ£¿
8.6. ÈçºÎʹÓÃMapPoint3.0µÃµ½µØÍ¼£¿
8.7. ÈçºÎʹÓÃMapPoint3.0»ñµÃµØÍ¼ºÍ·½Ïò£¿
8.8. Is NTLM authentication supported by the .NET Compact Framework?
8.9. When using blocking Sockets, why does Send throw an InvalidOperationException when blocking is set to false?
8.10. How do I create an http-server?
8.11. Why do I get an exception when calling SetSocketOption with ReuseAddress set?
8.12. Why do I get a socket error using SSL to communicate with a server via the WebRequest namespace?
9. SQL CE ºÍ Êý¾Ý
9.1. ʹÓÃ.net¾«¼ò¿ò¼Ü¡¢SQL Server CE ºÍ ¸´ÖÆ ¿ª·¢Ó¦ÓóÌÐòʱ£¬Òª×¢ÒâЩʲô£¿
9.2. ÈçºÎÔÚ΢Èí.net¾«¼ò¿ò¼ÜÉÏʹÓúϲ¢¸´ÖÆ(Merge Replication)£¿
9.3. ÈçºÎ½«ADO.NETÊý¾ÝºÍ£Ø£Í£Ì°ó¶¨£¿
9.4. ÈçºÎ½¨Á¢SQL Server CEµÄÊý¾Ý¿â£¿
9.5. ÈçºÎÏòSQL Server CEÌá½»Ò»¸ö´ø²ÎÊýµÄ²éѯ£¿
9.6. Why does using RDA and the push method fail with error 27750?
10. ÆäËûÐÅÏ¢
10.1. Pocket TaskVision ³ÌÐò
10.2. ½¨Á¢»ùÓÚ΢Èí.net¾«¼ò¿ò¼ÜµÄ½ø³Ì¹ÜÀíÆ÷
10.3. ʹÓÃ΢Èí.net¾«¼ò¿ò¼Ü¿ª·¢Òƶ¯ÓÎÏ·
10.4. ÖÆ×÷Ò»¸ö΢Èí.net¾«¼ò¿ò¼ÜµÄDateTimePicker¿Ø¼þ
10.5. дһ¸ö²¶×½Pocket PCÇ©ÃûµÄ³ÌÐò
10.6. ÓÐûÓзÇ΢ÈíµÄÍøÕ¾ÌṩÔÚ.net¾«¼ò¿ò¼ÜÉÏ¿ª·¢Ó¦ÓõÄÐÅÏ¢£¿
11. Á¬Í¨ÐÔ
11.1. Ϊʲô²»Í¬Í¨¹ýActiveSync°Ñ³ÌÐò²¿Êðµ½Windows CEµÄÉ豸ÉÏ£¿
11.2. Ϊʲô²»ÄÜͨ¹ýActiveSyncµ÷ÊÔ CEPC »òÆäËû x86 µÄWindows CEÉ豸£¿
11.3. Ϊʲôµ±É豸ÉϵÄToolhelp.dllÎļþ¶ªÊ§ºó£¬µ÷ÊԾͻáʧ°Ü£¿
11.4. Ϊʲôµ±ÍøÂçЭÒéÊý³¬¹ý£µ£°¸öµÄʱºò£¬¾Í²»ÄÜÏòÉ豸·¢²¼³ÌÐò£¿
11.5. ÎªÊ²Ã´Ð¶ÔØActiveSyncºó£¬²»ÄÜͨ¹ýActiveSyncÏòÉ豸·¢²¼£¿
11.6. Ϊʲô±¾µØ»¯µÄ»úÆ÷Ãû»òÓû§Ãû»òµ¼ÖÂÏòÉ豸·¢²¼³ÌÐòµÄʧ°Ü£¿
11.7. Ϊʲôµ±Ç°Óû§²»ÊôÓÚAdministrators×éµÄʱºò£¬²»ÄÜÏòÉ豸·¢²¼³ÌÐò£¿
11.8. ΪʲôÏòPocket PC»òÄ£ÄâÆ÷·¢²¼µÄʱºò³öÏÖ sharing violation µÄ´íÎó£¿
11.9. ΪʲôÔÚ.NET ServerµÄ¼ÆËã»úÉϵÚÒ»´ÎʹÓÃÄ£ÄâÆ÷µÄʱºò£¬µÃµ½Ò»¸ö°²È«¾¯¸æÏûÏ¢£¿
11.10. ΪʲôÔÚÄ£ÄâÆ÷¸Õ¿ªÊ¼ÔËÐеÄʱºò³öÏÖ¹ØÓÚÕÒ²»µ½ÎļþµÄ´íÎóÐÅÏ¢£¿
11.11. ΪʲôµÚÒ»´ÎÓÃÄ£ÄâÆ÷·¢²¼Ê±£¬»á³öÏÖż¶ûµÄ´íÎó£¿
11.12. ΪʲôµÚÒ»´ÎÓÃConnect°´Å¥Á¬½ÓÄ£ÄâÆ÷²¢·¢²¼³ÌÐòµÄʱºòʧ°ÜÁË£¿
11.13. Ϊʲôµ±¼ÆËã»úûÓÐÍøÂçÁ¬½ÓµÄʱºò£¬ÓÃÄ£ÄâÆ÷µ÷ÊÔ³ÌÐò»á³öÏÖ´íÎó£¿
11.14. Ϊʲôµ±Ä£ÄâÆ÷ʹÓÃÁËÒ»¸öCOM¶Ë¿ÚµÄʱºò²»Æô¶¯²»ÁË(ºÚÆÁ)£¿
11.15. ΪʲôVisual Studio .NET 2003µÄÄ£ÄâÆ÷²»ÄܺÍeMbedded Visual ToolsµÄÄ£ÄâÆ÷ͬʱʹÓã¿
11.16. ΪʲôûÓÐActiveSyncÁ¬½ÓµÄʱºò²»ÄÜͨ¹ýTCPÁ¬½ÓÏòÉ豸·¢²¼³ÌÐò£¿
11.17. How can I allow Activesync to connect to an Emulator session from Visual Studio .NET 2003?
11.18. How can I copy files to the device currently connected to desktop ActiveSync?
11.19. Why does the Visual Studio debugger fail to connect to an ARMV4I device?
12. Smartphone
12.1. Where can I get the latest Smartphone SDK?
12.2. What are the rules for Smartphone menus?
12.3. Why are there disabled controls in the toolbox when creating a Smartphone project?
12.4. Does Smartphone support RAM installs of the .NET Compact Framework?
12.5. How do I set the title of a fullscreen multiline edit control window?
12.6. How can I generate Smartphone CABWizSP XML docs from existing Pocket PC CAB files?
12.7. How can I send characters and strings to the Smartphone 2003 Emulator via ActiveSync?
12.8. How do I programmatically set the Smartphone input mode?

1. ¿ª·¢

1.1. ʲôÊÇ΢Èí .net¾«¼ò¿ò¼Ü£¿

΢Èí.net¾«¼ò¿ò¼ÜÊÇ.net¿ò¼ÜΪÖÇÄÜÉ豸¿ª·¢µÄƽ̨£¬ÊÇʵÏÖ΢ÈíµÄÄ¿±ê£º¡°ÎªÓû§Ìṩ¾«²ÊµÄÌåÑé--ÈκÎʱ¼ä¡¢Èκεص㡢ÈκÎÉ豸¡± µÄ¹Ø¼ü²¿·Ö¡£.net¾«¼ò¿ò¼Ü°ÑÍйܴúÂëµÄÊÀ½ç´Óweb·þÎñ´øµ½ÁËÖÇÄÜÉ豸ÉÏ£¬ ÔÊÐíÔÚ¸öÈËÊý×ÖÖúÀí£¨PDA£©¡¢Òƶ¯µç»°¡¢»ú¶¥ºÐÉ豸É쵀 °²È«µÄ¡¢¿ÉÏÂÔØµÄÓ¦Óá£

http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/overview/default.aspx

1.2. ÎÒÐèҪʲô¹¤¾ß²ÅÄÜ¿ª·¢.net¾«¼ò¿ò¼ÜµÄÓ¦Óã¿

Visual Studio .NET 2003 ÊÇÔÚPocket PC 2000¡¢Pocket PC 2002ºÍWindows CE.NET 4.1ÉÏ¿ª·¢.net¾«¼ò¿ò¼ÜËùÐèÒªµÄ£¬ .net¾«¼ò¿ò¼ÜÓëVisual Studio .NET 2003һͬ·¢ÊÛ.
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/vstudio/default.aspx

ÆäËûWindowsÒÆ¶¯Æ½Ì¨¿ª·¢°ü¿ÉÒÔÔÚÒÔϵط½»ñµÃ£º

Windows Mobile 2003 Pocket PC SDK:
http://www.microsoft.com/downloads/details.aspx?familyid=9996b314-0364-4623-9ede-0b5fbb133652&displaylang=en

Windows Mobile 2003 Smartphone SDK:
http://www.microsoft.com/downloads/details.aspx?familyid=a6c4f799-ec5c-427c-807c-4c0f96765a81&displaylang=en

ÕâÆªÎÄÕ½«½éÉÜÈçºÎʹÓÃ.net¾«¼ò¿ò¼ÜºÍVisual Studio .NET 2003Ï¿ª·¢½¡×³µÄÖÇÄÜÉ豸ӦÓóÌÐò£®
http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfgetstarted.asp

1.3. ÄÄÀï¿ÉÒÔÏÂÔØ×îÐµĹ¤¾ßºÍÏà¹ØÈí¼þ£¿

Visual Studio .NET 2003ÊÔÓðæ¿ÉÒÔÔÚÕâÀï»ñµÃ£º
http://msdn.microsoft.com/vstudio/productinfo/trial/default.aspx

×îеÄ.net¾«¼ò¿ò¼ÜºÍ²¹¶¡¼¯¿ÉÒÔÔÚÕâÀï»ñµÃ£º
http://msdn.microsoft.com/mobility/downloads/default.aspx

1.4. .net¾«¼ò¿ò¼ÜÖ§³ÖЩʲôÉ豸£¿

.net¾«¼ò¿ò¼Ü¿ÉÒÔÔÚPocket PC 2000, Pocket PC 2002£¬ Windows Mobile 2003µÄPocket PC ºÍ »ùÓÚWindows CE.NET 4.1ǶÈëʽϵͳµÄPocket PC¡¢ÖÇÄÜÊÖ»ú ÉÏÔËÐС£

1.5. .net¾«¼ò¿ò¼ÜÒÔºó½«Ö§³ÖʲôÉ豸£¿

.net¾«¼ò¿ò¼Ü½«±»¼¯³Éµ½Î¢ÈíϵͳÖв¢³ÉΪһ²¿·Ö£¬°üÀ¨Î´À´µÄPocket PCÉ豸£¬Pocket PCµç»°°æ£¬ÖÇÄÜÊÖ»ú£¬³µÔØWindows CEϵͳ£¬£Í£Ó£Ô£Ö¡£ ¸÷ÖÖÉ豸µÄ·¢²¼Ê±¼ä´ý¶¨¡£

.net¾«¼ò¿ò¼Ü½«×÷ΪWindows CE .NET 4.1ϵͳ×é¼þµÄÒ»²¿·Ö£¬Òò´ËÔÊÐíOEM³§ÉÌʹÓÃPlatformBuilder°Ñ.net¾«¼ò¿ò¼Ü¼¯³Éµ½ÐµÄWindows CEÉ豸ÖС£

1.6. µ÷ÊÔ³ÌÐòʱΪʲô»á³öÏÖ¡°ÓëÄ£ÄâÆ÷½¨Á¢Á¬½Óʧ°Ü¡±µÄ´íÎó(¸Õ¿ªÊ¼Ö´ÐгÌÐòµÄʱºò)£¿

ÏÂÃæÕâ¸öÁ¬½Ó½«¸æËßÄãÈçºÎÉèÖõ÷ÊÔºÍÅÅ´í¡£
http://download.microsoft.com/download/c/d/b/cdbff573-73fb-4f9f-a464-c5adc890e1ae/Readme.htm

1.7. .net¿ò¼ÜºÍ.net¾«¼ò¿ò¼ÜÖ®¼äÓÐÊ²Ã´Çø±ð£¿

.NET¿ò¼Ü ºÍ .net¾«¼ò¿ò¼Ü µÄ¹ØÏµ£º
http://msdn.microsoft.com/library/en-us/dv_evtuv/html/etconComparisonsWithNETFramework.asp

ÔÚÏ߲鿴.net¾«¼ò¿ò¼ÜÀà¿â¹ØÏµ¹¤¾ß£º
http://msdn.microsoft.com/library/en-us/dv_spchk/html/NET_Compact_Framework.htm

1.8. .net¾«¼ò¿ò¼ÜµÄ²¹¶¡ÓÐʲô¸Ä½ø£¿

.net¾«¼ò¿ò¼Ü SP1 ÐÞÕýÁËÐí¶à©¶´£¬²é¿´ÐÞÕýÏîÄ¿ÁÐ±í£º
http://www.microsoft.com/downloads/details.aspx?familyid=1f62a2a3-7282-4ba9-b26b-2267e972501d&displaylang=en

1.9. Poclet PCÉϵÄ.net¾«¼ò¿ò¼Ü¿ª·¢ºÍWindows CE .NETÉϵÄ.net¾«¼ò¿ò¼Ü¿ª·¢ÓÐʲô²»Í¬£¿

ÕâÆªÎÄÕ½«ÃèÊöÔÚPocket PCºÍWindows CE.NETƽ̨ÉÏ¿ª·¢»ùÓÚ.net ¾«¼ò¿ò¼ÜµÄÓ¦ÓóÌÐòµÄÇø±ðÖ®´¦¡£
http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfPPCtoCE.asp

1.10. ÄÄÀïÓиü¶àµÄ¹ØÓÚ½¨Á¢.net¾«¼ò¿ò¼ÜÉϵÄÓ¦ÓóÌÐòµÄÐÅÏ¢£¿

ÒÔÏÂ×ÊÔ´Ä̻ܽáÄúÔõÑù½¨Á¢.net¾«¼ò¿ò¼ÜÓ¦ÓóÌÐò:

  • .net¾«¼ò¿ò¼Ü  ¿ìËÙÈëÃÅ
    http://samples.gotdotnet.com/quickstart/compactframework/
  • .net¾«¼ò¿ò¼Ü°×ƤÊé MSDNÒÆ¶¯ºÍǶÈëʽ¿ª·¢ÖÐÐÄ:
    http://msdn.microsoft.com/mobility/understanding/articles/default.aspx

    1.11. .net¾«¼ò¿ò¼ÜµÄÎĵµÔÚÄÄÀ

    http://msdn.microsoft.com/library/en-us/dv_evtuv/html/etconNETCompactFramework.asp

    1.12. ÔõÑùÉèÖòŲ»»áÔÚÿ´Îµ÷ÊÔµÄʱºò°ÑËùÉæ¼°µÄÎļþ¶¼¿½±´µ½É豸ÉÏ£¿

    ÔÚVisual Studio .NET 2003, ÓÒ¼üµã»÷Îļþ²¢Ñ¡ÔñÊôÐÔ,°ÑBuildµÄÊôÐÔÉèÖÃΪNone.Îļþ½«²»ÔÙ±»¿½±´.Èç¹ûÎļþÐ޸ĹýÁË,ÐèÒªÖØÐ¿½±´,°ÑBuildÊôÐÔ¸ÄΪContent¼´¿É.

    1.13. ÔõÑùÉèÖÃÄ£ÄâÆ÷µÄÊôÐÔ£¿

    ÔÚVisual Studio .NET 2003²Ëµ¥ÖÐ,Ñ¡Ôñ Tools->Options. ´ò¿ª Device Tools Îļþ¼Ð,²¢Ñ¡Ôñ Devices. ÄúÓ¦¸Ã¿´µ½Ò»¸öÏÔʾÉ豸ÁбíµÄ¶Ô»°¿ò.Ñ¡ÔñÄúÏëÐ޸ĵÄÉ豸,°´Configuration°´Å¥.
    ÏÖÔÚÄúÓ¦¸Ã¿´µ½Ò»¸ö°üº¬¶à¸öTAB²¢¿ÉÒÔÐÞ¸ÄÉèÖõĶԻ°¿ò,ÈçÉèÖÃÄÚ´æºÍÆÁÄ»´óСµÈ.

    1.14. Ôõôµ÷ÊÔ.net¾«¼ò¿ò¼ÜµÄÓ¦ÓóÌÐò£¿

    ΢Èí.net¾«¼ò¿ò¼ÜÍêÈ«¼¯³ÉÔÚVisual Studio .NET 2003ÖУ¬ÔÚVisual Studio .NET 2003ϵ÷ÊÔ.net¾«¼ò¿ò¼ÜµÄÓ¦ÓúÍÔÚVisual Studio .NET 2003ϵ÷ÊÔÆäËûÓ¦ÓÃÒ»Ñù¡£ÔÚÒ»¸öµ¥¶ÀµÄÉ豸Éϵ÷ÊÔ³ÌÐòºÍÔÚÄ£ÄâÆ÷Öе÷ÊÔ³ÌÐòÐèҪעÒⲻͬµÄµØ·½¡£²é¿´ÏÂÃæÎÄÕ¿ÉÒÔ»ñµÃ¸ü¶àµ÷ÊÔ.net¾«¼ò¿ò¼ÜµÄ¾­Ñé¡£
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/CompactFXDebug.asp

    1.15. ÔõÑù¿ªÊ¼Ê¹ÓÃVisual Basic .NET¿ª·¢.net¾«¼ò¿ò¼ÜµÄ³ÌÐò£¿

    Á˽âÔõÑùʹÓÃSmart Device Extensions (SDE)±àдֻÄÜÉ豸µÄÓ¦Óá£ÕâÆªÎÄÕÂÏêϸ½éÉÜÁËÔÚ.net¾«¼ò¿ò¼ÜÉÏ¿ª·¢¡¢µ÷ÊÔ¡¢·¢²¼µÄÍêÕû¹ý³Ì£¬²¢ÃèÊöÁ˺ÍÔÚ.net¿ò¼ÜÉÏ¿ª·¢µÄÇø±ð¡£
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/sdeforvb.asp

    1.16. ÔõÑù²ÅÄܰÑ.net¾«¼ò¿ò¼Ü°²×°µ½×°Å伯ÖÐ(GAC)£¿

    http://msdn.microsoft.com/library/en-us/dncfhowto/html/HOWTOGAC.asp

    1.17. µ±´ÓVisual Studio .NET 2003Öз¢²¼³ÌÐòµ½É豸ÉϵÄʱºò£¬ÔõÑù´¦Àí"Sharing Violation"£¿

    This article illustrates the cause of a sharing violation that prevents the deployment of your application from Visual Studio .NET 2003, and gives instructions on how to work around it.
    http://msdn.microsoft.com/library/en-us/dncfhowto/html/HOWTOSharingviolation.asp

    1.18. ʲôÊÇcommon language runtime (CLR)?

    .net¾«¼ò¿ò¼ÜÌṩµÄÔËÐл·¾³½Ð×öCLR£¬Ëüʹ³ÌÐòÔËÐУ¬²¢ÇÒÊÇ¿ª·¢¸ü¼ÓÈÝÒס£ÒÔÏÂÎÄÕ½«Ê¹ÄúÁ˽â¸ü¶à¹ØÓÚCLR£º
    http://msdn.microsoft.com/library/en-us/cpguide/html/cpconcommonlanguageruntimeoverview.asp

    1.19. ʲôÊÇGlobal Assembly Cache (GAC)?

    ÿһ̨װÁË.net»·¾³µÄ»úÆ÷¶¼»áÓÐÒ»¸ö±¾»úÆ÷·¶Î§ÄڵĻº³å£¬Õâ¾ÍÊÇGAC¡£GACÖдæ·ÅµÄ×°Åä»á±»Õą̂¼ÆËã»úÉϵÄһЩӦÓóÌÐò¹²Ïí ¡£ÕâÆªÎÄÕ½«¸æËßÄã¸ü¶à¹ØÓÚGACµÄÐÅÏ¢£º
    http://msdn.microsoft.com/library/en-us/cpguide/html/cpconglobalassemblycache.asp

    1.20. ÔÚ.net¾«¼ò¿ò¼ÜÏÂÄÚ´æ¹ÜÀíÊÇÔõÑùµÄ£¿

    ×Ô¶¯ÄÚ´æ¹ÜÀíÊÇCLRÌṩµÄÒ»Ïî·þÎñ¡£CLRµÄÀ¬»ø»ØÊÕÆ÷»á¹ÜÀíÓ¦ÓóÌÐòÄÚ´æµÄ·ÖÅɺͻØÊÕ£¬ÒÔÏÂÎÄÕ½«ÎªÄú½âÊÍ£º
    http://msdn.microsoft.com/library/en-us/cpguide/html/cpconautomaticmemorymanagement.asp

    1.21. µ±ÎÒµÄÍøÂçЭÒéÊý³¬¹ý50¸öµÄʱºò£¬ÎªÊ²Ã´²»ÄÜÏò·¢²¼³ÌÐò£¿

    Çë²é¿´±¾ÎÄÕµĠ "11.4. Ϊʲôµ±ÍøÂçЭÒéÊý³¬¹ý£µ£°¸öµÄʱºò£¬¾Í²»ÄÜÏòÉ豸·¢²¼³ÌÐò£¿"  ²¿·Ö¡£

    1.22. Ϊʲô»áÓÐ¿çÆ½Ì¨´úÂ룿

    .net¾«¼ò¿ò¼ÜºÍËüµÄÖ´ÐÐÒýÇæÊÇ.net¿ò¼ÜºÍCLRµÄ×Ó¼¯¡£È±Ê¡µÄÇ¿Ãû³Æ²ßÂÔ£¬Õë¶Ô.net¾«¼ò¿ò¼Ü±àÒëµÄ³ÌÐòͬÑù¿ÉÒÔÔÚÍêÕûµÄ.NET¿ò¼ÜÉÏÔËÐУ¬µ«»áÓÐÒ»Ð©ÖØÒªµÄÒì³£ÐÅÏ¢£º
    • .net¾«¼ò¿ò¼Ü×°ÅäʹÓúÍ.net¿ò¼Ü²»ÓõÄÇ¿Ãû³ÆÇ©Ãû£¬ËùÒÔCLR¿ÉÒÔÇø·ÖËüÃÇ¡£
    • ÔÚδÀ´·¢²¼µÄ.NET¿ò¼ÜºÍCLRµÄ°ó¶¨²ßÂÔÖн«Ê¹ÓÃ.NET¿ò¼Ü×°Åä´úÌæ¼æÈÝ.NET¾«¼ò¿ò¼Ü²Î¿¼¡£ÕâÑù£¬ÔÚÆÕͨÇé¿öÏ£¬²»ÐèÒªÖØÐÂÁ¬½Ó¾ÍÄÜÖØÓÃ×é¼þ¡£ ÀýÈ磺Èç¹ûÄúµÄ×é¼þÖ»ÒýÓÃÁË.net¾«¼ò¿ò¼ÜµÄ System ºÍ System.NET Àà¿â£¬ËüÔò²»ÐèÒªÖØÐÂÁ¬½Ó¾ÍÊʺÏÔÚ.net¾«¼ò¿ò¼ÜºÍÍêÕûµÄ.NET¿ò¼ÜÏÂÔËÐС£
    • Èç¹ûÄãÒýÓÃÁË.net¾«¼ò¿ò¼ÜÌØÓеŦÄÜ£¬ÈçPocketPCÌØÓеÄÓû§½çÃæ£¬³ÌÐò½«²»ÄÜÔÚÍêÕûµÄ.net¿ò¼ÜÉÏÔËÐС£
    • Èç¿çƽ̨µÄÖмä×é¼þµÄ¿ª·¢ºÍ·¢²¼£¬Î¢ÈíÈÏΪ·á¸»µÄ¿Í»§¶ËÓ¦ÓÃÓ¦¸ÃÀûÓÃÖÇÄÜÉè±¸ÌØÓеŦÄÜΪÓû§´øÀ´¸üºÃµÄÌåÑé¡£ÕâһζןõÄͼÐÎÓû§½çÃæ»ù±¾ÉÏÊǿͻ§¶ËÌØÓеġ£
    • ¾¡¹Ü΢Èí»¨·ÑºÜ´ó¾«Á¦Îª²»Í¬É豸ºÍ¹¦ÄÜ»®·ÖÁ˲»Í¬µÄÃüÃû¿Õ¼äºÍ×°ÅäÒÔ±ÜÃâ×°Åä³åÍ»£¬µ«ÔÚ1.0µÄ°æ±¾ÀﻹÊÇ»áÓв»ÄÜ´¦ÀíµÄ¼æÈÝÐÔÎÊÌâ¡£ÔÚÕâÖÖÇé¿öÏ£¬ÔÚ. net¿ò¼ÜÉϲ»¾­ÒâµØÊ¹ÓÃÁËÉ豸רÓеŦÄܽ«»áµ¼Ö³ÌÐòÔÚÔËÐÐʱµÄÒì³££¬¶ø²»ÊÇÔØÈëʱµÄÒì³£¡£

    1.23. ÕâЩARMÖ¸Áî´ú±íʲô£¿

    XScaleÖ§³ÖARM v5Ö¸Á£¬Í¬Ê±Ò²ÏòϼæÈÝARM v4Ö¸Á¡£ÕâÀïÓÐÈýÖÖÇé¿ö£º
    • ARMv4 -> Ö»Ö§³Ö32λARMv4Ö¸Áî
    • ARMv4T -> 'T' ±íʾ Thumb. Thumb ÊÇARM16λָÁîģʽ
    • ARMv4I -> 'I' ±íʾ Interworking. ÔÊÐí32λºÍ16λָÁî¹²´æ

    ¶ÔÓÚÆäËûARM´¦ÀíÆ÷£º
    • StrongARM (SA1110) -> Ö»Ö§³ÖARMv4Ö¸Áî
    • ARM920T, etc -> Ö§³ÖËùÓÐÈýÖÖÇé¿ö

    .net¾«¼ò¿ò¼ÜÖ§³ÖÈýÖÖARM´úÂë
    • ARMv4 for PocketPC 2000 and Pocket PC 2002. Ö§³ÖËùÓÐARMÉ豸£¬°üÀ¨XScale¡£·¢²¼µ½É豸µÄCABÎļþÃû°üº¬ÓÐ"arm"×Ö·û¡£
    • ARMv4 for Windows CE.NET. Ö§³ÖÓÉPlatformBuilderʹÓÃARMv4ºËÐıàÒëµÄWindows CE.NETÉ豸¡£Pocket PC 2003Ö§³ÖÕâÖÖ´úÂë¡£·¢²¼µ½É豸µÄCABÎļþÃû°üº¬ÓÐ"armv4"×Ö·û¡£
    • ARMv4T or ARMv4I for Windows CE.NET. Ö§³ÖÓÉPlatformBuilderʹÓÃARMv4T »ò ARMv4IºËÐıàÒëµÄWindows CE.NETÉ豸¡£·¢²¼µ½É豸µÄCABÎļþÃû°üº¬ÓÐ"armv4T"×Ö·û¡£

    1.24. ÔõÑùдע²á±í£¿

    Visual Studio .NET µÄ·¢²¼ÖÐûÓаüÀ¨Windows CEµÄÔ¶³Ì×¢²á±í±à¼­Æ÷¡£ÒªÐÞ¸Ä×¢²á¼üÖµ£¬¿ÉÒÔ²ÉÓÃÒÔÏ·½·¨£º
    • Microsoft Embedded Visual Tools Remote Registry Editor
    • Microsoft Windows CE Platform Builder Remote Registry Editor
    • PHM Pocket PC Registry Editor (¹²ÏíÈí¼þ£¬ºÜÈÝÒ×ÔÚÍøÉÏÕÒµ½)
    1.25. How can I prevent .CAB files from being deleted after installation?

    Automatic deletion of .CAB files can be prevented by setting the property of the .CAB file(s) to Read Only.

    1.26. How can I determine the version of the .NET Compact Framework that is installed on a device?

    Each version of the .NET Compact Framework is released with a different Win32 File Version number (this is a separate version number from the Assembly Version, which should be the same across all releases of the Version 1 .NET Compact Framework, including Service Packs).

    In order to see what version is installed, use File Explorer to navigate to the \Windows directory on the device, and click the file called CGACUTIL. You will get a message box showing you the Win32 File Version of the .NET Compact Framework installed on the device.

    RTM = 1.0.2268.0
    SP1 = 1.0.3111.0
    SP2 Recall = 1.0.3226.0
    SP2 Beta = 1.0.3227.0
    SP2 Final = 1.0.3316.0

    To determine the version programmatically you can use System.Environment.Version.ToString().

    1.27. How do I copy files to the emulator?

    One approach would be to create a file share on your development PC, and then connect to that share via File Explorer in the emulator. You may then copy and paste the files from the share to the emulator's local file system. Another approach would be to add the file(s) to a smart device project and set their Build Action(s) property to "Content". See the Visual Studio .NET online documentation for more information on "File Properties":

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconfileproperties.asp

    Step by step instructions for adding a "Content" file to a smart device project:
    1. Open or create a smart device project,
    2. On the View menu, click Solution Explorer,
    3. In Solution Explorer, right-click on your project, point to Add, and click Add Existing Item. Browse to and add the desired file to the project.
    4. Right-click on the file that you added, in solution explorer, and click Properties,
    5. Set the Build Action property to "Content", if it is not already set.
    1.28. Why does installation of the PocketPC 2002 SDK fail?

    Symptom: The Pocket PC 2002 SDK installer hangs while "registering components."

    Cause: An unregestered component causes the installation to hang while attempting to run the emulator.

    Workaround: From a console window prompt:
    cd \WINNT\system32
    regsvr32 atl.dll

    1.29. How do I debug a Web service consumed by a Smart Device application?

    You need to attach the debugger to the ASP.NET worker process.

    Refer to the following link for more information:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxtskdebugginganaspdeployedwebapplication.asp

    1.30. What is the footprint of the .NET Compact Framework?

    .NET Compact Framework storage size:
    • 1.55MB (ROM) on Pocket PC 2000/2002
    • 1.35MB (ROM) on Windows Mobile for Pocket PC 2003 or Windows CE .NET Devices
    Running RAM requirements:
    • .5 MB+ (depends on application)
    Typical application sizes:
    • 5 - 100 KB
    1.31. How do I include imgdecmp.dll in an emulator image?

    You must ask the OEM to include it in the device's image. If you are the OEM and you are using Platform Builder 4.2, then including the OS Dependencies for the .NET item automatically causes imgdecmp.dll to be part of the emulator image - if that is not working then refer to cesysgen.bat. Another method is to set the environment variable "__SYSGEN_IMGDECMP=1" to explicitly force the DLL into the image.

    1.32. How do I programmatically replace Assemblies in the Global Assembly Cache (GAC)?

    One can install and remove Assemblies directly to and from the GAC by programmatically launching cgacutil.
    • Remove assemblies from the GAC using the -u option
    • Install assemblies to the GAC using the -i option
    It is typically safest to remove the Assembly before reinstalling it.

    1.33. How can I display Pocket PC applications on my desktop or laptop without needing any device side configuration?

    Download the ActiveSync Remote Display from Windows Mobile Developer Power Toys:
    http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

    1.34. How can I allow Activesync to connect to an Emulator session from Visual Studio .NET 2003?

    See the entry titled "11.17. How can I allow Activesync to connect to an Emulator session from Visual Studio .NET 2003?" of this FAQ.

    1.35. How can I copy files to the device currently connected to desktop ActiveSync?

    See the entry titled "11.18. How can I copy files to the device currently connected to desktop ActiveSync?" of this FAQ.

    1.36. How can I stress test user input?

    Download Hopper from Windows Mobile Developer Power Toys:
    http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

    1.37. Where can I get a UI version of the Platform Builder Target Control Window?

    Download JShell from Windows Mobile Developer Power Toys:
    http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

    1.38. Where can I get a Command shell for Pocket PC 2003 devices?

    Download PPC Command Shell from Windows Mobile Developer Power Toys:
    http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

    1.39. How can I get detailed information about currently running processes?

    Download RAPI Debug from Windows Mobile Developer Power Toys:
    http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

    1.40. How can I remotely start an application on a Pocket PC from my desktop?

    Download RAPI Start from Windows Mobile Developer Power Toys:
    http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

    1.41. Why can't I load different assemblies with the same name?

    This is by design. You must either change the names of the DLLs, or if the DLLs are strong named, place them in the GAC and use Assembly.Load with a full strong name.

    1.42. How can I force Visual Studio .NET 2003 to connect to newer versions of the Pocket PC 2003 emulator?

    Download the Emulator ActiveSync Connection Tool from Windows Mobile Developer Power Toys:
    http://www.microsoft.com/downloads/details.aspx?familyid=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

    This allows ActiveSync to connect to your Emulator session from Visual Studio .NET 2003. Create an ActiveSync session to the 4.2 emulator, this will allow Visual Studio 2003 to consider it a real device (Choose PPC device as the deployment target).

    1.43. Why don't my custom controls show up properly in the toolbox?

    While adding designer support in Visual Studio .NET 2003 for Smart Device custom controls, you may run into the following issues:
    • Unable to associate an Icon to the Control for showing it in the toolbox at design time
    • The component, when added to the toolbox, becomes greyed out
    Causes
    • Using a design project separate from the control project. Visual Studio .NET automatically prepends the project default namespace to the bitmap name. The "default namespace" defaults to the project name. This may be a problem because the design project has a slightly different name than the runtime project.
    • Not setting the correct ToolBoxItemFilterAttribute values
    Resolutions

    Given the following example:
    Runtime VS.NET Project: MyProject
    Class Name: MyProject.MyClass
    Design VS.NET Project Name: MyProject.Design
    BitMap name in VS.NET Design Project: Foo.bmp
    Bitmap name in design assembly: MyProject.Design.MyClass.bmp
    -- This creates a problem because the bitmap needs the name: MyProject.MyClass.bmp

    In the above example, setting the design project's default namespace to "MyProject" rather then "MyProject.Design" should fix the problem.

    The easiest way to check the name of the bitmap within the assembly is to run ILDASM and open the Manifest. The embedded resources are listed at the end of the manifest.

    If you create a custom component derived from the Component class, your code must include the following statements so that your component appears in the Toolbox:
    ToolBoxItemFilterAttribute("NETCF",ToolBoxItemFilterType.Require)
    ToolBoxItemFilterAttribute("System.CF.Windows.Forms", ToolBoxITemFilterType.Custom)

    2. ͼÐÎ


     2.1. ÔõÑù½¨Á¢Ò»¸öͼÐζÔÏó£¿

    ÓкܶàÖÖ·½·¨¿ÉÒÔ½¨Á¢Í¼ÐζÔÏ󣬿´ÄãÔõôÓãº

    ÔÚOnPaintÖУ¬Ê¹ÓÃobject²ÎÊýÌṩµÄPaintEventArgs²ÎÊý£º
    //C#
    protected override void OnPaint(PaintEventArgs e)
    {
    e.Graphics.DrawLine(...);
    }

    'VB
    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    e.Graphics.DrawLine(...)
    End Sub 'OnPaint
    ÔÚ³ÌÐòµÄÆäËû²¿·Ö£¬ÀûÓÿؼþµÄÒ»¸ö·½·¨£¬¿ÉÒÔÓÃÀ´½¨Á¢ÈÎÒâ¿Ø¼þµÄͼÐζÔÏó£º
    //C#
    using System.Drawing;

    Graphics g = this.CreateGraphics();

    'VB
    Imports System.Drawing

    Dim g As Graphics = Me.CreateGraphics()
    Ö±½Ó»­µ½bitmapλͼÎļþÖУº
    //C#
    using System.Drawing;

    Bitmap bm = new Bitmap(10,10);
    Graphics g = Graphics.FromImage(bm);

    'VB
    Imports System.Drawing

    Dim bm As New Bitmap(10, 10)
    Dim g As Graphics = Graphics.FromImage(bm)
    2.2. ÔõÑùÓÅ»¯GDI+£¿

    ÒÔϱàÂ뷽ʽÓÐÖúÌá¸ßʹÓÃGraphicsµÄ»æÍ¼ËÙ¶È£º
    • Ö»½¨Á¢Ò»¸öͼÐζÔÏó (»òֻʹÓÃOnPaintÖÐµÄ PaintEventArgs)¡£
    • °ÑËùÓлæÍ¼¹¤×÷ÏÈ»­µ½²»ÏÔʾµÄλͼÉÏ£¬ÔÙÒ»´ÎÐÔ°ÑλͼÏÔʾ³öÀ´¡£
    • Ö»ÖØ»­±ä»¯µÄ²¿·ÖͼÏó¡£
    • ¾¡¿ÉÄÜÔÚÏàͬµÄÇøÓòÉÏ»­Ïàͬ´óСµÄͼÏó¡£
    Ö÷Ҫ˼·£º×îС»¯µØÖØ»­Í¼Ïó¡£ÀýÈ磬µ±¹â±êÍϹýͼÏóʱ£¬²»ÐèÒª°ÑÕû¸öÍ¼ÖØÐ»­Ò»±é¡£Ö»ÐèÒªÖØ»­¹â±ê֮ǰ¾­¹ýµÄµØ·½¡£

    2.3. ÔõÑùÔÚ´°ÌåÉÏ»­Ò»¸öͼ°¸£¿

    ÕâÀïÓиöÀý×Ó£¬¸æËßÄãÔõÑù°ÑͼƬ»­µ½´°ÌåµÄ±³¾°ÉÏ£º
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/bkgndimage.aspx

    2.4. ÔõÑù»­Ò»¸ö´øÓÐ͸Ã÷É«µÄͼ°¸£¿

    »­Ò»¸ö´øÓÐ͸Ã÷É«µÄͼÏó£¬ÐèÒªÉèÖÃImageAttributes¶ÔÏóµÄ͸Ã÷É«¡£Ä¿Ç°.net¾«¼ò¿ò¼ÜÖ§³Öµ¥ÖÖÑÕÉ«µÄ͸Ã÷É«¡£ËäÈ»SetColorKey ¹¦ÄÜ¿ÉÒÔÉèÖÃÑÕÉ«·¶Î§£¬µ«ÑÕÉ«µÄ×î´óÖµºÍ×îСֵ±ØÐëÏàͬ£¬²»È»ÔÚÔËÐÐʱ»á³öÏÖArgumentExceptionµÄ´íÎó£º
    //C#
    using System.Drawing.Imaging;

    ImageAttributes attr = new ImageAttributes();

    'VB
    Imports System.Drawing.Imaging

    Dim attr As New ImageAttributes()
    ÒÔÏ´úÂëÃèÊöÁËÈçºÎ¸ù¾ÝͼÏó×óÉϽǵÄÑÕÉ«ÉèÖÃ͸Ã÷É«¡£
    //C#
    attr.SetColorKey(bmp.GetPixel(0,0), bmp.GetPixel(0,0));

    'VB
    attr.SetColorKey(bmp.GetPixel(0,0), bmp.GetPixel(0,0))
    ÒÔÏ·½·¨¿ÉÒÔ׼ȷµÄÉèÖÃÑÕÉ«£º
    //C#
    attr.SetColorKey(Color.FromArgb(255,0,255),Color.FromArgb(255,0,255));
    attr.SetColorKey(Color.Fuchsia, Color.Fuchsia);

    'VB
    attr.SetColorKey(Color.FromArgb(255,0,255),Color.FromArgb(255,0,255))
    attr.SetColorKey(Color.Fuchsia, Color.Fuchsia)
    ͼÏó»á±»ÖØÔصÄGraphics.DrawImage·½·¨ÖØ»­£¬²¢ÇÒʹÓÃImageAttributes¶ÔÏó×÷Ϊһ¸ö²ÎÊýparameter£º
    //C#
    g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height,GraphicsUnit.Pixel, attr);

    'VB
    g.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height,GraphicsUnit.Pixel, attr)
    2.5. Ϊʲô´ÓTextBoxÉϵ÷ÓÃCreateGraphics»áʧ°Ü£¿

    Ö»ÓÐFormÀà²ÅÖ§³ÖControl.CreateGraphics().

    2.6. ÔõÑù»ñµÃÆÁÄ»ÉÏÎÄ×ֵĴóС£¿

    ʹÓÃGraphicsµÄMeasureString·½·¨¡£ÒÔÏ´úÂë˵Ã÷ÈçºÎÔÚÎÄ×ÖÖÜΧ»­Ò»¸ö·½¿ò£º
    //C#
    using System.Drawing;

    protected override void OnPaint(PaintEventArgs e)
    {
    string s = "Hello World"

    Pen pen = new Pen(Color.Fuchsia);
    Font font = new Font("Arial", 18, FontStyle.Regular);
    Brush brush = new SolidBrush(Color.Black);

    SizeF sSize = e.Graphics.MeasureString(s, font);

    Rectangle r = new Rectangle(9, 199,(int)sSize.Width + 1, (int)sSize.Height + 1);

    e.Graphics.DrawRectangle(pen, r);
    e.Graphics.DrawString(s, font, brush, 10.0f, 200.0f);

    base.OnPaint (e);
    }

    'VB
    Imports System.Drawing

    Protected Overrides Sub OnPaint(e As PaintEventArgs)
    Dim s As String = "Hello World"

    Dim pen As New Pen(Color.Fuchsia)
    Dim font As New Font("Arial", 18, FontStyle.Regular)
    Dim brush = New SolidBrush(Color.Black)

    Dim sSize As SizeF = e.Graphics.MeasureString(s, font)

    Dim r As New Rectangle(9, 199, Fix(sSize.Width) + 1, Fix(sSize.Height) + 1)

    e.Graphics.DrawRectangle(pen, r)
    e.Graphics.DrawString(s, font, brush, 10F, 200F)

    MyBase.OnPaint(e)

    End Sub 'OnPaint
    2.7. Can I set the width of a pen?

    Setting the pen width is not available in the .NET Compact Framework. Some alternate solutions include:

    • Drawing filled rectangles with the Graphics.FillRectangle method
    • Drawing multiple lines next to each other
    • Writing a custom graphics routine with GAPI
    2.8. How do I zoom an image?

    While there is no inherent support for zooming or stretching a single image, these effects can be achieved quite easily by creating a new Bitmap object with an associated Graphics object and copying the desired portion of the original Bitmap into it. The following sample creates two bitmaps of the same size, where the second contains a zoomed center section of the first, provided the project has an embedded resource named MyImage.bmp. This same technique could be used to stretch images by modifying the source and destination rectangles such that they do not maintain their original aspect ratio.
    //C#
    using System.Drawing;
    using System.Reflection;

    Bitmap m_bmpOriginal;
    Bitmap m_bmpZoom;

    private void Form1_Load(object sender, System.EventArgs e)
    {
    Assembly asm = Assembly.GetExecutingAssembly();
    m_bmpOriginal = new Bitmap(asm.GetManifestResourceStream(asm.GetName().Name
    + ".MyImage.bmp"));

    // Take the center quarter of m_bmpOriginal
    // and create stetch it into m_bmpZoom of the same size
    m_bmpZoom = new Bitmap(m_bmpOriginal.Width, m_bmpOriginal.Height);
    Graphics gZoom = Graphics.FromImage(m_bmpZoom);

    Rectangle srcRect = new Rectangle(m_bmpOriginal.Width / 4, m_bmpOriginal.Height / 4,
    m_bmpOriginal.Width / 2, m_bmpOriginal.Height / 2);
    Rectangle dstRect = new Rectangle(0, 0, m_bmpZoom.Width, m_bmpZoom.Height);
    gZoom.DrawImage(m_bmpOriginal, dstRect, srcRect, GraphicsUnit.Pixel);
    }

    protected override void OnPaint(PaintEventArgs e)
    {
    e.Graphics.DrawImage(m_bmpOriginal, 0, 0);
    e.Graphics.DrawImage(m_bmpZoom, 125, 0);
    base.OnPaint (e);
    }

    'VB
    Imports System.Drawing
    Imports System.Reflection

    Private m_bmpOriginal As Bitmap
    Private m_bmpZoom As Bitmap

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim asm As [Assembly] = [Assembly].GetExecutingAssembly()
    m_bmpOriginal = New Bitmap(asm.GetManifestResourceStream((asm.GetName().Name _
    + ".MyImage.bmp")))

    ' Take the center quarter of m_bmpOriginal
    ' and create stetch it into m_bmpZoom of the same size
    m_bmpZoom = New Bitmap(m_bmpOriginal.Width, m_bmpOriginal.Height)
    Dim gZoom As Graphics = Graphics.FromImage(m_bmpZoom)

    Dim srcRect As New Rectangle(m_bmpOriginal.Width / 4, m_bmpOriginal.Height / 4, _
    m_bmpOriginal.Width / 2, m_bmpOriginal.Height / 2)
    Dim dstRect As New Rectangle(0, 0, m_bmpZoom.Width, m_bmpZoom.Height)
    gZoom.DrawImage(m_bmpOriginal, dstRect, srcRect, GraphicsUnit.Pixel)
    End Sub 'Form1_Load

    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    e.Graphics.DrawImage(m_bmpOriginal, 0, 0)
    e.Graphics.DrawImage(m_bmpZoom, 125, 0)
    MyBase.OnPaint(e)
    End Sub 'OnPaint
    2.9. Why can't I load an image?

    Ensure that imgdecmp.dll is in the device's Windows directory.

    For more information, see the topic "1.31. How do include imgdemp.dll in an emulator image?" of this FAQ.



    3. ·¢²¼

    3.1. ÔõÑù½¨Á¢Ò»¸öPocketPCµÄÉèÖóÌÐò£¿

    ÕâÆªÎÄÕ¸æËßÄúÈçºÎ½¨Á¢Ò»¸öµ¥¶ÀµÄ.msiÎļþ£¬¿ÉÒÔÔËÐв¢°ÑÓ¦Óð²×°µ½²»Í¬µÄPocket PCÉ豸ÉÏ¡£Õû¸ö¹ý³Ì¶¼ÊÇ×Ô¶¯µÄ£¬ËùÒÔºÜÈÝÒ×°ÑËùÓÐÐèÒªµÄ×é¼þ¶¼´ò°üµ½.msiÎļþÖС£°üº¬C#ºÍMicrosoft Visual Basic .NET´úÂë¡£
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfdeployment.asp

    3.2. Äĸö·¢²¼°ü¿ÉÒÔ°üÀ¨ÔÚÎҵݲװ³ÌÐòÖУ¿

    Äú¿ÉÒÔΪÄúµÄÓû§Ìṩһ¸ö×îÖյķ¢²¼°ü£¬ÒÔ°ïÖúËûÃÇÉý¼¶É豸¡£Äú²»Äܲð¿ªÕâ¸ö·¢²¼°ü°ÑÄÚÈݸøÄúµÄÓû§¡£µ«ÊÇ£¬Äú¿ÉÒԲ𿪿ª·¢ÈËÔ±µÄ·¢²¼°ü°ÑÄÚÈݸøÄúµÄÓû§¡£

    3.3. ÔõÑù¿ÉÒÔ½¨Á¢Ò»¸ö²»ÐèÒª.net¿ò¼ÜµÄ°²×°³ÌÐò£¿

    ÕâÆªÎÄÕÂÌÖÂÛÁËÈçºÎ³É¹¦µÄ°²×°Ò»¸öPocket PCµÄÓ¦Óãº
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppc2k/html/ppc_allation.asp

    3.4. ÔõÑù½¨Á¢²»ÊÜPocketPCÏµÍ³Ô¼ÊøµÄCAB°²×°Îļþ£¿

    Äú¿ÉÒÔ½¨Á¢Ò»¸ö.infÎļþÉú³ÉÒ»¸öÊʺÏÈκÎPocket PCÉ豸µÄÓ¦ÓóÌÐò°²×°Îļþ¡£²é¿´Ê¾Àý´úÂ룺
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/cabfile.aspx

    3.5. Ϊʲô²»Í¬µÄ´¦ÀíÆ÷»áÓв»Í¬µÄCAB°²×°Îļþ£¿

    ÿһ¸öCABÎļþ¶¼°üº¬Ò»Ð¡¶Î¼ì²âÖÇÄÜÉ豸ÉϵÄ.net¾«¼ò¿ò¼Ü°æ±¾µÄ´úÂë¡£Õâ¸ö¹¦ÄÜÊÇ´¦ÀíÆ÷/Æ½Ì¨ÌØÓе쬲»Í¬µÄCABÎļþ¸ù¾Ý´¦ÀíÆ÷ÀàÐͰ󶨲»Í¬µÄ´úÂë¡£

    3.6. How do I create a desktop installer that detects the presence of the .NET Compact Framework on the target device and installs it if necessary?


    The article titled "Creating an MSI Package that Detects and Updates the .NET Compact Framework" in the MSDN Library describes a technique that may be used:
    http://msdn.microsoft.com/mobility/understanding/articles/default.aspx?pull=/library/en-us/dnnetcomp/html/netcfdepl.asp

    3.7. How do I deploy a .NET Compact Framework Service Pack to the emulator?

    Download and install to your desktop development PC a "Developer" version of the service pack (the download title will read something like: "Microsoft?? .NET Compact Framework 1.0 SPx Developer Redistributable") from:
    http://msdn.microsoft.com/mobility/downloads/updates/default.aspx

    The next step is to copy the appropriate .NET Compact Framework cab file (as per next paragraph) to the emulator. From within the emulator point File Explorer to a share on your PC and then copy and paste the cab to somewhere on the emulator's file system. Now launch the cab file from File Explorer and answer "Yes" if asked to overwrite anything.

     

    Emulator

    CAB File

    Pocket PC 2002 netcf.core.ppc3.x86.cab
    Windows Mobile 2003 for Pocket PC netcf.core.wce4.x86.cab
    Windows Mobile 2003 for Smartphone RAM installs not supported

    3.8. How do I include SQL Server CE with my application installation?

    To install SQL Server CE with an application, simply install the proper SQL Server CE CAB files as part of the application's installation. There are two sets of cabs associated with SQL Server CE.

    The developer CAB includes Query Analyzer, and error strings. This CAB should not be included with application deployment. It comes in two actual files, one for Pocket PC and one for Windows CE 4.x devices:

    sqlce.dev.ppc3.<processor>.cab
    sqlce.dev.wce4.<processor>.cab

    The SQL Server CE CAB, which includes the engine, client agent, and managed extensions for the client agent is required by applications utilizing System.Data.SqlServerCe components. This CAB also comes in two actual files, one for Pocket PC and one for Windows CE 4.x devices:

    sqlce.ppc3.<processor>.cab
    sqlce.wce4.<processor>.cab

    Applications that access SQL Server, ie applications utilizing System.Data.SqlClient components should deploy the 'sql' CAB. This CAB also comes in two actual files, one for Pocket PC and one for Windows CE 4.x devices:

    sql.ppc3.<processor>.cab
    sql.wce4.<processor>.cab

    All of these CABs are included in the Visual Studio .NET 2003 Professional Edtion install. The default location is:

    \Program Files\Microsoft Visual Studio .NET 2003\CompactFrameworkSDK\v1.0.5000\Windows CE\...

    3.9. How do I use GAPI to create a graphics engine?

    This article describes how to create a DLL that wraps GAPI (Game API), such that it is .NET Compact Framework compliant, and use it to create and optimize a basic graphics library in managed code.
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/WrapGAPI1.asp

    This article expands upon the "Dancing Rectangles" sample by implementing loading and displaying of bitmaps. It also implements some more advanced features such as animated bitmaps, source and destination key transparency, and alpha blending, i.e., translucency.
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/WrapGAPI2.asp

    This article expands upon the "Dancing Zombies" sample by implementing drawing of points, lines, and custom 1 bit fonts converted from 8 bit bitmaps. It also implements an input system that overrides the functionality of the hardware buttons and tracks button states.
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/WrapGAPI3.asp  

    4. ͼÐÎÓû§½çÃæ(GUI): ´°Ìå

    4.1. ÔõÑù½¨Á¢Ò»¸öÈ«ÆÁµÄ´°Ì壿

    Äú±ØÐë°ÑWindowStateÊôÐÔÉèÖÃΪ×î´ó»¯¡£×öÒ»¸ö¿´²»¼ûµÄ´°Ì壬Èç°ÑÈ«ÆÁµÄͼƬ·Åµ½´°ÌåÖУ¬ÄúÐèÒª°ÑFormBorderStyleÉèÖÃΪNone£¬¹ØµôControlBoxɾµô´°ÌåÖÐËùÓеIJ˵¥¡£

    //C#
    this.WindowState = FormWindowState.Maximized;
    this.FormBorderStyle = FormBorderStyle.None;
    this.ControlBox = false;
    this.Menu = null;

    'VB
    Me.WindowState = FormWindowState.Maximized
    Me.FormBorderStyle = FormBorderStyle.None
    Me.ControlBox = False
    Me.Menu = Nothing
    4.2. ʲôʱºòÓô°ÌåµÄ¹¹ÔìÆ÷£¿Ê²Ã´Ê±ºòÓô°ÌåµÄLoadʼþ£¿

    ´°ÌåµÄload¹¦ÄÜÊÇ×ö½çÃæ²Ù×÷µÄ×îºÃ·½·¨¡£µäÐÍÓÖ°²È«µÄ×ö·¨ÊÇÔÚ¹¹ÔìÆ÷Öд´½¨Êý¾ÝºÍ¿Ø¼þµÄʵÀý¡£Èκΰüº¬Óû§½çÃæµÄ¿Ø¼þ»ò´°ÌåµÄ³õʼ»¯£¬¶¼Ó¦¸ÃÔÚ load¹¦ÄÜÖÐÍê³É¡£ÀýÈ磺ÔÚ´°ÌåµÄ¹¹ÔìÆ÷ÖÐÍê³É¿Ø¼þ¶ÔÏóµÄ½¨Á¢£¬È»ºóÔÚload¹¦ÄÜÖÐÉèÖÿؼþµÄλÖÃµÈ Êǰ²È«µÄ×ö·¨¡£

    4.3. ÔõÑù°Ñ×îС»¯°´Å¥»»³É¹Ø±Õ°´Å¥£¿

    ͨ¹ý¿ª·¢»·¾³µÄÉè¼ÆÆ÷£¬¿ÉÒÔ°Ñ´°ÌåµÄ×Ô¶¯×îС»¯Ä£Ê½×ª±ä³É¹Ø±Õģʽ£¬»òÕßͨ¹ý±ä³ÉʵÏÖ¡£(x)°´Å¥×Ô¶¯×îС»¯Ó¦ÓóÌÐò£¬(ok)°´Å¥»Ø¹Ø±Õ³ÌÐò¡£

    ÔÚÉè¼ÆÆ÷ÖÐת»¯´°ÌåµÄ·ç¸ñ
    ´ò¿ªVisual Studio»·¾³µÄ´°ÌåÉè¼ÆÆ÷£¬²é¿´ÊôÐÔ¡£ÔÚ´°ÌåÉÏÓÒ¼ü²¢Ñ¡ÔñProperties£¬ÔÚWindow Style ²¿·Ö°ÑMinimizeBoxÉèÖÃΪ False¡£

    ÔÚ´úÂëÖÐת±ä´°Ìå·ç¸ñ
    ¼òµ¥µÄÔÚ´°ÌåµÄload¹¦ÄÜÖÐÌí¼ÓÒÔÏÂÒ»ÐдúÂ룺
    //C#
    this.MinimizeBox = false;

    'VB
    Me.MinimizeBox = False
    4.4. ÔõÑùÔÚ.net¾«¼ò¿ò¼ÜÉϽ¨Á¢¶à´°Ìåϵͳ½á¹¹£¿

    ÕâÆªÎÄÕÂÌÖÂÛÁËÈçºÎÔÚ.net¾«¼ò¿ò¼ÜÉÏΪӦÓóÌÐòÓÐЧµÄ½¨Á¢Óû§½çÃæ£º
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfuiframework.asp

    4.5. ÔõÑùÌá¸ß.net¾«¼ò¿ò¼ÜÓ¦ÓóÌÐòµÄÔØÈëËÙ¶È£¿

    ͨ¹ýÏÂÃæÎÄÕÂÖеÄÓÅ»¯¼¼ÇÉ£¬¼õÉÙ.net¾«¼ò¿ò¼ÜÓ¦ÓóÌÐòµÄÔØÈçʱ¼ä£º
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfimproveformloadperf.asp

    4.6. ÔËÐÐʱÔõÑùÐ޸Ĵ°ÌåµÄ·ç¸ñ£¿

    ÕâÆª¿ìËÙÈëÃŽ̳ÌÃèÊöÁËÔÚpocket pcÓ¦ÓóÌÐòÖÐʹÓôúÂë¸Ä±ä´°Ìå½çÃæ£º
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/ppcformproperties.aspx

    4.7. ÔõÑù¹ö¶¯´°ÌåµÄÄÚÈÝ£¿

    ÕâÆª¿ìËÙÈëÃŽ̳ÌÑÝʾÁËÈçºÎʹÓÃ×ÝÏòºÍºáÏò¹ö¶¯Ìõ »¹ÓÐÈçºÎÔÚ´°ÌåÖлæÖÆÒ»¸öͼÏó£º
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/scrolling.aspx

    4.8. ÔõÑùÖÆ×÷Ò»¸ö¸¡¶¯µÄ´°Ì壿ºÃÏóËùÓеĴ°Ìå×ÜÊÇÈ«ÆÁ״̬µÄ¡£

    Óб߽çµÄ×î¶¥¶ËµÄ´°Ìå×ÜÊÇÈ«ÆÁµÄ£¬²»ÄÜÒÆ¶¯»ò¸Ä±ä´óС¡£Ã»Óб߽ç»ò×Ó´°Ìå¿ÉÒÔÒÆ¶¯ºÍ¸Ä±ä´óС¡£

    ʹÓ㺠Form.BorderStyle = BorderStyle.None;  //À´ÉèÖÃÓÐÎޱ߽ç

    4.9. ÔõÑùÇ¿ÆÈÒ»¸ö´°Ìå±ä³É×îС»¯£¿

    Çë²é¿´±¾ÎÊ "6.6. ÈçºÎÊÇ´°¿ÚÒ»Ö±±£³Ö×îС»¯£¿ " ²¿·Ö¡£

    4.10. ÎÒÓÐÒ»¸ö°üº¬ºÜ¶à¿Ø¼þµÄÖÇÄÜÉ豸´°Ì壬ΪʲôÔËÐеÄʱºò³öÏÖ"NotSupportedException"´íÎó£¿

    Èç¹ûÄãµÄ´°ÌåÖаüº¬ÁËºÜ¶à¿Ø¼þ£¬µ±ÄãÔËÐеÄʱºò¿ÉÄÜ»áÓÐNotSupportedExceptionµÄ´íÎó¡£Èç¹ûÄãÊÇÔÚDebugģʽÏÂÔËÐеϰ£¬Äã»á·¢ÏÖÒì³£ÊÇÀ´×ÔÓÚ´°ÌåµÄInitializeComponent²¿·Ö¡£ÕâÖÖÇé¿öÊÇÓÉÓÚ¾«¼ò¿ò¼ÜCLRÔÚ±àÒëÀàµÄ·½·¨Ê±£¬»áÓÐ64kbµÄÏÞÖÆÔì³ÉµÄ¡£ÕâÒâζ×Å CLR°Ñ·½·¨£¨È磬InitializeComponent£©·­Òë³ÉÖмäÓïÑÔʱ£¬·µ»ØµÄ»úÆ÷Âë²»Äܳ¬¹ý64KB¡£Èç¹û³¬¹ýÁË64KB£¬ NotSupportedException½«±»Å׳ö¡£ÕâÒ²ÊÇΪʲôÈÝÒ×ÔÚDebugģʽ(F5)ϵ¼Ö´íÎ󣬶ø·ÇDebugģʽ(Ctrl+F5)È´²»ÈÝÒ׳ö´í¡£ÒòΪDebugģʽÔËÐÐʱ»áÉú³É¸ü¶àÈÝÁ¿µÄµ÷ÊÔ´úÂë¡£

    ³ýÁËÄ£ÄâÆ÷£¬ÄúÒ²¿ÉÄÜÔÚÖÇÄÜÉ豸ÉÏÓöµ½Õâ¸ö´íÎó£¬ÒòΪ¼´Ê±±àÒë´úÂë¸ù¾ÝÒòCPUÀàÐͶøÒìµÄ£¨È磬PocketPCʹÓõÄÊÇARMÖ¸Á¶øÄ£ÄâÆ÷ÉÏʹÓõÄx86Ö¸Á

    ûÓÐÒ»¸ö׼ȷµÄÊý×Ö˵Ã÷£¬Ò»¸ö´°ÌåÖе½µ×¿ÉÒÔ°üº¬¶àÉÙ¸ö¿Ø¼þ¡£ÒòΪ²»Í¬¿Ø¼þµÄ²úÉúµÄ´úÂëÁ¿²»Ò»Ñù¡£È磬һ¸öButton¿Ø¼þ£¬±ÈTabControl¿Ø¼þ²úÉúµÄ´úÂëÒªÉÙ¡£»¹»áÒòÓÉÉèÖÃÁ˶àÉÙÊôÐÔ¶øÒì¡£°üº¬¼¯ºÏµÄ¿Ø¼þ£¬ÏóListBox»òTreeView£¬Èç¹ûÔÚÉè¼ÆÊ±ÏòÊôÐÔ¿òÖÐÌîÈëÁ˺ܶàÖµ£¬±àÒëʱ½«²úÉú´óÁ¿´úÂ롣ͬÑù£¬ÉèÖÃÁËLocalizedµÄ´°Ìå(LocalizableÊôÐÔΪtrue)£¬»á±ÈûÉèÖÃlocalizeµÄ´°Ìå²úÉú¸ü¶à´úÂë¡£ÒòΪ localizeÐèÒª´Ó×ÊÔ´ÎļþÖжÁÈ¡ÊôÐÔÖµ£¬·ÅÔÚInitializeComponent·½·¨ÖС£

    ¹ûÄãÓöµ½ÕâÖÖÇé¿ö£¬ÏÂÃæÓÐһЩ¼¼ÇɰïÖúÄã±ÜÃâËüµÄ·¢Éú£º
    • °ÑÒ»¸ö´°ÌåµÄ´úÂë·Ö³É¶à¸ö´°Ìå¡£¹ý¶à¿Ø¼þµÄ´°Ì壬»áÓ°Ïì³ÌÐò¿ªÊ¼Ê±ÔØÈëµÄÐÔÄÜ¡£¾¡¿ÉÄܰÑÓû§½çÃæ·Ö³ÉÁ½¸ö»ò¶à¸ö´°Ìå¡£
    • ²»ÒªÔÚÉè¼ÆÊ±Ìî³ä´óµÄ¡¢ÄÚ²¿µÄ¡¢´ø¼¯ºÏµÄ¿Ø¼þ¡£Èç¹ûÄã°ÑºÜ¶à½Úµã¼¯ºÏ¼Óµ½TreeView¿Ø¼þÖУ¬ÕâÑù»áÔÚInitializeComponent·½·¨ÖмÓÈë´óÁ¿´úÂë¡£¾¡¿ÉÄܰѼÓÈ뼯ºÏµÄ´úÂëÒÆµ½Form.LoadʼþÖС£ÕâÑù×öµÄȱµãÊÇ£¬ÒªÔÚÉè¼ÆÊ±±à¼­ÕâЩ¼¯ºÏ½«±äµÃ²»ÈÝÒ×£¬µ«ËüÓÐÖúÓÚ·Ö¸î´úÂë¡£
    • ²»Òª°Ñ×Ô¼ºµÄ´úÂëÌí¼Óµ½InitializeComponent·½·¨ÖУ¬Õâ¶Ôͨ³£µÄ±àÂë¶¼ÓÐÓ㬲»½¨ÒéÌí¼Ó¡¢ÐÞ¸ÄÉè¼ÆÆðÉú³ÉµÄ´úÂë¡£ÕâÑù×ö»áÔì³ÉÉè¼ÆÆ÷²»¿ÉÖªµÄ´íÎó¡£Èç¹ûÄãÏëÌí¼Ó×Ô¼ºµÄÆô¶¯´úÂ룬ÄãÓ¦¸ÃÔÚForm.LoadʼþÖÐ×ö¡£
    • ÔËÐÐʱ³õʼ»¯ÀàËÆµÄ¿Ø¼þ¡£±ÈÈ磬ÓÐ12¸öButton¿Ø¼þ£¬Ö»ÊÇÎÄ×ÖºÍλÖò»Í¬£¬ÄãÓ¦¸Ã¿¼ÂÇʹÓÃÑ­»·À´ÉèÖÃÊôÐÔ£¬¶ø²»ÊÇÔÚÉè¼ÆÊ±ÉèÖÃÊôÐÔ¡£ÔڴΣ¬Èç¹ûÄã×Ô¼ºÐ´´úÂëÀ´ÊµÏÖËü£¬²»Òª°Ñ´úÂë·ÅÔÚInitializeComponent·½·¨ÖС£

    ±à¼­InitializeComponent·½·¨µÄȱµãÊÇ£¬ÔÚInitializeComponent´úÂëÍ⽨Á¢¶ÔÏóʵÀýµÄ´úÂ룬½«²»ÄÜÔÚÉè¼ÆÆ÷ÖØ±»Éè¼Æ¡£Í¬Ñù£¬Èç¹ûÄãÊÖ¶¯ÐÞ¸ÄÁËInitializeComponentÖеĴúÂ룬Äã»á·¢ÏÖ£¬Éè¼ÆÆ÷¿ÉÄܲ»ÔÙʶ±ðÄãÐ޸ĵĴúÂë¡£ËùÒÔÒÔÉϼ¼ÇɵÄǰÌáÊÇ£¬²»ÒªÐÞ¸ÄInitializeComponentÖеĴúÂë¡£

    4.11. ÄĸöÊÇÕýÈ·¹Ø±Õ´°ÌåµÄ·½·¨£ºAppplication.Exit »¹ÊÇ Form.Close £¿

    Application.ExitÊÇÀàËÆWin32ƽ̨ϵÄPostQuitMessage()Ó²ÐÔÍ˳ö¡£ÊÕ»ØËùÓе¯³öµÄÐÅÏ¢£¬Êͷźô½Ð¶ÑÕ»£¬°ÑÖ´ÐÐȨ·µ»Ø¸øÏµÍ³¡£

    ÔÚwindowsƽ̨(Win32»ò.NET)ÏÂÕýÈ·¹Ø±ÕÓ¦ÓóÌÐòµÄ·½·¨ÊǹرÕÖ÷´°Ìå(È磺Form.Close)¡£ËùÓÐÖ÷´°Ìå½áÊøÊ±ÈÔ´æÔڵĴ°ÌåÐèÒªÊÖ¹¤¹Ø±Õ¡£Any window that's still present after the main message pump ends needs to be manually closed. ºÃµÄ·½·¨¾ÍÊÇÔÚÓ¦ÓóÌÐòµ÷ÓÃForm.Close»òForm.DisposeÍ˳ö֮ǰ£¬¹Ø±ÕËùÓд°Ìå¡£ÐèÒª¼Çס.NET¿ò¼ÜµÄOnClosing()¾ÍÊÇWin32ƽ̨ÏÂWM_CLOSEµÄÍйܰ汾£¬¶ø²»ÊÇWM_DESTROY¡£

    ÁíÍ⣬ʹÓÃform.Close()µÄ»°£¬ÄãµÄ³ÌÐò¿ÉÒÔÔÚOnClosing»òOnClosedʼþÖд¦ÀíÊÍ·Å×ÊÔ´¡¢¹Ø±ÕÎļþµÈ²Ù×÷¡£Èç¹ûʹÓÃApplication.ExitÍ˳ö£¬ÕâЩʼþ½«²»»á±»´¥·¢¡£


    4.12. Why does showing a MessageBox on Windows Mobile 2003 for Smartphone with the Abort, Retry, and Fail set of buttons or the Yes, No, Cancel set of buttons, or the third button as the default button result in a NotSupportedException?

    Windows Mobile 2003 for Smartphone only supports 1 or 2 button MessageBoxes.

    4.13 How do I get an icon in the Pocket PC Start Menu Most Recently Used (MRU) List?

    Create a shortcut to your application somewhere under \windows\start menu\programs. When your application is launched from this shortcut an icon for your applications will appear the MRU list.



    4.14 How do I center a Form on the screen?

    In order to display a non-full screen Form, ensure that the Form's FormBorderStyle property is set to FormBorderStyle.None. To center the form add the following code to the Form's FormLoad event handler: Set FormBorderStyle to FormBorderStyle.None then:
    //c#
    Rectangle screen = Screen.PrimaryScreen.Bounds;
    this.Location = new Point((screen.Width - this.Width) / 2,
    (screen.Height - this.Height ) / 2);

    'VB
    Dim theScreen As Rectangle
    theScreen = Screen.PrimaryScreen.Bounds()
    Me.Location = New Point((theScreen.Width - Me.Width) / 2, _
    (theScreen.Height - Me.Height) / 2)
    4.15 Why can't I show a Form that has been closed?

    Once a Form is closed, it is disposed and therefore may be garbage collected by the system so it is not safe to attempt to show a closed Form. An alternative solution is to use Form.Hide and Form.Show to hide and display Forms respectively.

    4.16 How can I enable multiple instances of an application?

    Multi-instancing is not supported by the .NET Compact Framework. The following code sample provides a solution that allows applications to be instanced rather than maximized when an application is launched but a running instance already exists.

    Note: The following code is not supported and is not guaranteed to work on all versions of the OS, including future versions.
    // C#
    using System.Runtime.InteropServices;
    using System.Reflection;

    private void Form1_Load(object sender, System.EventArgs e)
    {
    this.Text = string.Format("Form {0}", new Random().Next());
    }

    [DllImport("CoreDll")]
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    [DllImport("CoreDll")]
    public static extern int SetWindowText(IntPtr hWnd, string lpString);

    protected override void OnResize(EventArgs e)
    {
    Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
    IntPtr hWnd = FindWindow("#NETCF_AGL_PARK_",
    asm.GetModules()[0].FullyQualifiedName);

    if (hWnd != IntPtr.Zero)
    SetWindowText(hWnd, "#42");

    base.OnResize (e);
    }

    'VB
    Imports System.Runtime.InteropServices
    Imports System.Reflection

    Private Sub Form1_Load(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Text = String.Format("Form {0}", New Random().Next())
    End Sub 'Form1_Load

    <DllImport("CoreDll")> _
    Public Shared Function FindWindow(ByVal lpClassName As String, _
    ByVal lpWindowName As String) As IntPtr
    End Function

    <DllImport("CoreDll")> _
    Public Shared Function SetWindowText(ByVal hWnd As IntPtr, _
    ByVal lpString As String) As Integer
    End Function

    Protected Overrides Sub OnResize(ByVal e As EventArgs)
    Dim asm As [Assembly] = System.Reflection.Assembly.GetExecutingAssembly()
    Dim hWnd As IntPtr = FindWindow("#NETCF_AGL_PARK_", _
    asm.GetModules()(0).FullyQualifiedName)
    If hWnd.ToInt32() <> IntPtr.Zero.ToInt32() Then
    SetWindowText(hWnd, "#42")
    End If
    MyBase.OnResize(e)
    End Sub 'OnResize

     


    5. ͼÐÎÓû§½çÃæ (GUI): ͨÓÃ


    5.1. ÔõÑù½¨Á¢Ò»¸ö´øÓÐͼÐλòÖ§³Ö¶àÐеİ´Å¥£¿

    ½¨Á¢Ò»¸ö´øÓÐͼÐλòÖ§³Ö¶àÐеİ´Å¥ÐèҪʹÓÃ×Ô¶¨Òå¿Ø¼þ¡£×Ô¶¨Òå¿Ø¼þÄܼ̳ÐbuttonµÄpaint·½·¨£¬ÒÔ¼°ÆäËûÈκÎÐèÒªµÄ×Ô¶¨ÒåÊý¾Ý¡£²Î¿¼ÒÔÏÂÁ¬½Ó»ñµÃ¸ü¶à¹ØÓÚ×Ô¶¨Òå¿Ø¼þµÄÐÅÏ¢£º

    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/customctrlscompactfx.asp

    ¿ìËÙÈëÃŽ̸̳æËßÄãÈçºÎ½¨Á¢Ò»¸ö´øÍ¼ÏñµÄ°´Å¥£º
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/picturebutton.aspx

    5.2. TextBox.AcceptsReturnÔÚ.net¾«¼ò¿ò¼ÜÏÂÊÇÔõÑù¹¤×÷µÄ£¿

    ËäÈ»ÉèÖÃÁËAcceptsReturnΪfalse£¬µ«Ëü»¹Êǰ´trueµÄ·½Ê½À´²Ù×÷¡£Äã¿ÉÒÔдһ¸ö¼Ì³ÐTextBoxµÄÀ࣬ÔÚKeyPressʼþÖÐʵÏÖ¶ÔEnterµÄ´¦Àí¡£

    5.3. µ±Êý¾ÝÔØÈëComboBoxµÄʱºò£¬ÎªÊ²Ã´SelectedIndexChangedʼþûÓб»´¥·¢£¿

    ÕâÊÇÒ»¸öÒѾ­ÖªµÀµÄÎÊÌ⣬½«ÔÚÒÔºóµÄ.net¾«¼ò¿ò¼ÜÖз¢²¼¡£

    5.4. ShowºÍShowDialogÓÐʲô²»Í¬£¿

    ShowDialog»á°ÑÒ»¸ö´°ÌåÒÔ Ä£Ê½ ·½Ê½ÏÔʾ£¬ÕâÊÇÒ»ÖÖ¶ÀÕ¼µ÷Ó÷½Ê½£¬ÖªµÀ´°Ì幨±Õ²Å»á·µ»Ø¡£Õâ¸ö·½·¨½«·µ»ØÒ»¸öDialogResultö¾Ù£¬±íʾ¹Ø±ÕµÄÌõ¼þ¡£
    ShowÊÇÒ»ÖַǶÀÕ¼µÄµ÷Ó÷½Ê½£¬ºÍÏÔʾһ¸ö¿Ø¼þÒ»Ñù£¬¿ÉÒÔÁ¢¿Ì·µ»Ø£¬Ã»Óзµ»Ø²ÎÊý¡£ÏÔʾһ¸ö¿Ø¼þÒâζ×ÅVisibleÊôÐÔ±»ÉèÖÃΪtrue£¬Ö±µ½Hide·½·¨±»µ÷Óã¬Visible·½·¨²Å»á±äΪfalse¡£

    5.5. ΪʲôÎÒ²»Äܽ¨Á¢ÓÒ¼ü²Ëµ¥·ÖÀëÆ÷£¿(separator)

    ÕâÊÇÒ»¸öÒѾ­ÖªµÀµÄBUG£¬°ÑÓÒ¼ü²Ëµ¥ÉèÖÃΪ·Ö¸îÏߣ¬½«Å׳öNotSupportedException´íÎó¡£Õâ¸öÎÊÌâÊÇÓÉÓÚWinCEϵͳÓиöÏÞÖÆ£¬²»ÔÊÐíÔÚÒѾ­¼ÓÈëÓÒ¼ü²Ëµ¥µÄ²Ëµ¥ÏîÉèÖÃΪ·Ö¸ô·û£¬²¢ÇҲ˵¥µÄ¸¸ÀàÊÇÒ»¸ö¿Ø¼þ¡£ÔÚVisual Studio 2003ÖÖ£¬Éè¼ÆÆ÷·Ö¸îÒÆ¶¯Ó¦ÓôúÂëµÄ·½Ê½ºÍPCÉϵÄÓ¦ÓóÌÐòÀàËÆ¡£ÕâÊǵ¼Ö´ËÎÊÌâµÄÔ­Òò¡£½â¾öµÄ·½·¨ÊÇ£¬°ÑÓÒ¼ü²Ëµ¥µ¥¶À·ÅÔÚInitilizeComponent·½·¨ÍâµÄµØ·½¡£

    5.6. ÔËÐÐʱ°ÑImageList¸³¸øToolBarʱ£¬ÎªÊ²Ã´Í¼Ïó²»³öÏÖ£¿

    Äã¿ÉÒÔÔÚ´°ÌåÔØÈëµÄʱºò°ÑImageList·ÖÅ䏸ToolBar£¬µ«ÖØÐÂÓ¦ÓÃͼÏñÔÚToolBarÉϵÄ˳Ðò¡£ÔÚÉèÖÃToolBarµÄImageList֮ǰ ÉèÖÃToolBar°´Å¥µÄͼÏñ˳ÐòÊDz»±»Ö§³ÖµÄ¡£

    5.7. ÔõÑù°Ñ¹â±êÉèÖóɵȴý״̬£¿

    Õâ¶Î´úÂë¿ÉÒ԰ѹâ±êÉèÖóɵȴý¹â±ê£º

  • //C#
    Cursor.Current = Cursors.WaitCursor;

    'VB
    Cursor.Current = Cursors.WaitCursor
    Õâ¶Î´úÂë¿ÉÒ԰ѹâ±êÉèÖÃΪĬÈÏ£º
    //C#
    Cursor.Current = Cursors.Default;

    'VB
    Cursor.Current = Cursors.Default
    5.8. ÈçºÎÔڲ˵¥ÏîÖÐÏÔʾ·ûºÅ£º&£¿

    ÕâÏÄÜ»¹²»±».net¾«¼ò¿ò¼ÜÖ§³Ö¡£Ê¹ÓÃ"&&"²»»áÔڲ˵¥ÏîµÄÎÄ×ÖÖÐÏÔʾ"&"·ûºÅ¡£

    5.9. ÈçºÎÖÆ×÷»ùÓÚ.net¾«¼ò¿ò¼ÜµÄ¶¯»­¿Ø¼þ£¿

    ÕâÆªÎÄÕ½«¸æËßÄãÈçºÎÖÆ×÷»ùÓÚ.net¾«¼ò¿ò¼ÜµÄ¶¯»­¿Ø¼þ£º
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/animationcontrol.asp

    5.10. ÈçºÎÔÚ.net¾«¼ò¿ò¼ÜÉÏÖÆ×÷×Ô¶¨Òå¿Ø¼þ£¿

    Ñ§Ï°ÖÆ×÷.net¾«¼ò¿ò¼Ü¿Ø¼þ£¬Ìá¸ßÄúµÄ¼¼ÇÉ¡£(ÎÄÕ¸½´øÁË×Ô¶¨Òå¿Ø¼þµÄʾÀý´úÂë)£º
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/customctrlscompactfx.asp

    5.11. ÈçºÎÖÆ×÷»ùÓÚ.net¾«¼ò¿ò¼ÜµÄ´øÍ¼Æ¬µÄ°´Å¥£¿

    ÕâÆªÎÄÕÂÌÖÂÛÁ˽¨Á¢»ùÓÚ.net¾«¼ò¿ò¼ÜµÄ´øÍ¼Æ¬µÄ°´Å¥£º
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/ImageButton.asp

    5.12. ÈçºÎʹÓÃ.net¾«¼ò¿ò¼ÜϵÄMessageWindowÀà¿â£¿

    ѧϰÈçºÎʹÓÃ.net¾«¼ò¿ò¼Ü MessageWindow ÀཨÁ¢Ò»¸öÌáʾͼ±ê£º
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/messagewindow.asp

    ÕâÆª¿ìËÙÈëÃÅʵÏÖÁË£¬µ±Êó±êµã»÷¾ØÐÎ×Ô¶¨Òå¿Ø¼þ»òµã»÷Panel¿Ø¼þʱ£¬Ê¹ÓÃMessageWindow°ÑÏûÏ¢·¢Ë͸ø·¢ËÍ´°Ì壺
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/messagewindow.aspx

    5.13. ÈçºÎÏòDataGridÖÐÌí¼ÓÐкÍÁУ¿

    ÕâÆª¿ìËÙÈëÃŽ̳̽âÊÍÁËÈçºÎÔÚÔËÐÐʱÏòDataGrid¿Ø¼þÌí¼Ó»òɾ³ýÐС¢ÁУº
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/datagridadding.aspx

    5.14. ÈçºÎʵÏÖDataGridµÄ±à¼­£¿

    .net¾«¼ò¿ò¼ÜÖеÄDataGrid¿Ø¼þÌṩÁ˼¸ºõ.net¿ò¼ÜÖеÄDataGrid¿Ø¼þµÄËùÓй¦ÄÜ¡£Ò»¸öÖ÷ÒªµÄÇø±ðÊÇ.net¾«¼ò¿ò¼ÜÖеÄDataGrid²»ÄÜÔÚÔËÐÐʱ±à¼­µ¥Ôª¡£ÕâÆª¿ìËÙÈëÃŽ̳ÌÑÝʾÁËÈçºÎͨ¹ý³ÌÐòʵÏֱ༭µ¥Ôª¸ñµÄÒ»ÖÖ·½·¨£º
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/datagridediting.aspx

    5.15. ÔõÑùÉèÖÃDataGridµÄDataSource£¿

    Óë.net¿ò¼ÜµÄDataGridµÄÁíÒ»¸öÇø±ðÊÇ£¬.net¾«¼ò¿ò¼ÜµÄDataGrid²»Ö§³Ö°ÑDataSourceÉèÖÃΪDataSet¡£
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/datagrid.aspx

    5.16. ÔõÑù¶ÔDataGridµÄÁÐÅÅÐò£¿

    Óë.net¿ò¼ÜµÄDataGridµÄÁíÒ»¸öÇø±ðÊÇ£¬.net¾«¼ò¿ò¼ÜµÄDataGrid²»Ö§³ÖÔÚÔËÐÐʱ°´ÕÕÁнøÐÐÅÅÐò¡£
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/datagridsorting.aspx

    5.17. ÔõÑù¶ÔListViewÖеÄÄÚÈÝÅÅÐò£¿

    .net¾«¼ò¿ò¼Ü²»Ö§³ÖListView.Sort·½·¨£¬µ«ÈÎÈ»¿ÉÒÔÅÅÐò¡£ÕâÆª¿ìËÙÈëÃŽ̶̳¨ÒåÁËÒ»¸ö¼Ì³ÐArrayList.SortµÄIComparable½Ó¿ÚµÄ·½·¨:
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/listviewsort.aspx

    5.18. ÈçºÎʹÓà ÊäÈë°å(SIP)¿Ø¼þ£¿

    ÕâÆª¿ìËÙÈëÃŽ̳ÌÑÝʾÁËÔÚPocketPCÉÏ´ò¿ªºÍ¹Ø±ÕÈíÊäÈë°å(SIP)£¬ÒÔ¼°µ±SIPÏÔʾʱ£¬tab¿Ø¼þ´óСҲ¸úËæ±ä»¯£º
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/inputpanel.aspx

    ¶à¸ö´°ÌåÓ¦¸Ã¹²ÏíÒ»¸öÊäÈë°å¶ÔÏ󡣿ÉÒÔͨ¹ýÏÈÔÚÖ÷´°ÌåÖн¨Á¢SIP¶ÔÏó£¬È»ºó°ÑËü´«¸ø×Ó´°Ìå»ò±©Â¶SIP¶ÔÏóµÄһЩ·½·¨¡¢ÊôÐÔ¸øÆäËûÐèҪʹÓÃSIPµÄ´°Ìå¡£

    5.19. ÈçºÎ×Ô¶¨Òåʼþ£¿

    ÕâÆª¿ìËÙÈëÃŽ̳ÌÃèÊöÁËÈçºÎ¼Ì³ÐButtonÀà¡¢ÖØÔØ·½·¨À´ÊÂÏÖË«»÷ʼþ¡£Õâ¸ö×Ô¶¨Òåʼþ»áÔÚ°´Å¥±»Ë«»÷ʱ´¥·¢£¬Á½´Îµã»÷µÄ¼ä¸ôʱ¼äÊÇSystemInformation.DoubleClickTime ÊôÐÔµÄÖµ£¬ÒÔºÁÃëΪµ¥Î»¡£
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/btndclick.aspx

    .net¾«¼ò¿ò¼ÜµÄ¿Ø¼þ²»Ö§³ÖOnEnterºÍOnLeave·½·¨£¬°üÀ¨Windows.Forms.Control»ùÀà¡£µ«ÊÇ£¬ÒòΪ֧³ÖControl.OnMouseMove·½·¨£¬Äú¿ÉÒÔͨ¹ýËüºÍControl.Capture ÊôÐÔÅжÏÊó±êʲôʱºò½øÈëºÍÀ뿪¿Ø¼þ¡£
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/enterleave.aspx

    5.20. ÈçºÎ×öÒ»¸ö owner-drawn List Box?

    Äú¿ÉÒÔÖÆ×÷Ò»¸ö.net¾«¼ò¿ò¼ÜµÄowner drawn list box¡£.net¾«¼ò¿ò¼ÜµÄListBox»òÆäËû¿Ø¼þ²»Ö§³ÖDrawMode¡¢DrawItem£¬ »òÆäËûdrawing·½·¨£¬µ«Äú¿ÉÒÔ±à³ÌʵÏÖ¡£ÕâÆª¿ìËÙÈëÃŽ̳ÌÌṩһ¸ö×Ô¶¨Òå¿Ø¼þÀ࣬½¨Á¢Ò»¸öowner-drawn list box£¬²¢ÊµÏÖÁËÑ¡Ôñ×ÖÌåµÄ¿Ø¼þµÄ¹¦ÄÜ¡£
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/ownerdrawnlistbox.aspx

    5.21. ÈçºÎ×öÒ»¸ö¶àÑ¡¿òÅжÏÕæ¼Ù£¿

    ÕâÆª¿ìËÙÈëÃŽ̳ÌÌṩÁËÔÚWindows.Forms.CheckBox¿Ø¼þÉϽ¨Á¢Õæ/¼Ù¶àÑ¡¿ò£º
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/tfcheckbox.aspx

    5.22. ÉèÖÃInputPanel.Enabled = trueµÄʱºòΪʲô³öÏÖÒì³££¿

    InputPanel×é¼þÐèÒª´°Ìå°üº¬MainMenu¿Ø¼þ£¬¶øÇÒÄǸö´°ÌåÊÇÏÔʾÔÚÆÁÄ»Éϵġ£

    5.23. Ϊʲô×Ô¶¨Òå¿Ø¼þ²»»á×Ô¶¯¼Ì³Ð¸¸ÀàµÄ×ÖÌ壿

    Õâ¸ö¹¦Äܲ»±».net¾«¼ò¿ò¼ÜËùÖ§³Ö¡£

    5.24. Ϊʲôµ±ÊäÈë×Ö·ûʱ£¬NumericUpDown ºÍ DomainUpDown ¿Ø¼þ²»»áÒý·¢ ValueChanged ºÍ SelectedItemChanged ʼþ£¿

    ÔÚ´úÂëÖÐ¸Ä±ä¿Ø¼þµÄÖµ »ò °´ÏÂÁËÉÏ¡¢Ï¼ýÍ·²Å»á´¥·¢ValueChangedºÍSelectedItemChangedʼþ¡£µ±Óû§Íù¿Ø¼þÖÐÊäÈë×Ö·ûµÄʱºòʱ²»»á´¥·¢µÄ¡£

    5.25. ΪʲôNumericUpDown¿Ø¼þÔö³¤µÄÖµ²»ÊÇÉèÖúõÄÖµ£¿

    µ±Äú°´ÁËÉÏ¡¢Ïºó³öÏÖµÄÖµ£¬²»ÊÇÔö³¤ÖµµÄ±¶Êý£¬Ëü½«Ïò×ÅÄǸö·½Ïò(ÉÏ»òÏÂ)Ö±µ½ÏÂÒ»¸öÔö³¤ÖµµÄ±¶ÊýµÄÖµ¡£

    5.26. ΪʲôStatusBar²»ÄÜ·ÅÔÚ´°ÌåµÄÈÎÒâλÖã¿Ò»¶¨ÒªÔڵײ¿£¿

    StatusBar¿Ø¼þÖ»ÄÜÍ£¿¿ÔÚ´°ÌåµÄµ×²¿£¬ËüµÄ´óС²»Äܸı䡣

    5.27. ΪʲôÎҵĿؼþ×Ô¶¯¼Ì³ÐÁ˸¸¿Ø¼þµÄ±³¾°É«£¿

    Õâ¸ö¹¦Äܲ»±».net¾«¼ò¿ò¼ÜËùÖ§³Ö¡£¿ÉÒÔ²ÉÈ¡µÄ·½·¨ÊǼ̳ÐOnParentChanged·½·¨ÊÖ¶¯ÉèÖÃÑÕÉ«£º
    //C#
    protected override void OnParentChanged(EventArgs e)
    {
    base.OnParentChanged(e);
    this.BackColor = Parent.BackColor;
    }

    'VB
    Protected Overrides Sub OnParentChanged(ByVal e As EventArgs)
    MyBase.OnParentChanged(e)
    Me.BackColor = Parent.BackColor
    End Sub 'OnParentChanged
    5.28. ΪʲôNumericUpDown¿Ø¼þÄܽÓÊÜdecimalÀàÐ͵ÄÖµ£¬µ«²»»áÏÔʾ´óÓÚ2^16µÄÖµ£¿

    ËäÈ»NumericUpDown¿Ø¼þ½ÓÊÜdecimalÀàÐ͵ÄÖµ£¬µ«.net¾«¼ò¿ò¼Ü°ÑÕâ¸ö¿Ø¼þµÄÖµµ±×÷intÀàÐÍÀ´´¦Àí¡£È磬10.23µ±×÷10¡£Í¬Ñù´Ë¿Ø¼þÔÚPocketPCÉϲ»½ÓÊÜ´óÓÚ´ø·ûºÅµÄ16λÕûÐÍ¡£

    5.29. Ϊʲô²»ÄÜÔÚDomainUpDown ÖÐÊäÈëÎÄ×Ö£¬¶øÒªÑ¡Ôñ£¿

    DomainUpDown¿Ø¼þ²»»á¶ÔÊäÈëµÄÎÄ×Ö½øÐÐÈ·ÈÏ(²»ÏóÍêÕûµÄ.net¿ò¼Ü)¡£Èç¹ûÄúÏÈÊäÈëÁËһЩÎÄ×Ö£¬ÔÙ°´ÉÏ¡¢Ï¼ýÍ·£¬Ëü»áÏÔʾÄÚÈݸıäǰµÄÖµµÄÏÂÒ»¸öÖµ¡£

    5.30. ΪʲôOpenFileDialog±»ÏÞÖÆÔÚ"My Documents" Îļþ¼ÐÖУ¿

    OpenFileDialogµÄ³õʼ»¯Ä¿Â¼±»ÏÞÖÆÔÚ"My Documents"Îļþ¼Ð»òËüµÄ×ÓÎļþ¼ÐÖС£Õâ¸öÏÞÖÆÊÇÓÉPocketPCϵͳǿ¼ÓµÄ£¬ÎªÁ˰ïÖúÓû§ÔÚ±ê׼Ŀ¼Ï¹ÜÀí×Ô¼ºµÄÎĵµ¡£
      5.31. How can I activate the SIP (InputPanel) without a menu?

    The SIP can be activated by P/Invoking the function "SipShowIM" as follows.
    //C#
    using System.Runtime.InteropServices;

    const uint SIPF_OFF = 0x0;
    const uint SIPF_ON = 0x1;

    [DllImport("coredll.dll")]
    private extern static void SipShowIM(uint dwFlag);

    'VB
    Imports System.Runtime.InteropServices

    Const SIPF_OFF As Integer = &H0
    Const SIPF_ON As Integer = &H1

    <DllImport("coredll.dll")> _
    Private Shared Function SipShowIM(ByVal dwFlag As Integer) As Integer
    End Function
    5.32. How do I add a subnode to every node in a TreeView?

    Adding subnodes to all nodes is accomplished by iterating through all of the nodes in the TreeView and adding a new node to each.
    //C#
    foreach (TreeNode node in treeView1.Nodes)
    {
        node.Nodes.Add(new TreeNode("SubNode"));
    }

    'VB
    Dim node As TreeNode
    For Each node In  treeView1.Nodes
        node.Nodes.Add(New TreeNode("SubNode"))
    Next node
    5.33. How do I determine the number of rows or columns in a DataGrid?

    The number of rows and columns in a DataGrid can be determined from the data source itself. For example:
    //C#
    DataSet ds = new DataSet();

    int numRows = ds.Tables[0].Rows.Count;
    int numCols = ds.Tables[0].Columns.Count;

    'VB
    Dim ds As New DataSet()

    Dim numRows As Integer = ds.Tables(0).Rows.Count
    Dim numCols As Integer = ds.Tables(0).Columns.Count
    If the DataGrid is bound to the DataView you can also use DataView.Count.

    5.34. How do I create a owner drawn Listbox?

    See the .NET Compact Framework QuickStarts, Implementing Events topic:

    http://samples.gotdotnet.com/quickstart/compactframework/doc/btndclick.aspx

    5.35. How can I implement Control.GetNextControl under the .NET Compact Framework?

    The tab order of the controls in the .NET Compact Framework correspond directly to the order of the Controls in the Form.Controls collection. Therefore, GetNextControl can be implemented by determining the index of the specified Control and determing its neighbors in the collection.
    //C#
    public Control GetNextControl(Control ctl, bool forward)
    {
    int curIndex = this.Controls.IndexOf(ctl);

    if (forward)
    {
    if (curIndex < this.Controls.Count)
    curIndex++;
    else
    curIndex = 0;
    }
    else
    {
    if (curIndex > 0)
    curIndex--;
    else
    curIndex = this.Controls.Count - 1;
    }

    return this.Controls[curIndex];
    }

    'VB
    Public Function GetNextControl(ByVal ctl As Control, _
    ByVal forward As Boolean) As Control
    Dim curIndex As Integer = Me.Controls.IndexOf(ctl)

    If forward Then
    If curIndex < Me.Controls.Count Then
    curIndex += 1
    Else
    curIndex = 0
    End If
    Else
    If curIndex > 0 Then
    curIndex -= 1
    Else
    curIndex = Me.Controls.Count - 1
    End If
    End If

    Return Me.Controls(curIndex)

    End Function 'GetNextControl
    5.36. How do I get notified when the user clicks on a treeview node?

    TreeView does not support the Click event, however, a workaround is to use the AfterSelect event instead.

    5.37. How do I set the title of a fullscreen multiline edit control window?

    This is not supported by the current version of the .NET Compact Framework.

    5.38. Why don' I see the validItem selected when I set ComboBox.SelectedValue to validItemInCollection?

    Setting the SelectedValue property only works if the control is databound.

    5.39. How do I detect the location where a 'tap & hold' occurred to bring up a context menu on my custom control?

    Handle the ContextMenu.Popup event, and then query the current mouse coordinates using 'Control.MousePosition'.

    5.40. Why doesn't the scrollbar value ever get set to the maximum value?

    Similar to the NumericUpDown control, the maximum achievable value is the first empty row above the thumb. More specifically, from the editor properties, this equates to:

    Maximum - (LargeChange + 1).

    5.41. How do I tab out of a custom control to the previous control?

    Call this.Parent.Controls(this.Parent.GetChildIndex(customcontrol) - 1).Focus() in the KeyDown event handler when a Keys.Up key is detected.

    5.42. How do I add Toolbar buttons with transparency?

    Icons support transparency, however, there is a known bug in Visual Studio .NET 2003 designer that creates incorrect code and makes icons non-transparent. A work around is to add an icon file to the ImageList outside of InitializeComponent and add the icon files to the project as content or embedded resources. The following code demonstrates this:
    //C#
    using System.Drawing;
    using System.IO;
    using System.Reflection;

    // Loaded as content example
    private void Form1_Load(object sender, System.EventArgs e)
    {
    this.imageList1.Images.Add(new Icon(File.Open("fullFileName.ico",
    FileMode.Open)));

    this.toolBar1.Buttons[0].ImageIndex = 0;
    }

    // Loaded as a resource example
    private void Form1_Load(object sender, System.EventArgs e)
    {
    this.imageList1.Images.Add(new
    Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream(
    ".filename.ico")));

    this.toolBar1.Buttons[0].ImageIndex = 0;
    }

    'VB
    Imports System.Drawing
    Imports System.IO
    Imports System.Reflection

    ' Loaded as content example
    Private Sub Form1_Load1(ByVal sender As Object, ByVal e As System.EventArgs)

    Me.imageList1.Images.Add(New Icon(File.Open("fullFileName.ico", _
    FileMode.Open)))

    Me.toolBar1.Buttons(0).ImageIndex = 0

    End Sub 'Form1_Load1

    ' Loaded as a resource example
    Private Sub Form1_Load2(ByVal sender As Object, ByVal e As System.EventArgs)

    Me.imageList1.Images.Add(New _
    Icon([Assembly].GetExecutingAssembly().GetManifestResourceStream( _
    ".filename.ico")))

    Me.toolBar1.Buttons(0).ImageIndex = 0

    End Sub 'Form1_Load2
     

    6. Óë±¾µØ´úÂë(Native Code)»¥ÓÃ

    6.1. ÈçºÎµ÷Óñ¾µØ´úÂëдµÄ£Ä£Ì£ÌÖеĺ¯Êý£¿

    ±¾µØDLL´úÂë¿ÉÒÔͨ¹ýϵͳµÄInvoke (P/Invoke)·½·¨µ÷Óá£ÕâЩÎÄÕÂÌṩÁËÈçºÎʵÏÖµ÷Óú͸ü¶àµÄµ÷Óü¼ÇÉ£º

    6.2. ÈçºÎʹÓÃdumpbin.exe°ïÖúÃèÊö P/Invokes?

    ¼û±¾ÎÊ´ðµÄ "6.1. ÈçºÎµ÷Óñ¾µØÐ´µÄ£Ä£Ì£ÌÖеĺ¯Êý£¿ " Õ½ڡ£

    6.3. ÈçºÎΪ΢Èí.net¾«¼ò¿ò¼Üд·ÇÍйܴúÂ룿

    ¼û±¾ÎÊ´ðµÄ "6.1. ÈçºÎµ÷Óñ¾µØÐ´µÄ£Ä£Ì£ÌÖеĺ¯Êý£¿ " Õ½ڡ£

    6.4. ÈçºÎµ÷Óà P/Invoke GetTickCount?

    ²»ÐèҪʹÓÃP/Invokeµ÷ÓÃGetTickCount¹¦ÄÜ£¬ÒòΪEnvironment.TickCount¾ÍÌṩÁËÕâ¸ö¹¦ÄÜ¡£
    ¼û±¾ÎÊ´ðµÄ " 7.2. ÈçºÎ¼ÆË㾫ȷµÄʱ¼ä¼ä¸ô£¿" Õ½ڡ£

    6.5. ÈçºÎ»ñµÃϵͳ»¹ÓжàÉÙ¿ÉÓÃÄڴ棿

    Äú¿ÉÒÔµ÷ÓÃGetSystemMemoryDivisionºÍGlobalMemorySystemº¯£¬Êý»ñµÃ³ÌÐòºÍ´æ´¢Æ÷¼äÓжàÉÙÄÚ´æÊǸôÀëµÄºÍÒѾ­·ÖÅäµÄ¡£

    ²ÎÊýµÄ˵Ã÷¿ÉÒÔÔÚAPI²Î¿¼ÎĵµÖÐÕÒµ½¡£
    //C#
    using System.Runtime.InteropServices;

    public class MEMORYSTATUS
    {
    public uint dwLength;
    public uint dwMemoryLoad;
    public uint dwTotalPhys;
    public uint dwAvailPhys;
    public uint dwTotalPageFile;
    public uint dwAvailPageFile;
    public uint dwTotalVirtual;
    public uint dwAvailVirtual;
    }

    [DllImport("CoreDll.dll")]
    public static extern void GlobalMemoryStatus
    (
    MEMORYSTATUS lpBuffer
    );

    [DllImport("CoreDll.dll")]
    public static extern int GetSystemMemoryDivision
    (
    ref uint lpdwStorePages,
    ref uint lpdwRamPages,
    ref uint lpdwPageSize
    );

    public void Test()
    {
    uint storePages = 0;
    uint ramPages = 0;
    uint pageSize = 0;
    int res = GetSystemMemoryDivision(ref storePages, ref ramPages, ref pageSize);

    MEMORYSTATUS memStatus = new MEMORYSTATUS();
    GlobalMemoryStatus(memStatus);
    }

    'VB
    Imports System.Runtime.InteropServices

    Public Structure MEMORYSTATUS
    Public dwLength As UInt32
    Public dwMemoryLoad As UInt32
    Public dwTotalPhys As UInt32
    Public dwAvailPhys As UInt32
    Public dwTotalPageFile As UInt32
    Public dwAvailPageFile As UInt32
    Public dwTotalVirtual As UInt32
    Public dwAvailVirtual As UInt32
    End Structure 'MEMORYSTATUS

    <DllImport("coredll.dll")> _
    Private Shared Sub GlobalMemoryStatus(ByRef ms As MEMORYSTATUS)
    End Sub

    <DllImport("CoreDll.dll")> _
    Public Shared Function GetSystemMemoryDivision( _
    ByRef lpdwStorePages As UInt32, _
    ByRef lpdwRamPages As UInt32, _
    ByRef lpdwPageSize As UInt32) As Integer
    End Function

    Public Shared Sub Test()
    Dim storePages As UInt32
    Dim ramPages As UInt32
    Dim pageSize As UInt32
    Dim res As Integer = GetSystemMemoryDivision(storePages, ramPages, pageSize)

    Dim memStatus As New MEMORYSTATUS
    GlobalMemoryStatus(memStatus)
    End Sub 'Test
    6.6. ÈçºÎÊÇ´°¿ÚÒ»Ö±±£³Ö×îС»¯£¿
    1. ¼Ì³Ð´°ÌåµÄOnGotFocus·½·¨¡£
    2. ÕÒµ½´°ÌåµÄ´°¿Ú¾ä±ú¡£
    3. µ÷ÓÃShowWindow(hwnd, SW_MINIMIZE)Ç¿ÖÆ´°Ìå×îС»¯¡£
    //C#
    using System.Runtime.InteropServices;

    [DllImport("CoreDll")]
    public static extern IntPtr FindWindow(string className,string WindowsName);

    [DllImport("CoreDll")]
    public static extern bool ShowWindow(IntPtr hwnd,int nCmdShow);

    const int SW_MINIMIZE = 6;

    protected override void OnGotFocus(EventArgs e)
    {
    IntPtr hwnd = FindWindow(null, this.Text);
    ShowWindow(hwnd, SW_MINIMIZE);
    base.OnGotFocus(e);
    }

    'VB
    Imports System.Runtime.InteropServices

    <DllImport("CoreDll")> _
    Public Shared Function FindWindow(ByVal className As String, ByVal WindowsName As String) As IntPtr
    End Function

    <DllImport("CoreDll")> _
    Public Shared Function ShowWindow(ByVal hwnd As IntPtr,ByVal nCmdShow As Integer) As Boolean
    End Function

    Private Const SW_MINIMIZE As Integer = 6

    Protected Overrides Sub OnGotFocus(ByVal e As EventArgs)
    Dim hwnd As IntPtr = FindWindow(Nothing, Me.Text)
    ShowWindow(hwnd, SW_MINIMIZE)
    MyBase.OnGotFocus(e)
    End Sub 'OnGotFocus
    6.7. ÔÚ΢Èí.net¾«¼ò¿ò¼ÜÉϵ÷ÓÃϵͳº¯Êýʱ£¬ÈçºÎ×°ÅäÊý¾ÝÀàÐÍ£¿

    ¼û±¾ÎÊ´ðµÄ "6.1. ÈçºÎµ÷Óñ¾µØÐ´µÄ£Ä£Ì£ÌÖеĺ¯Êý£¿ " Õ½ڡ£

    6.8. ÈçºÎµÃµ½Ò»¸ö´°Ìå»ò¿Ø¼þµÄ¾ä±ú (HWND) £¿

    ÆäʵÓÐһЩʹÓõ÷Óñ¾µØ´úÂëµÄ·½·¨¿ÉÒÔ»ñµÃ¿Ø¼þµÄ¾ä±úHWND¡£ÏÂÃæÁгöÆäÖÐÁ½ÖÖ£¬Ò»ÖÖʹÓÃGetCapture£¬ÁíÒ»¸öʹÓÃFindWindow¡£
    //C#
    [DllImport("coredll.dll"]
    public static extern IntPtr GetCapture();

    [DllImport("coredll.dll")]
    public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);

    this.Text = "FindMe";
    IntPtr hwnd1 = FindWindow(null, "FindMe");

    this.Capture = true;
    IntPtr hwnd2 = GetCapture();
    this.Capture = false;

    'VB
    <DllImport("coredll.dll", SetLastError:=True)> _
    Public Shared Function GetCapture() As IntPtr
    End Function

    <DllImport("coredll.dll", SetLastError:=True)> _
    Public Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    End Function

    Me.Text = "FindMe"
    Dim deskWin As IntPtr = FindWindow(Nothing, "FindMe")

    Me.Capture = True
    Dim hwnd As IntPtr = GetCapture()
    Me.Capture = False
    6.9. ÈçºÎʹÓÃÐÔÄܼÆÊýÆ÷¹¦ÄÜ£¿

    ʹÓÃQueryPerformanceFrequencyº¯ÊýºÍQueryPerformanceCounterº¯Êý¿ÉÒÔ½¨Á¢¾«È·µÄ¼ÆÊ±³ÌÐò¡£ÕâЩ¹¦ÄÜÊǺÍÉ豸ÌṩÉÌÏà¹ØµÄ£¬Èç¹ûËûÃDz»ÄÜÖ´ÐУ¬ÄÇôֻÄܺÍGetTickCount¹¦Äܵõ½Ò»ÑùµÄ½á¹û¡£Èç¹ûÄÜÖ´ÐÐÕâЩº¯Êý£¬¾ÍÄܱ£Ö¤¼ÆÊ±Æ÷×î׼ȷµÄÔËÐУ¬±ÈGetTickCounter»òEnvironment.TickCount׼ȷµÃ¶à¡£TickCountÆäʵÊǵ÷Óà GetTickCounterµÄ¡£

    Èç¹ûÐÔÄܼÆÊýÆ÷ÊÇGetTickCountµÄÒ»¸öʵÀý£¬QueryPerformanceFrequency½«°Ñ1000×÷Ϊ¼ÆÊ±ÆµÂÊ¡£Èç¹ûÕâЩº¯Êý²»ÄÜÖ´ÐУ¬½«µÃµ½·µ»ØÖµÎª0¡£ÒÔÏ´úÂëÑÝʾÁËÈçºÎʹÓÃÕâЩº¯Êý¡£
    //C#
    [DllImport("CoreDll.dll")]
    public static extern int QueryPerformanceFrequency(ref Int64 lpFrequency);

    [DllImport("CoreDll.dll")]
    public static extern int QueryPerformanceCounter(ref Int64 lpPerformanceCount);

    private void TestTimer()
    {
    System.Int64 freq = 0;
    if (QueryPerformanceFrequency(ref freq) != 0)
    {
    System.Int64 count1 = 0;
    System.Int64 count2 = 0;

    if (QueryPerformanceCounter(ref count1) != 0)
    {
    System.Threading.Thread.Sleep(1200);
    QueryPerformanceCounter(ref count2);
    System.Int64 time_ms = (count2 - count1) * 1000 / freq;
    }
    }
    }

    'VB
    <DllImport("CoreDll.dll")> _
    Public Shared Function QueryPerformanceFrequency(ByRef lpFrequency As Int64) As Integer
    End Function

    <DllImport("coredll.dll")> _
    Public Shared Function QueryPerformanceCounter(ByRef lpPerformanceCount As Int64) As Integer
    End Function

    Private Sub TestTimer()
    Dim freq As System.Int64 = 0

    If QueryPerformanceFrequency(freq) <> 0 Then
    Dim count1 As System.Int64 = 0
    Dim count2 As System.Int64 = 0

    If QueryPerformanceCounter(count1) <> 0 Then
    System.Threading.Thread.Sleep(1200)
    QueryPerformanceCounter(count2)
    Dim time_ms As System.Int64 = (count2 - count1) * 1000 / freq
    End If
    End If
    End Sub 'TestTimer

    6.10. µ÷Óñ¾µØ´úÂëʱ£¬Êý¾ÝÀàÐÍÓÐʲôÏÞÖÆ£¿What are the limitations on marshalling types via P/Invoke?

    • ·µ»ØÖµ
      • Ö»ÄÜÊdz¤¶ÈСÓÚµÈÓÚ32λµÄÀàÐÍ
      • ·Ç¸¡µãÐÍnot floating point
    • ²ÎÊý
      • Only support marshaling blittable types
        • blittable types -> same representation in memory in both managed and native
        • non-blittable -> memory transformation required
        • Since only blittable types, all objects are pinned and never copied
          • Exception: passing String ByVal in VB.NET
        • Implies that you can't marshal nested objects since this requires a memory transformation (non-blittable)
      • Ö»ÄÜÊdz¤¶ÈСÓÚµÈÓÚ32λµÄÀàÐÍ
        • ֵͨ¹ý¶ÑÕ»´«µÝ
        • ÀýÍ⣺float32
      • ²Î¿¼(References)
        • Pass blittable reference types
        • °Ñ²Î¿¼´«µÝµ½ÖµÀàÐͱäÁ¿
        • Õâ¾ÍÊÇÈçºÎ´«µÝfloat32ÀàÐ͵ÄÖµ
      • ¿ÉÒÔ´«µÝÖµÀàÐ͵ÄÊý×é
        • ÔÚ±¾µØ´úÂëÖУ¬Äú¿ÉÒÔʹÓÃÖ¸ÕëÖ¸ÏòµÚÒ»¸ö¶ÔÏó£¬È»ºóÒ»¸ö½ÓÒ»¸öµØ·ÃÎÊÆäËû¶ÔÏó
      • StringÊÇÌØÊâµÄ£¬´«µÝcharÊý×é -> ²»±äµÄ
      • StringBuilderÊÇÌØÊâµÄ£¬´«µÝcharÊý×é -> Ò×±äµÄ (ÐèÒªµ¥¶À´«µÝ³¤¶È)
      • ×¢Ò⣺C# boolÊÇ8¸ö±ÈÌØÎ»µÄ£¬²¢ÇÒ²»µÈÓÚWin32µÄBOOL
      • ¶ÓÁУº±àÒëÆ÷ĬÈϵĶÓÁÐ (4×Ö½Ú)
      • Marshal.GetLastWin32Error Ö§³Ö GetLastError() ÓïÒå
      • δ֧³ÖµÄ£º
        • MarshalAs: no support for non-blittable types
        • StructLayout: ²»ÄܸıäÍâ¹Û
        • Delegates(ίÍÐ)
        • DateTime
        • Only support default calling convention

    6.11. µ÷ÓÃGetLastErrorʱ£¬×ÜÊÇ»ñµÃ²»¶¨µÄ´úÂ룿

    ¾¡Á¿²»Òª³¢ÊÔµ÷ÓÃWindows GetLastError() API£¬ÒòΪCLRµ÷Óñ¾µØ´úÂëʱ¿ÉÄÜ»á¸Ä±älast errorµÄ´úÂ롣ȡ¶ø´úÖ®µÄÊÇ£¬Ê¹Óõ÷Óõķµ»ØÖµ±ê¼Ç´íÎó´úÂ룬ÔÙµ÷ÓÃSystem.Runtime.InteropServices.Marshal.GetLastWin32Error()·½·¨À´»ñµÃ´íÎó´úÂë¡£
    using System.Runtime.InteropServices;

    [DllImport("coredll.dll", SetLastError=true)]
    int myFoo(...);

    Foo(...)
    {
    int rc = myFoo(...);

    if (rc == false)
    {
    throw new Win32Exception(Marshal.GetLastWin32Error(), "Foo failed");
    }
    }

    6.12. µ÷Óñ¾µØ´úÂëʱ£¬ÓÐûÓвÎÊýÊýÁ¿µÄÏÞÖÆ£¿

    ÓÐÏÞÖÆ¡£.net¾«¼ò¿ò¼Ü°æ±¾1.0µÄÏÞÖÆÎª12¸ö¡£

    6.13. µ÷Óñ¾µØ´úÂëʱ£¬ÎªÊ²Ã´µÃµ½"NotSupportedException"Òì³££¿

    ͨ³£ÓÐÈýÖÖ¿ÉÄÜÐÔ£º
    • ÔÚÍйܴúÂëÖеÄÉêÃ÷²»ÕýÈ·
    • .net¾«¼ò¿ò¼Ü²»Ö§³ÖÄãÏë×öµÄ²Ù×÷
    • dllµÄÃû³ÆÔÚ±©Â¶¹ý³ÌÖÐËð»µÁË

    ¼ì²éÒÔÏÂÏîÄ¿£º 
    • ÓÐûÓÐÎ¥·´.net¾«¼ò¿ò¼Ü P/Invoke(µ÷ÓÃ)µÄÏÞÖÆ?
    • ÓÐûÓвÎÊýÐèÒªÔ¤ÏÈ·ÖÅäÄÚ´æ(È磬ÊDz»ÊÇÖ¸Õë)? Èç¹ûÊǵģ¬ÄúÓ¦¸Ã´«µÝÒѾ­´æÔڵıäÁ¿µÄ²Î¿¼¡£
    • ±©Â¶µÄº¯ÊýÃûÊÇ·ñÕýÈ·£¿ ¿ÉÒÔÓÃDUMPBIN.EXE¹¤¾ßÀ´ÑéÖ¤
    • ÊDz»ÊÇÏë³¢ÊÔÌ«¶àµÄ²ÎÊý£¿

    ÀýÈ磬Õë¶ÔÉÏÃæµÄµÚ¶þµã£¬RegOpenKey APIµÄ×îºóÒ»¸ö²ÎÊýHKEYµÄÖ¸Õë¡£ÄúÓ¦¸ÃÕâÑùÉêÃ÷ºÍµ÷Óãº
    //C#
    [DllImport("coredll.dll", SetLastError=true)]
    public static extern long RegOpenKey(
    IntPtr hkey,
    string lpSubKey,
    ref IntPtr hkeyResult
    );

    public long OpenMySubKey()
    {
    IntPtr hkey = IntPtr.Zero;
    return RegOpenKey(HKEY_CLASSES_ROOT, "MySubKey", ref hkey);
    }

    'VB
    <DllImport("coredll.dll", SetLastError:=True)> _
    Public Shared Function RegOpenKey(ByVal hkey As IntPtr, ByVal lpSubKey As String, ByRef hkeyResult As IntPtr) As Long
    End Function

    Public Function OpenMySubKey() As Long
    Dim hkey As IntPtr = IntPtr.Zero
    Return RegOpenKey(HKEY_CLASSES_ROOT, "MySubKey", hkey)
    End Function 'OpenMySubKey

    6.14. ÈçºÎ°Ñ byte[] ת»»³É IntPtr?

    Óв»Ö¹Ò»Öֵķ½·¨·ÃÎÊIntPtr¡£

    µÚÒ»ÖÖ·½·¨£¬Ê¹Ó÷ǰ²È«´úÂ룬ֱ½ÓÓÃÖ¸ÕëÖ¸ÏòbyteÊý×é¡£
    //C#
    unsafe
    {
    byte[] test = new byte[5];
    fixed (byte* p = &test[0])
    {
    *p = 0xff;
    }
    }
    Ò²¿ÉÒÔʹÓÃGCHandleÖ¸Ïò¶ÔÏó¡£
    //C#
    using System.Runtime.InteropServices;

    byte[] test = new byte[5];
    GCHandle hObject = GCHandle.Alloc(test, GCHandleType.Pinned);
    IntPtr pObject = hObject.AddrOfPinnedObject();

    if(hObject.IsAllocated)
    hObject.Free();

    'VB
    Imports System.Runtime.InteropServices

    Dim test(4) As Byte
    Dim hObject As GCHandle = GCHandle.Alloc(test, GCHandleType.Pinned)
    Dim pObject As IntPtr = hObject.AddrOfPinnedObject()
    If hObject.IsAllocated Then
    hObject.Free()
    End If
    ×îºó£¬¿ÉÒÔʹÓÃLocalAllocºÍMarshallingº¯Êý¸´ÖÆÄÚ´æ¿éµÃµ½Êý¾Ý¿é¡£
    //C#
    [DllImport("coredll.dll",SetLastError=true)]
    public static extern IntPtr LocalAlloc(uint uFlags, uint uBytes);

    [DllImport("coredll.dll",SetLastError=true)]
    public static extern IntPtr LocalFree(IntPtr hMem);

    [DllImport("coredll.dll",SetLastError=true)]
    public static extern IntPtr LocalReAlloc(IntPtr hMem, uint uBytes, uint fuFlags);

    public const uint LMEM_FIXED = 0;
    public const uint LMEM_MOVEABLE = 2;
    public const uint LMEM_ZEROINIT = 0x0040;

    byte[] test = new byte[5];
    IntPtr p = LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, (uint)test.Length);

    if (p == IntPtr.Zero)
    {
    throw new OutOfMemoryException();
    }
    else
    {
    Marshal.Copy(test, 0, p, test.Length);
    }

    'VB
    <DllImport("coredll.dll", SetLastError:=True)> _
    Public Shared Function LocalAlloc(ByVal uFlags As UInt32, ByVal uBytes As UInt32) As IntPtr
    End Function

    <DllImport("coredll.dll", SetLastError:=True)> _
    Public Shared Function LocalFree(ByVal hMem As IntPtr) As IntPtr
    End Function

    <DllImport("coredll.dll", SetLastError:=True)> _
    Public Shared Function LocalReAlloc(ByVal hMem As IntPtr, ByVal uBytes As UInt32, ByVal fuFlags As UInt32) As IntPtr
    End Function

    Public Const LMEM_FIXED As Integer = 0
    Public Const LMEM_MOVEABLE As Integer = 2
    Public Const LMEM_ZEROINIT As Integer = &H40

    Dim test(4) As Byte
    Dim p As IntPtr = LocalAlloc(Convert.ToUInt32(LMEM_FIXED Or LMEM_ZEROINIT), Convert.ToUInt32(test.Length))
    If p.Equals(IntPtr.Zero) Then
    Throw New OutOfMemoryException
    Else
    Marshal.Copy(test, 0, p, test.Length)
    End If

    6.15. Why do I get a MissingMethodException when I call a function from a native DLL?

    There are several issues to consider when determining the case of a MissingMethodException. When this exception occurs you should verify the following:

    For the latest Microsoft eMbedded Visual Tools and SDK downloads, visit the MSDN Mobile and Embedded Developer Center "Products & Updates" download page at:
    http://msdn.microsoft.com/mobility/downloads/updates/default.aspx

    6.16. How do I set the system time?
    You can set the system time by P/Invoking the SetSystemTime function.
    //C#
    using System.Runtime.InteropServices;

    public struct SYSTEMTIME
    {
    public ushort wYear;
    public ushort wMonth;
    public ushort wDayOfWeek;
    public ushort wDay;
    public ushort wHour;
    public ushort wMinute;
    public ushort wSecond;
    public ushort wMilliseconds;
    }

    [DllImport("coredll.dll")]
    public extern static void GetSystemTime(ref SYSTEMTIME lpSystemTime);

    [DllImport("coredll.dll")]
    public extern static uint SetSystemTime(ref SYSTEMTIME lpSystemTime);

    // Set the clock ahead one hour
    SYSTEMTIME st = new SYSTEMTIME();
    GetSystemTime(ref st);
    st.wHour = (ushort)(st.wHour + 1 % 24);
    SetSystemTime(ref st);

    'VB
    Imports System.Runtime.InteropServices

    Public Structure SYSTEMTIME
    Public wYear As UInt16
    Public wMonth As UInt16
    Public wDayOfWeek As UInt16
    Public wDay As UInt16
    Public wHour As UInt16
    Public wMinute As UInt16
    Public wSecond As UInt16
    Public wMilliseconds As UInt16
    End Structure

    <DllImport("coredll.dll")> _
    Public Shared Sub GetSystemTime(ByRef lpSystemTime As SYSTEMTIME)
    End Sub

    <DllImport("coredll.dll")> _
    Public Shared Function SetSystemTime(ByRef lpSystemTime As SYSTEMTIME) As UInt32
    End Function

    'Set the clock ahead one hour
    Dim st As New SYSTEMTIME
    GetSystemTime(st)
    st.wHour = Convert.ToUInt16(((Convert.ToInt32(st.wHour) + 1)) Mod 24)
    SetSystemTime(st)
    6.17. How do I programmatically soft reset the device?

    The device can be soft reset through P/Invoking of the KernelIoControl function, as demonstrated in the code below. For more information on how to use the function and extend the functionality of this sample, refer to Visual Studio .NET Help.

    Note: On Smartphone devices, this will only work if you are signed with a privileged certificate.
    //C#
    using System.Runtime.InteropServices;

    public const uint FILE_DEVICE_HAL = 0x00000101;
    public const uint METHOD_BUFFERED = 0;
    public const uint FILE_ANY_ACCESS = 0;

    public uint CTL_CODE(uint DeviceType, uint Function, uint Method, uint Access)
    {
    return ((DeviceType << 16) | (Access << 14) | (Function << 2) | Method);
    }

    [DllImport("Coredll.dll")]
    public extern static uint KernelIoControl
    (
    uint dwIoControlCode,
    IntPtr lpInBuf,
    uint nInBufSize,
    IntPtr lpOutBuf,
    uint nOutBufSize,
    ref uint lpBytesReturned
    );

    uint ResetPocketPC()
    {
    uint bytesReturned = 0;
    uint IOCTL_HAL_REBOOT = CTL_CODE(FILE_DEVICE_HAL, 15,
    METHOD_BUFFERED, FILE_ANY_ACCESS);
    return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0,
    IntPtr.Zero, 0, ref bytesReturned);
    }

    private void Form1_Load(object sender, System.EventArgs e)
    {
    DialogResult r = MessageBox.Show
    (
    "Are you sure you want to reset?",
    "Test",
    MessageBoxButtons.YesNo,
    MessageBoxIcon.Question,
    MessageBoxDefaultButton.Button2
    );

    if (r == DialogResult.Yes)
    {
    ResetPocketPC();
    }
    }

    'VB
    Public Const FILE_DEVICE_HAL As Integer = &H101
    Public Const METHOD_BUFFERED As Integer = 0
    Public Const FILE_ANY_ACCESS As Integer = 0

    Public Function CTL_CODE( _
    ByVal DeviceType As Integer, _
    ByVal Func As Integer, _
    ByVal Method As Integer, _
    ByVal Access As Integer) As Integer

    Return (DeviceType << 16) Or (Access << 14) Or (Func << 2) Or Method

    End Function 'CTL_CODE

    <DllImport("Coredll.dll")> _
    Public Shared Function KernelIoControl _
    ( _
    ByVal dwIoControlCode As Integer, _
    ByVal lpInBuf As IntPtr, _
    ByVal nInBufSize As Integer, _
    ByVal lpOutBuf As IntPtr, _
    ByVal nOutBufSize As Integer, _
    ByRef lpBytesReturned As Integer _
    ) As Integer
    End Function

    Function ResetPocketPC() As Integer
    Dim bytesReturned As Integer = 0
    Dim IOCTL_HAL_REBOOT As Integer = CTL_CODE(FILE_DEVICE_HAL, _
    15, METHOD_BUFFERED, FILE_ANY_ACCESS)
    Return KernelIoControl(IOCTL_HAL_REBOOT, IntPtr.Zero, 0, _
    IntPtr.Zero, 0, bytesReturned)
    End Function 'ResetPocketPC

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load
    Dim r As DialogResult = MessageBox.Show( _
    "Are you sure you want to reset?", _
    "Test", _
    MessageBoxButtons.YesNo, _
    MessageBoxIcon.Question, _
    MessageBoxDefaultButton.Button2)

    If r = DialogResult.Yes Then
    ResetPocketPC()
    End If

    End Sub 'Form1_Load
    6.18. How can I put an icon on the title bar regardless of the which form is active?

    This is not supported with the current version of the .NET Compact Framework. You can, however, P/Invoke Pocket PC's notificaiton system to do this. Refer to the following for more information:

    Sample Code:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppc2k2/html/ppc_fications.asp

    AYGShell APIs:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/html/_cerefaygshellfunctions.asp

    The native Notification APIs are: SHNotificationAdd, SHNotificationRemove, SHNotificationGetData, and SHNotificationUpdate.

    6.19. How do I disable and capture hardware buttons?

    Refer to the sample in the P/Invoke library.
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/PInvokeLib.asp#PInvokeLib_Topic03

    6.20. How do I hide the start icon?

    The Start icon can be hidden using the SHFullScreen API.
    //C#
    const uint SHFS_SHOWTASKBAR = 0x0001;
    const uint SHFS_HIDETASKBAR = 0x0002;
    const uint SHFS_SHOWSIPBUTTON = 0x0004;
    const uint SHFS_HIDESIPBUTTON = 0x0008;
    const uint SHFS_SHOWSTARTICON = 0x0010;
    const uint SHFS_HIDESTARTICON = 0x0020;

    [DllImport("aygshell.dll")]
    static extern uint SHFullScreen(IntPtr hwndRequester, uint dwState);

    [DllImport("coredll.dll")]
    public static extern IntPtr GetCapture();

    private void Form1_Load(object sender, System.EventArgs e)
    {
    Capture = true;
    IntPtr hwnd = GetCapture();
    Capture = false;
    SHFullScreen(hwnd, SHFS_HIDESTARTICON);
    }

    'VB
    Const SHFS_SHOWTASKBAR As Integer = &H1
    Const SHFS_HIDETASKBAR As Integer = &H2
    Const SHFS_SHOWSIPBUTTON As Integer = &H4
    Const SHFS_HIDESIPBUTTON As Integer = &H8
    Const SHFS_SHOWSTARTICON As Integer = &H10
    Const SHFS_HIDESTARTICON As Integer = &H20

    <DllImport("aygshell.dll")> _
    Shared Function SHFullScreen(ByVal hwndRequester As IntPtr, ByVal dwState As Integer) As Integer
    End Function

    <DllImport("coredll.dll")> _
    Public Shared Function GetCapture() As IntPtr
    End Function

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    Capture = True
    Dim hwnd As IntPtr = GetCapture()
    Capture = False

    SHFullScreen(hwnd, SHFS_HIDESTARTICON)

    End Sub 'Form1_Load
    6.21. How do I enumerate, create, and terminate processes?

    Refer to the sample:
    http://msdn.microsoft.com/mobility/understanding/articles/default.aspx?pull=/library/en-us/dnnetcomp/html/processmanager.asp

    6.22. Where can I find a centralized library of P/Invoke samples?

    This sample demonstrates how to P/Invoke numerous useful native functions that are not directly available through the .NET Compact Framework. A test Form is provided that enumerates all available test procedures and allows the user to select and run them:
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/PInvokeLib.asp

    6.23. How do I play and record .WAV audio files with the Waveform Audio Inteface?

    Learn how to use the Waveform Audio Interface to record and play ".wav" files:
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/WaveInOut.asp

     

    7. ͨÓÃ


    7.1. ÈçºÎÈ·¶¨Ó¦ÓóÌÐòµÄÖ÷Ŀ¼£¿

    ʹÓÃReflection£¬Ó¦ÓóÌÐò¿ÉÒÔÈ·¶¨×Ô¼ºÊÇ´ÓÄĸöĿ¼Æô¶¯µÄ£¬Ò²¿ÉÒÔʹÓÃIO.PathÃüÃû¿Õ¼äÀ´ÐÞ¸ÄËü¡£

    //C#
    using System.Reflection;
    using System.IO;

    // This is the full directory and exe name
    String fullAppName = Assembly.GetExecutingAssembly().GetName().CodeBase;

    // This strips off the exe name
    String fullAppPath = Path.GetDirectoryName(fullAppName);

    // This adds a file name to the path
    String splashImageName = Path.Combine(fullAppPath, "myfile.txt");

    'VB
    Imports System.IO
    Imports System.Reflection

    ' This is the full directory and exe name
    Dim fullAppName As String = [Assembly].GetExecutingAssembly().GetName().CodeBase

    ' This strips off the exe name
    Dim fullAppPath As String = Path.GetDirectoryName(fullAppName)

    ' This adds a file name to the path
    Dim splashImageName As String = Path.Combine(fullAppPath, "myfile.txt")
    ѧϰÈçºÎ»ñµÃ³ÌÐòÖ´Ðеĵ±Ç°Ä¿Â¼¡£ÔÚEmbedded Visual BasicÖУ¬³ÌÐòÖ´Ðеĵ±Ç°Ä¿Â¼¿ÉÒÔͨ¹ýApp.PathÊôÐÔ»ñµÃ¡£Ö´ÐгÌÐòµÄĿ¼¿ÉÒÔͨ¹ý³ÌÐò¼¯µÄAssemblyName¶ÔÏóµÄ»ñµÃ£¬AssemblyName¶ÔÏó°üº¬Á˳ÌÐò¼¯µÄËùÓÐÃèÊö£º
    http://msdn.microsoft.com/library/en-us/dncfhowto/html/HOWTOExecutingAppPath.asp

    ÕâÆª¿ìËÙÈëÃŽ̸̳æËßÄúÈçºÎ»ñµÃÄúµÄ³ÌÐò¼¯ºÍÊý¾ÝÎļþËùÔÚµÄĿ¼¡£Windows CE .NET±¾Éí²»Ö§³ÖÓ¦ÓóÌÐòµÄµ±Ç°Ä¿Â¼µÄÉèÖãº
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/getappdir.aspx

    7.2. ÈçºÎ¼ÆË㾫ȷµÄʱ¼ä¼ä¸ô£¿

    Ò»¸öÓ¦ÓóÌÐòÓÐËÄÖÖ·½·¨µÃµ½Ê±¼ä¼ä¸ô£º
    • System.Environment.TickCount
      »ñµÃÒ»¸ö´ø·ûºÅµÄÕûÐÍÖµ£¬±íʾ´Ó»úÆ÷Æô¶¯µ½µ÷ÓÃʱ¾­¹ýµÄºÀÃëÊý¡£ÔÚ.NET¾«¼ò¿ò¼ÜÏ£¬Õâ¸öÖµµÄÎó²îÔÚ0.5ÃëÄÚ£¬´ó¶àÇé¿öÏ»á±È0.5ÃëС¡£
    • GetTickCount()
      ÊôÐÔEnvironment.TickCount¾ÍÊǵ÷ÓÃGetTickCountº¯ÊýµÄ£¬ËùÒÔûÓбØÒªÔÙµ÷Óñ¾µØ´úÂëÖеÄÕâ¸ö·½·¨¡£
    • Performance Monitor
      ¿ÉÒÔ×÷ΪѹÁ¦²âÊÔÓÃ;£¬µ«²»ÊÇΪ×îÖÕʹÓõÄÓ¦ÓóÌÐò¶øÉè¼ÆµÄ¡£ÈçÐè¸ü¶àÐÅÏ¢£¬Çë²é¿´±¾ÎÊ´ðµÄ "7.5. ÈçºÎʹÓÃÐÔÄܼàÊÓÆ÷£¿ " Õ½Ú
    • Timers
      ʹÓÃSystem.Threading.TimerÀ࣬¿ÉÒÔÔÚÏß³ÌÄÚÉ趨¼ÆÊ±Æ÷£¬ÓÃίÍÐ(delegate)Ö¸ÏòÓ¦ÓóÌÐò ¡£
    • Performance Counter
      Èç¹ûOEM³§ÉÌÖ§³ÖµÄ»°£¬QueryPerformanceCounterº¯ÊýÄÜÌṩ×î¸ß¾«¶ÈµÄ¼ÆÊ±¹¦ÄÜ¡£
      Çë²é¿´±¾ÎÊ´ðµÄ"6.9. ÈçºÎʹÓÃÐÔÄܼÆÊýÆ÷¹¦ÄÜ? "Õ½ڡ£

    7.3. ÈçºÎ°ÑǶÈëʽ×ÊÔ´µ±×÷Ò»¸öÁ÷(Stream)£¿

    ΪÁËÄܹ»·ÃÎÊǶÈë×ÊÔ´£¬Ó¦ÓóÌÐòÖ»Ðë¼òµ¥µØÒýÓÃÏà¹ØµÄ³ÌÐò¼¯(assembly)²¢µ÷ÓÃGetManifestResourceStream·½·¨¡£ÏÂÃæÕâ¸öÀý×ÓÑÒʯÁËÈçºÎ´ÓǶÈë×ÊÔ´Öн¨Á¢Ò»¸öλͼ£º
    //C#
    using System.Reflection;

    Assembly asm = Assembly.GetExecutingAssembly();
    Bitmap bmpSprite = new Bitmap(asm.GetManifestResourceStream("AssemblyName.FileName"));

    'VB
    Imports System.Reflection

    Dim asm As [Assembly] = [Assembly].GetExecutingAssembly()
    Dim bmpSprite As New Bitmap(asm.GetManifestResourceStream("AssemblyName.FileName"))
    ÉÏÃæ´úÂëÖУ¬ ×Ö·û´®AssemblyName²¿·Ö¿ÉÒÔÔÚÔËÐÐʱͨ¹ýµ÷ÓÃasm.GetName().NameµÃµ½¡£

    ×¢Ò⣺Èç¹ûAssemblyNameÖÐÓпոñ£¬Ëü½«±»Ï»®Ïß´úÌæ£¬¶øÇÒ±ØÐëÕâÑù·ÃÎÊ¡£

    7.4. ΪʲôµÃµ½Ò»¸ö"An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in System.dll"µÄ´íÎó£¿

    ÕâÊÇ.net¾«¼ò¿ò¼ÜµÄBUG¡£ÕâÊÇÓÉÓÚWindows CEµ×²ãµÄSecure Sockets Layer (SSL)µÄÏÞÖÆÔì³ÉµÄ¡£µ«ÊÇ£¬Ò²Å¼±ÜÃâµÄ·½·¨£¬Èç¹ûÉèÖà req.AllowWriteStreamBufferingΪtrue£¬²»ÒªÉèÖÃreq.ContentLengthÊôÐÔ£¬ÄǾͲ»»áÔÚ·¢ÉúÕâ¸ö´íÎóÁË¡£

    7.5. ÈçºÎʹÓÃÐÔÄܼàÊÓÆ÷£¿

    ÐÔÄܼÆÊýÆ÷ͨ¹ý±à¼­É豸ע²á±í½¨Á¢£º
    1. ½¨Á¢×¢²á±í¼ü£º"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework\PerfMonitor"
    2. н¨Ë«×Ö½ÚÏֵ¾ÍÊǼÆÊýÆ÷µÄÃû×Ö¡£
    3. °ÑCountersµÄÖµÉèÖÃΪ1±íʾÔÊÐí¼ÆÊýÆ÷£¬ÉèÖÃΪ0±íʾ½ûֹʹÓá£
    ÉèÖÃÁËÐÔÄܼÆÊýÆ÷ºó£¬µ±³ÌÐò¹Ø±Õʱ£¬»á½¨Á¢Ò»¸öÎı¾Îļþ"mscoree.stat"¡£Õâ¸öÎļþ»á´æ·ÅÔÚÉ豸µÄ¸ùĿ¼¡£ÕâÊÇÒ»¸öÎļþÿÐеij¤¶ÈÊǹ̶¨µÄ£¬ËùÒÔµ¼ÈëExcelÊǷdz£·½±ãµÄ¡£

    ×¢Òâ: ¼ÆÊýÆ÷Ö»Äܱ»Ò»¸öÔËÐÐ×ŵÄÍйܵijÌÐòʹÓá£
    ×¢Òâ: ʹÓÃÐÔÄܼÆÊýÆ÷ʱ£¬»áµ¼ÖÂ30%µÄÐÔÄÜϽµ¡£

    7.6. ÈçºÎÈ¡ÏûÒ»¸ö³ÌÐòµÄ¹Ø±Õ£¿

    ³ÌÐò¿ÉÒÔÖØÔØOnClosing·½·¨£¬ÉèÖÃCancelEventArgs.CancelΪtrue¾Í¿ÉÒÔÈ¡Ïû¹Ø±Õ¡£
    //C#
    protected override void OnClosing(CancelEventArgs e)
    {
    e.Cancel = true;
    }

    'VB
    Protected Overrides Sub OnClosing(ByVal e As CancelEventArgs)
    e.Cancel = True
    End Sub 'OnClosing
    7.7. ÈçºÎÔÚÎҵijÌÐòÖе÷ÓÃÁíÒ»¸öÓ¦ÓóÌÐò£¿

    Äú¿ÉÒÔµ÷Óñ¾µØ´úÂëµÄCreateProcessº¯Êý¿ªÊ¼ÔËÐеڶþ¸ö³ÌÐò¡£È»ºóµ÷Óñ¾µØ´úÂëµÄWaitForSingleObjectº¯ÊýÔÝÍ£µ÷ÓõijÌÐò£¬Ö±µ½µÚ¶þ¸ö³ÌÐòÔËÐнáÊø¡£ÒÔÏ¿ìËÙÈëÃÅÑÝʾÁËͨ¹ýPocketPCÄ£ÄâÆ÷À´ÊµÏÖÕâÒ»²Ù×÷£º
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/waitforsingleobject.aspx

    7.8. .net¾«¼ò¿ò¼ÜµÄÓ¦ÓóÌÐò»á½¨Á¢Ê²Ã´Ị̈߳¿

    Ò»¸ö.net¾«¼ò¿ò¼Ü³ÌÐò×î¶à»á²úÉú4¸öỊ̈߳º
    • Ò»¸öÖ÷Ó¦ÓóÌÐòÏ̡߳£
    • Ò»¸öÏ߳̿ØÖƸ÷ÖÖʱ¼ä¼ä¸ô£¬Ê±¼ä¼ä¸ôÊǹ©ÏµÍ³ºÍÆäËûÓ¦ÓóÌÐòʹÓõġ£
    • Ò»¸öÏ̸߳ú×ٻµÄTCP/IP½Ó¿ÚµÄ±ä»¯(Ä£ÄâWindows XPÉϵÄýÌ嶯×÷£¬Windows CEÉÏÊÇûÓÐÕâЩ²Ù×÷µÄ)¡£
    • Ò»¸öÖ´ÐÐÖÕÖ¹¶ÔÏóµÄÏ̡߳£µ±µÚÒ»¸ö±»À¬»ø»ØÊյĶÔÏó»ØÊÕʱ£¬¾Í±»½¨Á¢ÁË¡£
    7.9. ÈçºÎ°ÑbyteÊý×éת»»³É½á¹¹Ì壿

    ÔÚC++ÖУ¬Í¨¹ý½¨ÔìÀàÐÍ(typecasting)¿ÉÒԺܷ½±ãºÍÓÐЧµÄ±£´æÒ»¸öÀà»ò½á¹¹Ìåµ½Îļþ£¬²¢Ö±½Ó´ÓÎļþÖÐÖØ¹¹³öÀ´¡£µ«ÍйܴúÂëµÄ±¾ÐÔ¾ö¶¨ÁËËü²»ÄÜÕâÑùʵÏÖ¡£µ«»¹ÊÇÓа취ʵÏֵ쬽¨Á¢Ò»¸öÀ࣬°ÑÄÚ´æÖеÄÊý¾Ý×÷ΪËüµÄÊôÐÔÈÃÆäËûÀà·ÃÎÊ¡£ÀýÈ磺
    //C#
    public class MyClass
    {
    protected byte[] m_data = null;
    // uint uiDummy
    // short sDummy

    // This is a bit unsafe so you should throw an
    // exception or assert if the byte array length is
    // not 6. A safer but less memory efficient approach
    // would be to set m_data = new byte[6] and then copy
    //bytes to m_data.
    public MyClass(byte[] bytes) {m_data = bytes;}

    // Get/Set the uint
    public uint uiDummy
    {
    get {return BitConverter.ToUInt32(m_data, 0);}
    set
    {
    Buffer.BlockCopy(BitConverter.GetBytes(value),0,m_data,0,BitConverter.GetBytes(value).Length);
    }
    }

    // Get/Set the short
    public short sDummy
    {
    get {return BitConverter.ToInt16(m_data, 4);}
    set
    {
    Buffer.BlockCopy(BitConverter.GetBytes(value),0,m_data,4,BitConverter.GetBytes(value).Length);
    }
    }
    }

    byte[] fromFile = {1,1,1,1,2,2};
    MyClass myClass = new MyClass(fromFile);

    uint test1 = myClass.uiDummy; // 0x1010101
    short test2 = myClass.sDummy; // 0x202

    myClass.sDummy = 0x0505; // Test setting the short
    uint test4 = myClass.uiDummy; // 0x1010101
    short test5 = myClass.sDummy; // 0x505

    'VB
    Public Class ByteClass
    Protected m_data As Byte() = Nothing

    ' uint uiDummy
    ' short sDummy
    ' This is a bit unsafe so you should throw an exception
    ' or assert if the byte array length is not 6. A safer
    ' but less memory efficient approach would be to set
    ' m_data = new byte[6] and then copy bytes to m_data.
    Public Sub New(ByVal bytes() As Byte)
    m_data = bytes
    End Sub 'New

    ' Get/Set the uint
    Public Property uiDummy() As UInt32
    Get
    Return BitConverter.ToUInt32(m_data, 0)
    End Get
    Set(ByVal Value As System.UInt32)
    Buffer.BlockCopy(BitConverter.GetBytes(Value),0,m_data,0,BitConverter.GetBytes(Value).Length)
    End Set
    End Property

    ' Get/Set the short
    Public Property sDummy() As Short
    Get
    Return BitConverter.ToInt16(m_data, 4)
    End Get
    Set(ByVal Value As Short)
    Buffer.BlockCopy(BitConverter.GetBytes(Value),0,m_data,4,BitConverter.GetBytes(Value).Length)
    End Set
    End Property
    End Class 'ByteClass

    Dim fromFile As Byte() = {1, 1, 1, 1, 2, 2}
    Dim testClass As New ByteClass(fromFile)

    Dim test1 As System.UInt32 = testClass.uiDummy ' 0x1010101
    Dim test2 As Short = testClass.sDummy ' 0x202
    testClass.sDummy = &H505 ' Test short
    Dim test4 As System.UInt32 = testClass.uiDummy ' 0x1010101
    Dim test5 As Short = testClass.sDummy ' 0x505
    7.10. ÎÒ¿ÉÒÔ½¨Á¢Ò»¸öίÍÐ(delegate)½»¸øInvokeÂð£¿

    ²»¿ÉÒÔ¡£ÔÚ.net¾«¼ò¿ò¼ÜÖУ¬Ö»ÓÐEventHandler·½·¨¿ÉÒÔ±»µ÷Óá£ÒÔÏ´úÂë˵Ã÷°¡ÈçºÎÕýȷʹÓô˷½·¨£º
    //C#
    public void HandleMe(object o, EventArgs e) {...}
    form.Invoke(new EventHandler(form.HandleMe));

    'VB
    Public Sub HandleMe(o As Object, e As EventArgs)
    End Sub 'HandleMe
    form.Invoke(New EventHandler(AddressOf form.HandleMe))
    Although the following will compile, it will not work properly:
    //C#
    public delegate void MyHandler();
    public void HandleMeBadly() {...}
    form.Invoke(new MyHandler(form.HandleMeBadly));

    'VB
    Delegate Sub MyHandler()
    Public Sub HandleMeBadly()
    End Sub 'HandleMeBadly
    form.Invoke(New MyHandler(form.HandleMeBadly))
    7.11. ÈçºÎÔÚ΢Èí.net¾«¼ò¿ò¼ÜÉÏʹÓõ绰API£¿

    ²é¿´ÕâÆªÎÄÕ£¬Ñ§Ï°ÈçºÎÔÚ»ùÓÚ.net¾«¼ò¿ò¼ÜµÄÓ¦ÓóÌÐòÖзÃÎʵ绰API£º

    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfphoneapi.asp

    7.12. ÈçºÎÔÚPocket PcÉÏÉú³ÉGUID£¿

    Guid.NewGuid·½·¨¿ÉÒÔÉú³ÉеÄGUID£¬µ«ÔÚ.net¾«¼ò¿ò¼ÜÖÐûÓд˷½·¨¡£ÔĶÁÕâÆªÎÄÕ£¬Ñ§Ï°ÈçºÎ¸ù¾ÝGUID¹æ·¶ÔÚPocketPCÓ¦ÓóÌÐòÖн¨Á¢GUID¶ÔÏó£º
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/PPCGuidGen.asp

    7.13. ÈçºÎÈÃÎÒµÄ.net¾«¼ò¿ò¼Ü³ÌÐòºÍPocket OutlookµÄÊý¾Ý½áºÏ£¿

    ÕâÆªÎÄÕÂÌÖÂÛÁËÈçºÎʹÓÃInTheHand¹«Ë¾µÄPocket Outlook .NET×é¼þ£º
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/inthehandpoom.asp

    7.14. ÎÒ¿ÉÒÔÅжÏ.net¾«¼ò¿ò¼ÜÖÐÒ»¸öÎļþµÄ°æ±¾Âð£¿

    Visual Studio .NET 2003°ïÖúÖеÄC# Programmer's ReferenceÌṩÁËÔÚ.net¾«¼ò¿ò¼ÜÏÂʹÓò»°²È«´úÂëµ÷ÓÃGetFileVersionInfoº¯Êý¡£ Õâ¸öÀý×Ó´øÀ´µÄÎÊÌâÊÇ£¬Õâ¸öº¯ÊýÊÇÓÉOEM³§É̾ö¶¨µÄ£¬²¢ÇÒ²»±£Ö¤ÄÜ·µ»ØÕýÈ·½á¹û¡£

    ʹÓÃReflection¿ÉÒÔ»ñµÃ³ÌÐò¼¯(Assembly)µÄ°æ±¾£º
    //C#
    using System.Reflection;

    String ver = Assembly.GetExecutingAssembly().GetName().Version.ToString();

    'VB
    Imports System.Reflection;

    Dim ver As String = [Assembly].GetExecutingAssembly().GetName().Version.ToString()
    7.15. ΢Èí.net¾«¼ò¿ò¼ÜµÄºǫ́´¦ÀíÓÐʲôÏà¹Ø¼¼Êõ£¿

    ʹÓúǫ́´¦Àí£¬ÐèҪעÒâÏà¹ØÏ¸½Ú²¢Ð¡ÐÄÉè¼Æ¡£ÕâÆªÎÄÕÂÌṩһЩ¹ØÓÚºǫ́´¦Àí×îÓÐÓõĽ¨Ò飬ÎÄÖнéÉܵĺܶà¹ÛµãÊDZØÐë˵Ã÷µÄ£º
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/BackgroundProcess.asp

    7.16. ÔÚ΢Èí.net¾«¼ò¿ò¼ÜÉÏʹÓöàÏß³ÌÓÐʲô¼¼ÇÉ£¿

    ѧϰÈçºÎÔÚ»ùÓÚ.net¾«¼ò¿ò¼ÜµÄWindows´°ÌåÓ¦ÓóÌÐòÖÐʹÓöàÏ̡߳£
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfmultithreadedapp.asp

    7.17. ÈçºÎÔÚ ÖÇÄÜÉ豸ӦÓà ÖÐʹÓûìÏýÆ÷£¿

    ѧϰÈçºÎʹÓÃPreEmptive Dotfuscator»ìÏýÆ÷±£»¤ÄãµÄ´úÂë¡£
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfobfuscation.asp

    7.18. ÈçºÎʹÓÃÃÜÂë·þÎñ¶ÔÊý¾Ý½øÐмÓÃÜ»ò½âÃÜ£¿

    Çë²Î¿¼±¾ÎÊ´ðµÄ "10.5. дһ¸ö²¶×½Pocket PCÇ©ÃûµÄ³ÌÐòn ." ²¿·Ö¡£

    7.19. ÈçºÎÔÚ΢Èí.net¾«¼ò¿ò¼ÜÉÏ»ñµÃWindows CEÉ豸µÄΨһºÅÂ룿

    ѧϰÈçºÎʹÓÃ.net¾«¼ò¿ò¼Ü»ñµÃWindows CEÉ豸µÄÉ豸ºÅ¡£
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/retrievedeviceid.asp

    Äã¿ÉÒÔµ÷Óñ¾µØ´úÂëµÄº¯ÊýÀ´»ñµÃPocketPCµÄÉ豸ºÅ£¬Ò²¾ÍÊÇÐòÁкš£ÕâÆª¿ìËÙÈëÃŽ̳̣¬ÑÝʾÁËÓÃMessageBoxÀ´ÏÔʾÉ豸ºÅ¡£
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/deviceid.aspx

    7.20. ÈçºÎÔÚ΢Èí.net¾«¼ò¿ò¼ÜµÄÓ¦ÓóÌÐòÉÏ·¢ËͶÌÏûÏ¢£¿

    ÕâÆªÎÄÕÂÑÝʾÁËÈçºÎ´Ó»ùÓÚ.net¾«¼ò¿ò¼ÜµÄÓ¦ÓóÌÐòÖз¢ËͶÌÏûÏ¢£º
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfsendsms.asp

    7.21. ²»Ê¹ÓÃControl.Name£¬¿ÉÒÔÅжÏʼþµÄ·¢ËÍÕßÂð£¿

    ÕâÆªÎÄÕÂÌÖÂÛÁËÔÚ.net¾«¼ò¿ò¼ÜÏÂÈçºÎÅжÏʼþµÄ·¢ËÍÕߣ¬.net¾«¼ò¿ò¼ÜÖеĿؼþ²»Ö§³ÖnameÊôÐÔ£º
    http://msdn.microsoft.com/library/en-us/dncfhowto/html/HOWTOsenderevent.asp

    7.22. ÈçºÎÔÚÏß³ÌÖе÷Ó÷½·¨µÄ²ÎÊý£¿

    ÔÚÓ¦ÓóÌÐòÖÐʹÓöàỊ̈߳¬¿ÉÒÔÌá¸ßÓû§½çÃæµÄÐÔÄÜ¡£»ùÀàControlÌṩInvoke¡¢BeginInvokeºÍEndInvoke·½·¨ÔڿؼþÖÐÀ´½¨Á¢Ï̡߳£.net¾«¼ò¿ò¼Ü²»Ö§³ÖÒì²½µÄBeginInvokeºÍEndInvokeµ÷Óᣵ½ÏÖÔÚ£¬Ò²»¹²»Ö§³ÖÏòͬ²½Invokeµ÷Óô«µÝ²ÎÊý¡£ÕâÆª¿ìËÙÈëÃŽ̳ÌÌṩһ¸ö×Ô¶¨ÒåÀàControlInvoker£¬¿ÉÒÔʵÏÖÏòInvoke·½·¨Öд«µÝ²ÎÊý£º
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/controlinvoker.aspx

    7.23. ÈçºÎ½¨Á¢ÌáÐѳÌÐòºÍ¶¨Ê±³ÌÐò£¿

    ÕâÆª¿ìËÙÈëÃÅÎÄÕÂÃèÊöÁËʹÓÃP/Invoke¶¨ÒåÒ»¸öÓû§ÌáÐѺͶ©Ê±µÄÓ¦Óá£Äú¿ÉÒԼƻ®ÌáÐÑ´°¿Úµ¯³öµÄʱ¼ä¡£ÄúÒ²¿ÉÒÔÉèÖÃÒ»¸öÓ¦ÓóÌÐòÔÚÌØ¶¨µÄʱ¼äÔËÐлòÏìӦij¸öʼþ¡£
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/notifications.aspx

    7.24. ÈçºÎ²¥·ÅÉùÒô£¿

    ÕâÆª¿ìËÙÈëÃŽ̳ÌÑÝʾÁËʹÓÃP/Invoke²¥·Å¸ö¶ÌWAVÎļþ£¬Ò»¸öÊÇ×÷ΪǶÈëʽ×ÊÔ´£¬ÁíÒ»¸ö×÷Ϊһ¸öÄÚÈÝ¡£Õâ¸ö´°Ìå°üº¬ÁËÁ½¸ö°´Å¥£¬Ò»¸ö²¥·ÅǶÈë×ÊÔ´µÄChimes.wav£¬ÁíÒ»¸ö°´µ¥¶ÀµÄÎļþ²¥·ÅChord.wav¡£
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/playsounds.aspx

    7.25. ÈçºÎʹÓÃÃüÁîÐвÎÊý£¿

    ÔÚ´úÂëÖÐʹÓÃÃüÁîÐвÎÊý£¬Ö»Ðë¼òµ¥µÄ¶¨Òåmain·½·¨½ÓÊܲÎÊý²¢ÕýÈ·´¦Àí¡£ÒÔÏ´úÂëÑÝʾÁËÕâ¸ö·½·¨£º
    //C#
    static void Main(string[] args)
    {
    // Do your thing here
    }

    'VB
    Shared Sub Main(ByVal args() As String)
    'Do your thing here
    End Sub
    ÔÚVisual Studio 2003ÖвâÊÔµÄʱºò£¬¿ÉÒÔͨ¹ý¼Ì³Ð¿ª·¢»·¾³ÉèÖÃÃüÁîÐеIJÎÊý¡£Ö÷²Ëµ¥£¬Ñ¡Ôñ Project->Project Name Properties. ÔÚProperty Pages¶Ô»°¿òÖУ¬Ñ¡Ôñ Configuration Properties->Debugging¡£ÔÚ Command Line Arguments ÖÐÊäÈë×Ö·û´®£ºtext box.

    7.26. µ±Ê¹ÓÃÒѾ­ÊͷŵĶÔÏóµÄ·½·¨»òÊôÐÔµÄʱºò£¬ÎªÊ²Ã´µÃµ½Ò»¸öÒì³££¿

    ÍêÕûµÄ.net¿ò¼Ü²»±£Ö¤£¬ÔÚ·ÃÎÊÒ»¸öÒѾ­ÊͷŵĶÔÏóµÄÊôÐÔ»ò·½·¨Ê±Äܳɹ¦¡£ÔÚÍêÕûµÄ.net¿ò¼ÜÏ£¬ËäÈ»·ÃÎÊijЩÊôÐÔ(ÏñText)£¬¾­³£Äܳɹ¦¡£¸ù¾Ý.net¿ò¼ÜºÍ.net¾«¼ò¿ò¼ÜÖ´ÐÐÉϵÄÇø±ð£¬ÔÚ.net¾«¼ò¿ò¼ÜÉÏ·ÃÎÊÒѾ­ÊÍ·ÅÁ˵ĶÔÏóµÄ·½·¨»òÊôÐԻᾭ³£Ê§°Ü¡£

    7.27. ÈçºÎ»ñµÃ"Enter", "TAB", ºÍ "Arrow"°´¼üµÄʼþ£¿

    ʹÓÃKeyDownºÍKeyUpʼþ£¬¿ÉÒÔ»ñµÃÎÞ×Ö·ûµÄ¼ü(Ïñtab)¡£

    ÏÖÔÚ£¬Ö»ÓÐÒ»Ð©ÌØ¶¨µÄ¿Ø¼þÖ§³ÖkeyµÄʼþ(È磬form, panel, textbox ºÍ×Ô¶¨Òå¿Ø¼þ)¡£ÔÚ.net¾«¼ò¿ò¼ÜSP2°æ±¾ÖУ¬ËùÓпؼþ¶¼½«Ö§³Ökeyʼþ¡£

    ÒѾ­ÖªµÀµÄÎÊÌ⣬ÔÚʹÓÃÄ£ÄâÆ÷ʱ£¬´Ó¼üÅ̰´ÏÂtab¼ü½«²»±»Ö§³Ö£¬µ«´ÓÈí¼üÅÌ(SIP)Éϰ´ÏÂtabʱ£¬»áÓÐЧ¹û¡£

    ÕâÊÇVS´øµÄÄ£ÄâÆ÷µÄÔ­ÒòÔì³É£¬¶ø²»ÊÇ.net¾«¼ò¿ò¼ÜµÄÎÊÌâ¡£.net¾«¼ò¿ò¼Ü´¥·¢Keyʼþµ±ËüÊÕµ½ÏµÍ³´«À´µÄWM_KEY*ÏûÏ¢¡£µ±ÄúÔÚÄ£ÄâÆ÷ÖÐÔËÐб¾µØ´úÂë³ÌÐòʱ£¬´Ó¼üÅ̰´ÏÂtab¼ü²¢²»»áÈÃϵͳ´¥·¢WM_KEYDOWNʼþ¡£ÈôÊÇͨ¹ýÄ£ÄâÆ÷µÄÈí¼üÅÌ(SIP)£¬»òÕæÕýµÄÉ豸£¬Ôò²»»áÓÐÕâ¸öÎÊÌâ¡£

    7.28. ÈçºÎɾ³ýÒ»¸öÖ»¶ÁÎļþ£¿

    ʹÓÃSystem.IO.FileInfoÀà·ÃÎÊÎļþµÄÊôÐÔ¡£
    //C#
    System.IO.FileInfo fi = new System.IO.FileInfo("filename");
    // remove readonly attribute
    fi.Attributes -= System.IO.FileAttributes.ReadOnly;
    System.IO.File.Delete("filename");

    'VB
    Dim fi As New System.IO.FileInfo("filename")
    'remove readonly attribute
    fi.Attributes -= IO.FileAttributes.ReadOnly
    System.IO.File.Delete("filename")

    7.29. How do I determine if a member exists at runtime?

    The existence of a member can be determined at runtime using Reflection. The code below demonstrates how to use Reflection to access the "Width" property and the "GetPixel" method of a Bitmap object. In the case of the "Width" property, the code enumerates all "public" properties with a "get" component and then searches for one named "Width". The "GetPixel" sample demonstrates how one might use Reflection to call a known function where the parameter order is unknown. This sample is set up as if the author knows there is a method named "GetPixel" which takes a pixel location of x,y but does not know the order in which they appear in the parameter list. The sample enumerates the methods and searches for one named "GetPixel" and then enumerates the parameter list to determine whether the first or second parameter is named "X". Keep in mind that, due to the differences in hardware pixel formats, the value returned by GetPixel may be different from that set by SetPixel in this sample.

    Reflection provides many powerful tools for determing functionality at runtime so for information, refer to the documentation regarding System.Type and the namespace System.Reflection.
    //C#
    using System.Reflection;
    using System.Drawing;

    Bitmap bm = new Bitmap(200, 100);
    int width = 0;

    // Explicitly set one pixel for testing
    int x = 199;
    int y = 20;
    Color pixColor = Color.Black;
    bm.SetPixel(x,y,Color.Magenta);

    // Get the "Width" property
    PropertyInfo[] propInfo =
      bm.GetType().GetProperties(BindingFlags.GetProperty |
    BindingFlags.Public | BindingFlags.Instance);

    for (int i = 0; i < propInfo.Length; i++)
    {
        if (propInfo[i].Name == "Width")
        {
            width = (int)propInfo[i].GetValue(bm, null);
            break;
        }
    }

    // Call the GetPixel method
    MethodInfo[] methInfo = bm.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance);
    for (int i = 0; i < methInfo.Length; i++)
    {
        if (methInfo[i].Name == "GetPixel")
        {
            ParameterInfo[] paramInfo = methInfo[i].GetParameters();
            if (paramInfo.Length == 2)
        {

        object[] xy = new object[2];
        if (paramInfo[0].Name == "x")
        {
            xy[0] = x;
            xy[1] = y;
        }
        else
        {
            xy[1] = x;
            xy[0] = y;
        }

        pixColor = (Color)methInfo[i].Invoke(bm, xy);
        break;
    }

    'VB
    Imports System.Reflection
    Imports System.Drawing

    Dim bm As New Bitmap(200, 100)
    Dim width As Integer = 0

    ' Explicitly set one pixel for testing
    Dim x As Integer = 199
    Dim y As Integer = 20
    Dim pixColor As Color = Color.Black
    bm.SetPixel(x, y, Color.Magenta)

    ' Get the "Width" property
    Dim propInfo As PropertyInfo() = _
      bm.GetType().GetProperties((BindingFlags.GetProperty Or _
    BindingFlags.Public Or BindingFlags.Instance))

    Dim i As Integer
    For i = 0 To propInfo.Length - 1
        If propInfo(i).Name = "Width" Then
            width = Fix(propInfo(i).GetValue(bm, Nothing))
            Exit For
        End If
    Next i

    ' Call the SetPixel method
    Dim methInfo As MethodInfo() = bm.GetType().GetMethods((BindingFlags.Public _
    Or BindingFlags.Instance))
    For i = 0 To methInfo.Length - 1
        If methInfo(i).Name = "GetPixel" Then
            Dim paramInfo As ParameterInfo() = methInfo(i).GetParameters()
            If paramInfo.Length = 2 Then
                Dim xy(1) As Object

                If paramInfo(0).Name = "x" Then
                    xy(0) = x
                    xy(1) = y
                Else
                    xy(1) = x
                    xy(0) = y
                End If

                pixColor = CType(methInfo(i).Invoke(bm, xy), Color)
                Exit For
            End If
        End If
    Next i

    7.30. How do I determine the device name programatically?

    The device name can be accessed through the System.Net namespace, as demonstrated by the following code.
    //C#
    String devName = System.Net.Dns.GetHostName();

    'VB
    Dim devName As String = System.Net.Dns.GetHostName()

    7.31. How do I build a C# Smart Device project from the command line?

    Enter the following commands as single lines (each is broken into two lines for clarity):
    set CFPath=%SystemDrive%\Program Files\Microsoft Visual Studio .NET 2003\
    CompactFrameworkSDK\v1.0.5000\Windows CE
    csc Form1.cs /noconfig /nostdlib /lib:"%CFPath%"  /r:"%CFPath%\system.dll";"%CFPath%\
    system.drawing.dll";"%CFPath%\system.windows.forms.dll";"%CFPath%\mscorlib.dll"

    7.32. How do I abort an executing thread??

    There is no Abort method to the Thread class in the .NET Compact Framework so a thread must be aborted by returning from the executing procedure. Typically, an application will notify threads of a closing event by setting a global variable. The main thread will then wait for worker threads to finish processing before closing the application. The following HOWTO article demonstrates how to accomplish this.

    http://msdn.microsoft.com/library/en-us/dncfhowto/html/stopmt.asp


    7.33. Why can't I play a movie on the Pocket PC emulator?

    Windows Media Player is only available on the Pocket PC 2003 emulator. The Windows Media Player install package is for installation on a hardware device connected through ActiveSync and will not install to the emulator.

    7.34. How do I suppress Form titles from showing in the active applications list?

    The Active Programs list on the Pocket PC enumerates all open Forms. To stop a Form from being displayed in the list, simply set the Form's caption to be an empty string. The following example shows how to keep only the application name in the list while a Form is displayed from within another Form:
    //C#
    string AppName = "MyApp";

    Form1 form1 = new Form1();
    this.Text = "";
    form1.Text = AppName;
    form1.ShowDialog();
    this.Text = AppName;

    'VB
    Dim AppName As String = "MyApp"

    Dim form1 As New Form1()
    Me.Text = ""
    form1.Text = AppName
    form1.ShowDialog()
    Me.Text = AppName

    7.35. How do I access a Control from its instance name?

    You can use Reflection to look up a control instance by its name. Here is some sample code:
    //C#
    private void Form1_Load(object sender, System.EventArgs e)
    {
        ComboBox c = (ComboBox)this.ControlFromName("combobox1");
        c.Items.Add("1");
        this.GetControls();
    }

    private Control ControlFromName(string name)
    {
    object o = this.GetType().GetField(name,
    System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance |
    System.Reflection.BindingFlags.IgnoreCase).GetValue(this);

        return((Control)o);
    }

    private void GetControls()
    {
        System.Reflection.FieldInfo[] fis = this.GetType().GetFields
        (
            System.Reflection.BindingFlags.NonPublic | 
            System.Reflection.BindingFlags.Instance |
            System.Reflection.BindingFlags.IgnoreCase
        );

        foreach(System.Reflection.FieldInfo fi in fis)
        {
            if (fi.GetValue(this) is Control)
                MessageBox.Show(fi.Name);
        }
    }
    'VB
    Private Function ControlFromName(ByVal name As String) As Control
        Dim o As ObjectDim o As Object
        o = Me.GetType().GetField(name, Reflection.BindingFlags.NonPublic Or _
          Reflection.BindingFlags.Instance Or _
          Reflection.BindingFlags.IgnoreCase).GetValue(Me)
       
        Return (CType(o, Control))
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
        Dim c As ComboBox
        c = CType(ControlFromName("_combobox1"), ComboBox)
        c.Items.Add("1")
        Me.GetControls()e.GetControls()
    End Sub

    Private Sub GetControls()
        Dim fis As System.Reflection.FieldInfo()

        fis = Me.GetType().GetFields(Reflection.BindingFlags.NonPublic Or _
          Reflection.BindingFlags.Instance Or _
          Reflection.BindingFlags.IgnoreCase)

        For Each fi As Reflection.FieldInfo In fis
            If TypeOf (fi.GetValue(Me)) Is Control Then
                MessageBox.Show(fi.Name)
            End Ifnd If
        Next
    End Sub

    7.36. How do I detect the hardware directional pad buttons?

    The hardware directional pad buttons can be detected through the standard key events by comparing the KeyCode from the KeyEventArgs parameter.
    //C#
    protected override void OnKeyDown(KeyEventArgs e)
    {
        switch (e.KeyCode)
        {
            case Keys.Up:
                MessageBox.Show("Up Key Pressed");
                break;
            case Keys.Down:
                MessageBox.Show("Down Key Pressed");
                break;
            case Keys.Left:
                MessageBox.Show("Left Key Pressed");
                break;
            case Keys.Right:
                MessageBox.Show("Right Key Pressed");
                break;
        }
        base.OnKeyDown (e);
    }
    'VB
    Protected Overrides Sub OnKeyDown(e As KeyEventArgs)
        Select Case e.KeyCode
            Case Keys.Up
                MessageBox.Show("Up Key Pressed")
            Case Keys.Down
                MessageBox.Show("Down Key Pressed")
            Case Keys.Left
                MessageBox.Show("Left Key Pressed")
            Case Keys.Right
                MessageBox.Show("Right Key Pressed")
        End Select
         
        MyBase.OnKeyDown(e)

    End Sub 'OnKeyDown

    7.37. How do I get a double click event when only the Click event is supported?

    See the .NET Compact Framework QuickStarts, Implementing Events topic:

    http://samples.gotdotnet.com/quickstart/compactframework/doc/btndclick.aspx

    7.38. How do I get onenter/onleave style notifications?

    See the .NET Compact Framework QuickStarts, OnEnter/OnLeave Functionality:

    http://samples.gotdotnet.com/quickstart/compactframework/doc/enterleave.aspx

    7.39. How do I use threading in a modal dialog that doesn't hang my app?

    Create a modeless dialog that behaves like a model dialog.
    //C#
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Collections;
    using System.ComponentModel;

    public interface IModelessDialogCallback
    {
    void DialogResultCallback(DialogResult result);
    }

    public class Test : System.Windows.Forms.Form, IModelessDialogCallback
    {
    ModelessDialog dlg;
    Button bShow;
    int counter = 0;

    protected override void OnLoad(EventArgs e)
    {
    this.Text = "Modal(less) Dialog Example";

    this.bShow = new Button();
    this.bShow.Parent = this;
    this.bShow.Bounds = new Rectangle (10, 10, 150, 30);
    this.bShow.Text = "Show Dialog";
    this.bShow.Click += new EventHandler(this._Click);

    this.dlg = new ModelessDialog(this);
    }


    private void _Click(object o, EventArgs e)
    {
    this.Enabled = false;
    this.bShow.Text = "waiting for dlg";
    dlg.Show();
    }

    public void DialogResultCallback(DialogResult result)
    {
    MessageBox.Show("dialog returned: " + (result == DialogResult.OK ? "OK" : "Cancel"));
    this.Enabled = true;
    this.bShow.Text = "Show Dialog:" + ++counter;
    }

    public static void Main()
    {
    Application.Run(new Test());
    }
    }

    public class ModelessDialog : Form
    {
    IModelessDialogCallback parent;
    Button bOK, bCancel;

    public ModelessDialog(IModelessDialogCallback parent)
    {
    this.parent = parent;
    this.Text = "Modeless Dialog";

    this.bOK = new Button();
    this.bOK.Parent = this;
    this.bOK.Bounds = new Rectangle (10, 10, 150, 30);
    this.bOK.Text = "OK";
    this.bOK.Click += new EventHandler(this._Click);

    this.bCancel = new Button();
    this.bCancel.Parent = this;
    this.bCancel.Bounds = new Rectangle (10, 50, 150, 30);
    this.bCancel.Text = "Cancel";
    this.bCancel.Click += new EventHandler(this._Click);
    }

    private void _Click(object o, EventArgs e)
    {
    this.Hide();
    this.parent.DialogResultCallback(o == this.bOK ? DialogResult.OK : DialogResult.Cancel);
    }

    protected override void OnClosing(CancelEventArgs e)
    {
    e.Cancel = true;
    this.Hide();
    this.parent.DialogResultCallback(DialogResult.Cancel);
    }
    }

    'VB
    Imports System
    Imports System.Drawing
    Imports System.Windows.Forms
    Imports System.Collections
    Imports System.ComponentModel

    Public Interface IModelessDialogCallback
    Sub DialogResultCallback(result As DialogResult)
    End Interface IModelessDialogCallback'


    Public Class Test
    Inherits System.Windows.Forms.Form
    Implements IModelessDialogCallback
    Private dlg As ModelessDialog
    Private bShow As Button
    Private counter As Integer = 0

    Protected Overrides Sub OnLoad(e As EventArgs)
    Me.Text = "Modal(less) Dialog Example"

    Me.bShow = New Button()
    Me.bShow.Parent = Me
    Me.bShow.Bounds = New Rectangle(10, 10, 150, 30)
    Me.bShow.Text = "Show Dialog"
    AddHandler Me.bShow.Click, AddressOf Me._Click

    Me.dlg = New ModelessDialog(Me)
    End Sub 'OnLoad

    Private Sub _Click(o As Object, e As EventArgs)
    Me.Enabled = False
    Me.bShow.Text = "waiting for dlg"
    dlg.Show()
    End Sub '_Click

    Public Sub DialogResultCallback(ByVal result As DialogResult) Implements _
    IModelessDialogCallback.DialogResultCallback
    MessageBox.Show(("dialog returned: " + IIf(result = DialogResult.OK, "OK", "Cancel")))
    Me.Enabled = True
    counter += 1
    Me.bShow.Text = String.Format("Show Dialog: {0}", counter)
    End Sub 'DialogResultCallback

    Public Shared Sub Main()
    Application.Run(New Test)
    End Sub 'Main
    End Class 'Test

    Public Class ModelessDialog
    Inherits Form
    Private myParent As IModelessDialogCallback
    Private bOK, bCancel As Button

    Public Sub New(parent As IModelessDialogCallback)
    Me.myParent = parent
    Me.Text = "Modeless Dialog"

    Me.bOK = New Button()
    Me.bOK.Parent = Me
    Me.bOK.Bounds = New Rectangle(10, 10, 150, 30)
    Me.bOK.Text = "OK"
    AddHandler Me.bOK.Click, AddressOf Me._Click

    Me.bCancel = New Button()
    Me.bCancel.Parent = Me
    Me.bCancel.Bounds = New Rectangle(10, 50, 150, 30)
    Me.bCancel.Text = "Cancel"
    AddHandler Me.bCancel.Click, AddressOf Me._Click
    End Sub 'New

    Private Sub _Click(o As Object, e As EventArgs)
    Me.Hide()
    Me.myParent.DialogResultCallback(IIf(o Is Me.bOK, DialogResult.OK, DialogResult.Cancel))
    End Sub '_Click

    Protected Overrides Sub OnClosing(e As CancelEventArgs)
    e.Cancel = True
    Me.Hide()
    Me.myParent.DialogResultCallback(DialogResult.Cancel)
    End Sub 'OnClosing
    End Class 'ModelessDialog
    7.40. How do I round floating point numbers efficiently?

    There are two primary methods for rounding numbers:
    • Convert.ToInt32
    • Cast or Fix (C# or VB)
    Convert.ToInt32 automatically handles rounding, where remainders of .5 and greater cause the number to be rounded up. Casting or using Fix requires adding .5 to the number to ensure that it will round properly, as these methods simply remove the remainder.

    Profiling on the emulator and a Compaq iPAQ H3600 series device yielded the following results for 1 million operations of each method, where num is a float set to 3.6F:

    Emulator
    iPAQ
    Operation Debug (ms) Release (ms) Debug (ms) Release (ms)
    C#: Convert.ToInt32(num) 1321 1109 6264 6283
    C#: (int)(num + .5F) 170 49 1479 59
    VB: Convert.ToInt32(num) 1218 1232 6531 6517
    VB: Fix(num + .5F) 3873 3677 18144 17955

    Thus, by examining the release build results for the device, it can be concluded that on the current generation of devices it is most efficient to use casting in C# and Convert.ToInt32 in VB. In C#, casting proved to be over 106 times faster, whereas in VB, Convert.ToInt32 was nearly 3 times faster.
    //C#
    float temp = 3.6f;
    int rounded1 = (int)(temp + .5f);
    int rounded2 = Convert.ToInt32(temp);

    'VB
    Dim temp As Single = 3.6F
    Dim rounded1 As Integer = Fix(temp + .5F)
    Dim rounded2 As Integer = Convert.ToInt32(temp)
    7.41. Why does Control.Invoke take so long when a modal dialog is displayed?

    There is a known bug with using Control.Invoke while a modal dialog is displayed through ShowDialog. Download the latest .NET Compact Framework Service Pack to fix this:

    The latest platform updates and .NET Compact Framework service packs are available at:
    http://msdn.microsoft.com/mobility/downloads/default.aspx


    7.42. Is there a way to retrieve the culture information of an Assembly?

    Culture information can be retrieved through Reflection:
    //C#
    using System.Reflection;
    using System.Globalization;

    Assembly asm = Assembly.GetExecutingAssembly();
    CultureInfo ci = asm.GetName().CultureInfo;

    'VB
    Imports System.Reflection
    Imports System.Globalization

    Dim asm As Assembly = Assembly.GetExecutingAssembly()
    Dim ci As CultureInfo = asm.GetName().CultureInfo
     

    8.ͨѶºÍWeb·þÎñ


    8.1. ÈçºÎͨ¹ýTCP SocketÏò×ÀÃæ»ú·¢ËÍÊý¾Ý£¿

    Çë²é¿´±¾ÎÊ´ðµÄ"10.5. дһ¸ö²¶×½Pocket PCÇ©ÃûµÄ³ÌÐò. " ²¿·Ö¡£

    8.2. Ϊʲô²»ÄÜ·ÃÎʱ¾»úÉϵÄWeb·þÎñ£¿

    ²»ÒªÔÚÉ豸ÉÏʹÓÃlocalhostÀ´ÒýÓÃWeb·þÎñ£¬ÒòΪ¶ÔÓÚÉ豸À´Ëµlocalhost¾ÍÊÇÔËÐÐÓ¦ÓóÌÐòËùÔÚµÄÉ豸£¬¾ÍÊÇÉ豸Ëü±¾Éí¡£ÄúÓ¦¸ÃʹÓûúÆ÷Ãû»òIPµØÖ·À´ÒýÓÃWeb·þÎñ¡£

    8.3. ÈçºÎÔÚ΢Èí.net¾«¼ò¿ò¼ÜÉϵ÷ÓÃWeb·þÎñ

    ÕâÆªÎÄÕÂÏòÄúÑÝʾÁËÈçºÎ´ÓÖÇÄÜÉ豸ÉÏ£¬Í¨¹ý.net¾«¼ò¿ò¼Üͬ²½ºÍÒì²½µ÷ÓÃWeb·þÎñ£º

    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfwebservices.asp

    8.4. ÈçºÎͨ¹ý´úÀí·þÎñÆ÷Ìá½»HTTP GETÉêÇ룿

    ͨ¹ý»ò²»Í¨¹ýÌØ¶¨µÄ´úÀí·þÎñÆ÷Ìá½»HTTP GETÇëÇó¡£
    ʹÓÃStreamReader¶ÁÈ¡·µ»ØµÄHTML£¬²¢×ª³É×Ö·ûÊý×顣Ȼºó°Ñ·µ»ØµÄÖµÏÔʾÔÚListBoxÖУ¬ÈçÒÔÏÂµÄÆÁÄ»½ØÍ¼Ëùʾ£º
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/httpgetwithproxy.aspx

    8.5. ÈçºÎʹÓÃWeb·þÎñ£¿

    ÕâÆª¿ìËÙÈëÃŽ̳̣¬ÃèÊöÁËÈçºÎʹÓÃÌṩÁ˼òµ¥Êýѧ¼ÆËãµÄWeb·þÎñ(Õâ¸öÊýѧ¼ÆËãµÄWeb·þÎñÔÚ.net¿ò¼ÜµÄ¿ìËÙÈëÃÅÖÐÓÐ˵Ã÷£¬±êÌâÊÇ"Write a Simple Web service,")¡£Õâ¸ö¿ìËÙÈëÃŽ̳ÌÌṩÁËÒ»¸öWeb·þÎñµÄ¿Í»§¶ËÓ¦Óãº
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/xmlwebservice.aspx

    8.6. ÈçºÎʹÓÃMapPoint3.0µÃµ½µØÍ¼£¿

    ÕâÆª¿ìËÙÈëÃÅÃèÊöÁËÈçºÎʹÓÃMapPointµÄWeb·þÎñ£¬±à³ÌʵÏÖÔÚPocketPCÉÏ»ñµÃÌØ¶¨Î»ÖõijÌÐò£¬ÈçÒÔÏÂÆÁÄ»½ØÍ¼Ëùʾ£º
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/mappointfindmap.aspx

    8.7. ÈçºÎʹÓÃMapPoint3.0»ñµÃµØÍ¼ºÍ·½Ïò£¿

    ÕâÆª¿ìËÙÈëÃŽ̳ÌÃèÊöÁËÈçºÎʹÓÃMapPointµÄWeb·þÎñ£¬ÔÚPocketPCÉÏ»ñµÃÌØ¶¨Î»ÖõĵØÍ¼·½Ïò£¬ÈçÒÔÏÂÆÁÄ»½ØÍ¼Ëùʾ£º
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/mappointdirections.aspx

    8.8. Is NTLM authentication supported by the .NET Compact Framework?

    Using Digest authentication instead of Basic or NTLM authentication is the recommended solution. Digest authentication is supported by the .NET Compact Framework.

    8.9. When using blocking Sockets, why does Send throw an InvalidOperationException when blocking is set to false?

    There is a known issue with setting Blocking to false on a blocking socket. There are three paradigms when programming with sockets (both managed and native) and it is strongly recommended that developers use asynchronous I/O functions as a solution to this problem. Select is very inefficient in managed code, and the cost of the regular case exception is also high. The three paradigms are detailed below, with the last being the preferred method.

    • Use blocking calls on blocking sockets (i.e. send(), recv(), etc). This is the simplest method, and probably the most commonly used. The functions perform their operation synchronously, tying up the currently executing thread. This is most acceptable for clients, and multithreaded servers (Microsoft does not recommend using one thread per client because threads are very expensive on Windows). Note that though the operations may block for an unspecified period of time (i.e. until the operation can be completed), they will most often complete immediately.
    • Use non-blocking sockets in conjunction with select or poll. Use the same "blocking" functions, but put the socket in a special mode that prohibits it from blocking. In the cases when the function would block, it returns an error code (in managed code, this throws an exception). You can then use poll or select to wait until a point in time at which an operation would complete (select allows you to manage more than one socket, so you can handle multiple clients on only one thread), and then perform the operation. At the time these calls were created, there were no threads in operating systems, so this was the only way to do things. Using this mechanism has by far the absolute worst performance you could possibly get from socket programming. This problem is exacerbated in managed code, since you now expect an exception to be thrown, which is an even bigger performance hit.
    • Use asynchronous I/O functions on the socket. This is your best all around solution. It allows you to perform operations asynchronously, and you get notified by callbacks. In general, the performance is better than using non-blocking I/O with select, and this is the recommendation for how to do things (at least, in native code).


    8.10. How do I create an http-server?

    Get technical insight on the implementation of Mobile Web Server architecture. Understand use cases, the web server framework and future developments in the architecture:
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/NETCFMA.asp

    8.11. Why do I get an exception when calling SetSocketOption with ReuseAddress set?

    This is a known issue in the version 1 of the .NET Compact Framework. To work around the issue, you can P/Invoke setsockopt with SO_REUSEADDR set to true.

    8.12. Why do I get a socket error using SSL to communicate with a server via the WebRequest namespace?

    There is a known issue in the .NET Compact Framework. You can work around this by setting HttpWebRequest.AllowStreamWriteBuffering to True and commenting out your setting of the ContentLength.

     


    9. SQL CE ºÍ Êý¾Ý


    9.1. ʹÓÃ.net¾«¼ò¿ò¼Ü¡¢SQL Server CE ºÍ ¸´ÖÆ ¿ª·¢Ó¦ÓóÌÐòʱ£¬Òª×¢ÒâЩʲô£¿

    ÕâÆªÎÄÕÂÏêϸÌÖÂÛÁËÕâ¸öÎÊÌ⣺
    http://msdn.microsoft.com/msdnmag/issues/03/09/datapoints/toc.asp

    9.2. ÈçºÎÔÚ΢Èí.net¾«¼ò¿ò¼ÜÉÏʹÓúϲ¢¸´ÖÆ(Merge Replication)£¿

    ÕâÆªÎÄÕÂÌÖÂÛÁËÈçºÎͨ¹ý³ÌÐòÔÚ.net¾«¼ò¿ò¼ÜµÄÓ¦ÓóÌÐòÖе÷Óúϲ¢¡¢¸´ÖÆ£º
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfmergereplication.asp

    SQL Server CEÊǷdz£ºÃµÄÔÚÉ豸ÉϹÜÀíÊý¾ÝµÄ¹¤¾ß£¬µ«ÔÚδ¸´ÖƵ½×ÀÃæ»úµÄSQL Server֮ǰ£¬Ëü±ØÐë±£ÁôÊý¾Ý¡£Ê¹Óúϲ¢¡¢¸´ÖÆÔÚÉ豸ÉϹÜÀíÊý¾Ý£¬È»ºóµ±É豸Á¬½Óµ½×ÀÃæ»úʱ£¬Ôٺϲ¢µ½×ÀÃæ»úµÄSQL ServerµÄʵÀýÖС£.net¾«¼ò¿ò¼ÜÌṩSqlCeReplication¶ÔÏ󣬿ÉÒÔͨ¹ý³ÌÐòʵÏÖÊý¾ÝµÄºÏ²¢Óë¸´ÖÆ¡£
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/sqlcemergereplication.aspx

    9.3. ÈçºÎ½«ADO.NETÊý¾ÝºÍ£Ø£Í£Ì°ó¶¨£¿

    ÒÔÏÂÈý¸ö²½Ö裺

    1. ¸ù¾ÝÌṩµÄXMLÎļþ£¬½¨Á¢Ò»¸öXML SchemaÎļþ(.xsd)¡£
    2. ¶ÁÈ¡XMLÊý¾ÝºÍËüµÄschema£¬ÒÔ±ã²Ù×÷¡£
    3. ½«XML±£´æ»áÎļþ¡£
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/adonetdatabinding.aspx

    9.4. ÈçºÎ½¨Á¢SQL Server CEµÄÊý¾Ý¿â£¿

    Äú¿ÉÒÔʹÓÃ.net¾«¼ò¿ò¼ÜÔÚWindows CE.NETµÄÉ豸ÉϽ¨Á¢¡¢¹ÜÀíSQL Server CEµÄÊý¾Ý¿â¡£ÕâÆª¿ìËÙÈëÃŽ̳ÌÑÝʾÁËÈçºÎʵÏÖËü£º
    • ½¨Á¢Ò»¸öSQL CEÊý¾Ý¿â¡£
    • Á¬½Óµ½SQL CEÊý¾Ý¿â¡£
    • ÔÚSQL CEµÄÊý¾Ý¿âÖн¨Á¢Ò»¸ö±í¡£
    • ²åÈëÒ»ÐÐÊý¾Ýµ½SQL CEÊý¾Ý¿âÖС£

    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/sqlcedbcreate.aspx

    9.5. ÈçºÎÏòSQL Server CEÌá½»Ò»¸ö´ø²ÎÊýµÄ²éѯ£¿

    Äú¿ÉÒÔʹÓÃ.net¾«¼ò¿ò¼ÜÔÚÓû§ÊäÈëʱ£¬ÏòSQL Server CEµÄÊý¾Ý¿âÖвåÈëÖµ¡£ÒÔϽ̳ÌÏòÄúչʾÁËÈçºÎʵÏִ˲Ù×÷£º
    • Éè¼ÆÒ»¸öÓû§¿ÉÒÔÉèÖòéѯֵµÄ½çÃæ¡£
    • Á¬½Óµ½SQL CEµÄÊý¾Ý¿â¡£
    • °ÑÓû§ÊäÈëµÄÖµ²åÈëµ½SQL CEµÄÊý¾Ý¿âÖÐ
    http://samples.gotdotnet.com/quickstart/CompactFramework/doc/sqlceparameterizedquery.aspx

    9.6. Why does using RDA and the push method fail with error 27750?

    Symptom
    When calling:
    rda = new SqlCeRemoteDataAccess();
    An error of type SQLCeException with a Native Error Code of 27750 occurs. This error corresponds to "Cannot load sscemw20.dll or ssceca20.dll is missing or not registered."

    Resolution
    Load the library at the start of the application, even if you do nothing with it. To load the library, you can load the SqlCeEngine object.
    SqlCeEngine eng = new SqlCeEngine();
       

    10. ÆäËûÐÅÏ¢


    10.1. Pocket TaskVision ³ÌÐò

    This document provides an overview of the development tasks that were unique to the Pocket TaskVision sample application. Pocket PC devices have much lower storage capacities, memory and lower-end processors than desktop systems¡ªstorage and performance considerations are mentioned throughout the document.
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/wnf_pkttaskvision.asp

    10.2. ½¨Á¢»ùÓÚ΢Èí.net¾«¼ò¿ò¼ÜµÄ½ø³Ì¹ÜÀíÆ÷

    In this article, learn how to marshal structures as byte arrays.
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/ProcessManager.asp

    10.3. ʹÓÃ΢Èí.net¾«¼ò¿ò¼Ü¿ª·¢Òƶ¯ÓÎÏ·

    Learn how to create .NET Compact Framework-based games. Learn the key requirements for writing games targeting small devices and see that the .NET Compact Framework can handle them with ease. Include advanced performance-tuning techniques that you can use to push the limits of your game.
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfgaming.asp

    10.4. ÖÆ×÷Ò»¸ö΢Èí.net¾«¼ò¿ò¼ÜµÄDateTimePicker¿Ø¼þ

    Learn how to use a managed DateTimePicker class in your Pocket PC projects. The .net¾«¼ò¿ò¼Ü provides managed classes for most controls but the DateTimePicker class is not supported. Wrapper classes that P/Invoke the native control can be found on the Web, but this sample provides a purely managed DateTimePicker class that you can use in your Pocket PC projects. The class and sample application are provided in C# and Visual Basic .NET.
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/netcfdatetimepicker.asp

    10.5. дһ¸ö²¶×½Pocket PCÇ©ÃûµÄ³ÌÐò.

    This article discusses the Pocket PC Signature sample application. The sample includes a client that runs on the Pocket PC that sends signature data over TCP sockets to a server that is running on the desktop. Data is encrypted and decrypted using the cryptography services.
    http://msdn.microsoft.com/library/en-us/dnnetcomp/html/PPCSignatureApp.asp

    10.6. ÓÐûÓзÇ΢ÈíµÄÍøÕ¾ÌṩÔÚ.net¾«¼ò¿ò¼ÜÉÏ¿ª·¢Ó¦ÓõÄÐÅÏ¢£¿

    See the "Related Sites" section of the MSDN Mobile and Embedded Developer Center:
    http://msdn.microsoft.com/mobility/Community/related/default.aspx



    11. Á¬Í¨ÐÔ


    11.1. Ϊʲô²»Í¬Í¨¹ýActiveSync°Ñ³ÌÐò²¿Êðµ½Windows CEµÄÉ豸ÉÏ£¿

    Symptom: When a Windows CE device is connected through ActiveSync, deployment and debugging (F5 and Ctrl-F5) fail with the typical error message "There were deployment errors. Continue?"

    Cause: Due to the fact that ActiveSync 3.5 and 3.6 do not provide accurate information about the device instruction set, ConMan (Visual Studio .NET 2003 component for device connectivity) cannot use the information returned by ActiveSync to map a Windows CE device to the right .NET Compact Framework target (MIPSII, ARMV4 etc).

    Workaround: Install and run the separately provided Windows CE Configuration Add-In. For ARMV4 devices, an alternative is to select Pocket PC Device at the beginning of the deployment.

    11.2. Ϊʲô²»ÄÜͨ¹ýActiveSyncµ÷ÊÔ CEPC »òÆäËû x86 µÄWindows CEÉ豸£¿

    Symptom: After running the Windows CE Device Configuration Add-In, the user can deploy without debugging (Ctrl-F5) to an ActiveSync connected CEPC (or any x86 based Windows CE device) but cannot debug (F5). Non-x86 based Windows CE devices do not have this problem.

    Cause: Debugging Windows CE Emulators (also x86 based) uses a TCP port that conflicts with the one used by ActiveSync for debugging x86 based devices. To support Emulator debugging, it is necessary to disable debugging for CEPC and other x86 devices by default.

    Workaround: The following workaround will allow debugging of x86 devices but disable debugging with the Windows CE Emulator. The workaround requires the files WinCEx86Device.reg, and ProxyPorts.reg which can be found in the SDK utilities directory: "<VSROOT>\CompactFrameworkSDK\WinCE Utilities\WinCE Proxy Ports Reg".

    If you do not have these files they can be downloaded from the following link:
    http://www.microsoft.com/downloads/details.aspx?FamilyID=7ec99ca6-2095-4086-b0cc-7c6c39b28762&DisplayLang=en#filelist

    • Import WinCEx86Device.reg to the registry. Now you will be able to debug x86 devices, but debugging with the Windows CE Emulator will fail.
    • To restore Emulator debugging, remove the registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\ProxyPorts" and then import ProxyPorts.reg.

    11.3. Ϊʲôµ±É豸ÉϵÄToolhelp.dllÎļþ¶ªÊ§ºó£¬µ÷ÊԾͻáʧ°Ü£¿

    Symptom: After F5, all the files including the application executables and .net¾«¼ò¿ò¼Ü cab files are copied to the device, and the IDE reports success on launching the application, but nothing is launched on the device. If you check the \windows folder of the device, toolhelp.dll does not exist.

    Cause: Some device images may not include toolhelp.dll which is required by SDE debugging.

    Workaround: Copy toolhelp.dll from Windows CE SDK to the \windows folder of the device. This file can be found in the corresponding target directory for each device.

    For example, for an ARM device: "<VSROOT>\CompactFrameworkSDK\WinCE Utilities\ToolHelp\WinCE4\armv4".

    If you do not have this file it can be downloaded from the following link:
    http://www.microsoft.com/downloads/details.aspx?FamilyID=7ec99ca6-2095-4086-b0cc-7c6c39b28762&DisplayLang=en#filelist

    11.4. Ϊʲôµ±ÍøÂçЭÒéÊý³¬¹ý£µ£°¸öµÄʱºò£¬¾Í²»ÄÜÏòÉ豸·¢²¼³ÌÐò£¿

    Symptom: The "deployment error" message box occurs on Ctrl-F5 or F5. Running EnumProtocols.exe lists more than 50 protocols. (EnumProtocols.exe can be found in the WinCE utilites directory: "<VSROOT>\CompactFrameworkSDK\WinCE Utilities\EnumProtocols"). If you do not have this file it can be downloaded from the following link:
    http://www.microsoft.com/downloads/details.aspx?FamilyID=7ec99ca6-2095-4086-b0cc-7c6c39b28762&DisplayLang=en#filelist

    Cause: It is a known issue that the .NET Framework method System.Net.Dns.GetHostName throws an exception when there are more than 50 network protocols installed on the current machine. The method is called by ConMan and the exception causes failure of the ConMan transport initialization.

    Workaround: Uninstall the network protocols that are not actually needed. One way to do this is to go to Device Manager (Right-click on "My Computer", select Properties->Hardware and press the "Device Manager" button) and remove unused entries under "Network adapters". Another way is to uninstall applications that have installed protocols. Those applications can be found from the output of EnumProtocles.exe.

    11.5. ÎªÊ²Ã´Ð¶ÔØActiveSyncºó£¬²»ÄÜͨ¹ýActiveSyncÏòÉ豸·¢²¼£¿

    Symptom: The "deployment error" message box occurs on Ctrl-F5 or F5 after ActiveSync has been uninstalled. Uninstalling ActiveSync typically happens when the user upgrades ActiveSync, e.g. from version 3.5 to 3.6.

    Cause: ConMan relies on some registry values under "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows CE Services\ProxyPorts" for deployment and debugging through ActiveSync. These registry values are removed when ActiveSync is uninstalled.

    Workaround: Reinstall or repair Visual Studio .NET 2003.
    A simpler fix is to import ProxyPorts.reg which can be found in the WinCE utilities folder: "<VSROOT>\CompactFrameworkSDK\WinCE Utilities\WinCE Proxy Ports Reg" . If you do not have this file it can be downloaded from the following link:
    http://www.microsoft.com/downloads/details.aspx?FamilyID=7ec99ca6-2095-4086-b0cc-7c6c39b28762&DisplayLang=en#filelist

    The device may need to be un-cradled/re-cradled or soft rebooted to make the fix take effect.
    It is recommended that users never uninstall ActiveSync. To upgrade ActiveSync, you should directly install the new version which will correctly override the old one.

    11.6. Ϊʲô±¾µØ»¯µÄ»úÆ÷Ãû»òÓû§Ãû»òµ¼ÖÂÏòÉ豸·¢²¼³ÌÐòµÄʧ°Ü£¿

    Symptom: When the machine name or the logon user name contains any character that is not on the current code page or below ASCII value 0x20, deployment to devices fails while deployment to the Emulator works fine.

    Cause: ConMan security authentication internally uses the machine name and user name in the ASCII form which is not able to handle characters in the categories described above.

    Workaround: Do not use characters described above in the machine name or the user name. If the user is not clear what characters belong to those categories, it is always safe to use just English alphabetic letters and numbers.

    11.7. Ϊʲôµ±Ç°Óû§²»ÊôÓÚAdministrators×éµÄʱºò£¬²»ÄÜÏòÉ豸·¢²¼³ÌÐò£¿

    Symptom: If the current logon user is not in the Administrators group, deployment to devices always fails even though the user is in the Visual Studio Developers group and the Debugger Users group. On the other hand deployment/debugging to the Emulator works fine.

    Cause: During device deployment, the ConMan code internally opens a file in a mode that requires administrator privileges.

    Workaround: Add the current user to the Administrators group or limit the deployment target to the Emulator only.

    11.8. ΪʲôÏòPocket PC»òÄ£ÄâÆ÷·¢²¼µÄʱºò³öÏÖ sharing violation µÄ´íÎó£¿

    Symptom: When deploying an application to a Pocket PC 2002/2003 device or Emulator, the deployment fails with an output message similar to "Could not write to output file 'SmartDeviceApplication1.exe' - Sharing violation". This usually happens after the same application has previously deployed to the same device or Emulator.

    Cause: By default the X button on an application for Pocket PC 2002 or 2003 (not 2000) does not close the process. It only "minimizes" the application window. When the user tries to deploy the application again, the "minimized" instance will cause the sharing violation and fail the deployment.
    Another possible cause is that the user has forcibly terminated a debug session in the middle.

    Workaround: Make sure the application is really closed on the device or Emulator when deploying it again. To see running processes, go to Start->Settings->Memory->Running Programs on the Pocket PC. In case it is intended to have a button to really close an application, create such a button explicitly or set Windows Form's property Minimize Box to False so that the X button will become an OK button for closing the application. If the cause was the manual termination of a debug session, the device or the Emulator may need to be soft rebooted.

    11.9. ΪʲôÔÚ.NET ServerµÄ¼ÆËã»úÉϵÚÒ»´ÎʹÓÃÄ£ÄâÆ÷µÄʱºò£¬µÃµ½Ò»¸ö°²È«¾¯¸æÏûÏ¢£¿

    Symptom: When the Emulator is used for the first time after the installation of Visual Studio .NET 2003 on a .NET Server machine, a message box pops up titled "Security Alert a€¡° Driver Installation". The text of the message starts with "The driver software you are installing for: Virtual PC Application Services has been signed with Authenticode(TM) technology. The publisher's identity has been identified, and the driver has not been modified since it was published". Near the end, it says "However, this driver cannot be tested by Microsoft Windows Hardware Quality Labs to verify its compatibility with this version of Windows. a€| Do you trust this publisher and want to install the driver?"

    Cause: Visual Studio .NET 2003 installs a Virtual PC Application Services Emulator driver which does not pass the validation of .NET Server's Driver Validation system.

    Workaround: When the alert message comes up, click the Yes button. Otherwise the Emulator will not work.

    11.10. ΪʲôÔÚÄ£ÄâÆ÷¸Õ¿ªÊ¼ÔËÐеÄʱºò³öÏÖ¹ØÓÚÕÒ²»µ½ÎļþµÄ´íÎóÐÅÏ¢£¿

    Symptom: When the Emulator is being started, a message box appears titled "Emulator for Windows CE" with the text "One or more files from the Emulator for Windows CE installation is missing. Please reinstall Emulator for Windows CE and try again." The connection or deployment to the Emulator will fail after the message box.

    Cause: A typical cause is that the Emulator driver is not installed or is corrupted.

    Workaround: Go to "Device Manager" (Right-click on "My Computer", select Properties->Hardware and press the "Device Manager" button) and check whether "Virtual PC Application Services" is installed under the System Devices group. If the driver is not installed, install it by running "<VSROOT>\CompactFrameworkSDK\ConnectionManager\Bin\DriverInstall\Smart Devices Emulator.msi".

    Note: Verify that the "Virtual PC Application Services" appears after running the msi file. If not then reboot the PC and attempt the installation again.

    11.11. ΪʲôµÚÒ»´ÎÓÃÄ£ÄâÆ÷·¢²¼Ê±£¬»á³öÏÖż¶ûµÄ´íÎó£¿

    Symptom: The startup of the Emulator is slow and the deployment eventually fails with a connection error message. The startup mainly includes starting the Emulator image and downloading the .net¾«¼ò¿ò¼Ü files. The failure happens more often on low-end machines when the Emulator is used for the first time or after "turn off" instead of "saving state" was used on the previous Emulator shutdown.

    Cause: Due to some performance issues in the Emulator, its startup may take too long to finish within the ConMan timeout period.

    Workaround: If possible, always choose "saving state" instead of "turn off" when closing the Emulator so that the startup will be much faster when the Emulator is started next time. Or before the deployment, pre-start the Emulator by clicking on the "Connect to Device" button which is located next to the Emulator name on the menu bar. Note that the first deployment will still fail after the pre-start. (See details in the issue about this.) In addition, hovering the mouse over the Emulator image may speed up the Emulator startup.

    11.12. ΪʲôµÚÒ»´ÎÓÃConnect°´Å¥Á¬½ÓÄ£ÄâÆ÷²¢·¢²¼³ÌÐòµÄʱºòʧ°ÜÁË£¿

    Symptom: When the Emulator is started with the "Connect to Device" button, the first deployment attempt always fails.

    Workaround: There is no workaround at this point for the failure of the first deployment after the Emulator is started with the button, but the subsequent deployment attempts should succeed.

    11.13. Ϊʲôµ±¼ÆËã»úûÓÐÍøÂçÁ¬½ÓµÄʱºò£¬ÓÃÄ£ÄâÆ÷µ÷ÊÔ³ÌÐò»á³öÏÖ´íÎó£¿

    Symptom: When a machine has no active network connection, debugging with the Emulator (F5) does not work, while deployment without debugging (Ctrl-F5) works fine.

    Cause: Emulator debugging relies on TCP transport.

    Workaround: Install the Microsoft Loopback Adapter on the machine.

    To install the the Microsoft Loopback Adapter in Microsoft Windows XP

    1. Open Control Panel, choose Add Hardware, and then choose Next.
    2. Choose Yes, I have already connected the hardware, and then choose Next.
    3. From the Installed hardware list, select Add a new hardware device, and then choose Next.
    4. Choose Install the hardware that I manually select from a list (Advanced), and then choose Next.
    5. From the Common hardware types list, select Network adapters, and then choose Next.
    6. From the Manufacturer list, select Microsoft.
    7. From the Network Adapter list, select Microsoft Loopback Adapter, and then choose Next.
    8. Choose Next, and then choose Finish.

    To install the Microsoft Loopback Adapter in Microsoft Windows 2000

    1. Open Control Panel, choose Add/Remove Hardware, and then choose Next.
    2. Choose Add/Troubleshoot a device, and then choose Next.
    3. From the Devices list, select Add a new device, and then choose Next.
    4. Choose No, I want to select the hardware from a list, and then choose Next.
    5. From the Hardware types list, select Network adapters, and then choose Next.
    6. From the Manufacturers list, select Microsoft.
    7. From the Network Adapter list, select Microsoft Loopback Adapter, and then choose Next.
    8. Choose Next, and then choose Finish.

    11.14. Ϊʲôµ±Ä£ÄâÆ÷ʹÓÃÁËÒ»¸öCOM¶Ë¿ÚµÄʱºò²»Æô¶¯²»ÁË(ºÚÆÁ)£¿

    Symptom: When the Emulator image is starting up, it stays as a black screen forever. This happens when the Emulator is configured to use at least one COM port.

    Cause: By default, the Emulator is not assigned a COM port but the user may change the configuration to assign a COM port to the Emulator. When a COM port assigned to the Emulator is used by ActiveSync or any other running application, the Emulator image loading will fail.

    Workaround: Remove all of the COM ports assigned to the Emulator or change them to those not used by ActiveSync or any other running application. To remove or change the COM port configurations in Visual Studio .NET 2003, go to Tools/Options/Devices, choose an Emulator in the Devices window and click the Configure button.

    11.15. ΪʲôVisual Studio .NET 2003µÄÄ£ÄâÆ÷²»ÄܺÍeMbedded Visual ToolsµÄÄ£ÄâÆ÷ͬʱʹÓã¿

    Symptom: When the eMbedded Visual Tools (Platform Builder) Emulator is running, Visual Studio .NET 2003 Emulator deployment fails, and vice versa. Sometimes even after the Visual Studio .NET 2003 Emulator is closed, the eMbedded Visual Tools Emulator still does not work.

    Cause: The Visual Studio .NET 2003 Emulator and the eMbedded Visual Tools Emulator internally use two different instances of Emulator.exe which are not compatible with each other. Because they share the same executable name and the exe is a single instance application, while Emulator.exe for eMbedded Visual Tools is running, the one for Visual Studio .NET 2003 cannot be started, and vice versa. Another issue is that when the Visual Studio .NET 2003 Emulator user interface is closed, emulator.exe does not close until the hosting Visual Studio IDE instance is closed. In that case, the eMbedded Visual Tools Emulator cannot be started even though there is no Emulator running visually.

    Workaround: Do not use the two Emulators at the same time. If an Emulator cannot be started, check the Task Manager and close any running emulator.exe processes.

    11.16. ΪʲôûÓÐActiveSyncÁ¬½ÓµÄʱºò²»ÄÜͨ¹ýTCPÁ¬½ÓÏòÉ豸·¢²¼³ÌÐò£¿

    Symptom: When a device does not have an ActiveSync connection with the Visual Studio machine but has a valid TCP connection, deployment does not work.

    Cause: ConMan relies on an ActiveSync connection to perform some initial settings between the Visual Studio machine and the device. If no ActiveSync connection is available, the setting will have to be performed manually.

    Workaround: Use the separately provided Keyman tool to perform the initial device settings with the following steps:

    1. Choose the correct flavor of Keyman.exe (e.g. ARMV4 or SH4, etc) and place it on the device. Launch Keyman and select "FILE->CONNECT". Keyman is now waiting for the VS machine to connect to it via TCP/IP. After the VS machine has connected, and then disconnected, Keyman on the device will automatically exit.
    2. On the VS machine, copy CryptoAPIWrapper.dll from <VSROOT>\ CompactFrameworkSDK\ConnectionManager\bin to the directory of KeymanDesktop.exe. Launch KeymanDesktop.exe.
    3. Click "Save" to save your settings in the current directory where KeymanDesktop.exe is running. The saved defaults will be loaded next time the exe is launched.
    4. Enter the IP Address of the device
    5. Use the recommended value for the Device Port.
    6. Enter the path of the "Target" directory where the ConmanClient bits such as ConManClient.exe reside. The typical value is \ CompactFrameworkSDK\ConnectionManager\Target.
    7. Use the Connect button to connect.
    8. Click on "prep device" after you have connected. On success, you will see a dialog telling you everything went OK.
    9. Use the Disconnect button to disconnect. When you disconnect, the device side bits will automatically exit.
    10. Launch ConManClient.exe on the device. First you must select the flavor of the target device. Also, you must select the location of your "Target" directory in Visual Studio.
    11.17. How can I allow Activesync to connect to an Emulator session from Visual Studio .NET 2003?

    Download the Emulator ActiveSync Connection Tool from Windows Mobile Developer Power Toys:
    http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

    11.18. How can I copy files to the device currently connected to desktop ActiveSync?

    Download CECopy from Windows Mobile Developer Power Toys:
    http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

    11.19. Why does the Visual Studio debugger fail to connect to an ARMV4I device?

    Cause
    Bug in the connection tool after selecting ARMV4I CPU type

    Resolution
    Configure tool for ARMV4T CPU type:
    1. In Visual Studio, on the Tools menu, click "Select Windows CE Device CPU". Note: this menu item is installed by the Windows CE Utilities for Visual Studio .NET 2003 Add-on Pack
    2. Change the device architecture to ARMV4T
    3. Click Configure, then click Close. Restart Visual Studio if prompted


    12. Smartphone

    12.1. Where can I get the latest Smartphone SDK?

    Download the Windows Mobile 2003 Smartphone SDK here:
    http://www.microsoft.com/downloads/details.aspx?familyid=a6c4f799-ec5c-427c-807c-4c0f96765a81&displaylang=en

    12.2. What are the rules for smartphone menus?

    Smartphone menus have several rules, such as:

    • the first menu item (corresponding to the left soft button) cannot have any sub items
    • the second menu item (corresponding to the right soft button) can have sub items
    • any other top level menu items are not used
    If the first menu item has more than 1 item, you will get a NotSupportedException.

    For a complete list of requirements, refer to the Smartphone help documentation:
    ms-help://MS.VSCC.2003/MS.Smartphone2003Help.1033/dv_smartphone/html/spconUsingMenus.htm

    The preceding link is referenced from the Windows Mobile 2003 Smartphone SDK:
    http://www.microsoft.com/downloads/details.aspx?familyid=a6c4f799-ec5c-427c-807c-4c0f96765a81&displaylang=en

    12.3. Why are there disabled controls in the toolbox when creating a Smartphone project?

    The smartphone platform only supports a small set of controls. The controls that are not supported are disabled.

    For more information, refer to the following Smartphone help documentation:
    ms-help://MS.VSCC.2003/MS.Smartphone2003Help.1033/dv_smartphone/html/spconWindowsFormsSupport.htm

    The preceding link is referenced from the Windows Mobile 2003 Smartphone SDK:
    http://www.microsoft.com/downloads/details.aspx?familyid=a6c4f799-ec5c-427c-807c-4c0f96765a81&displaylang=en

    12.4. Does Smartphone support RAM installs of the .NET Compact Framework?

    No. The .NET Compact Framework is serviced through operating system updates at the carrier's / OEM's discretion. Therefore, .NET Compact Framework will generally drop as part of larger Windows Mobile for Smartphone operating system updates.

    12.5. How do I set the title of a fullscreen multiline edit control window?

    This is not supported by the current version of the .NET Compact Framework.

    12.6. How can I generate Smartphone CABWizSP XML docs from existing Pocket PC CAB files?

    Download Convert PPC DAT to SP XML from Windows Mobile Developer Power Toys:
    http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

    12.7. How can I send characters and strings to the Smartphone 2003 Emulator via ActiveSync?

    Download TypeIt from Windows Mobile Developer Power Toys:
    http://www.microsoft.com/downloads/details.aspx?FamilyId=74473FD6-1DCC-47AA-AB28-6A2B006EDFE9&displaylang=en

    12.8. How do I programmatically set the Smartphone input mode?

    The input mode can be set using GetFocus and SendMessage APIs according to the code below:
    'VB
    Imports System.Runtime.InteropServices

    Public Const EM_SETINPUTMODE As Integer = &HDE
    Public Const EIM_SPELL As Integer = 0
    Public Const EIM_AMBIG As Integer = 1
    Public Const EIM_NUMBERS As Integer = 2

    <DllImport("coredll.dll")> _
    Public Shared Function GetFocus() As IntPtr
    End Function

    <DllImport("coredll.dll")> _
    Public Shared Function SendMessage(ByVal hWnd As IntPtr, _
    ByVal Message As Integer, ByVal wParam As Integer, _
    ByVal lParam As Integer) As Integer
    End Function

    'Sample use setting TextBox to number input
    Private Sub txtAmount_GotFocus(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles txtAmount.GotFocus

    Dim hWnd As IntPtr
    hWnd = Me.GetFocus()
    SendMessage(hWnd, EM_SETINPUTMODE, 0, EIM_NUMBERS)
    txtAmount.SelectionStart = txtAmount.Text.Length

    End Sub

    //C#
    using System.Runtime.InteropServices;

    public const uint EM_SETINPUTMODE = 0xDE;
    public const uint EIM_SPELL = 0;
    public const uint EIM_AMBIG = 1;
    public const uint EIM_NUMBERS = 2;

    [DllImport("coredll.dll")]
    public static extern IntPtr GetFocus();

    [DllImport("coredll.dll")]
    public static extern int SendMessage(IntPtr hWnd,
    uint Message, uint wParam, uint lParam);

    // Sample use setting TextBox to number input
    private void Form1_Load(object sender, System.EventArgs e)
    {
    txtAmount.GotFocus +=
    new System.EventHandler(txtAmount_GotFocus);
    }

    private void txtAmount_GotFocus(object sender, System.EventArgs e)
    {
    IntPtr hWnd;
    hWnd = GetFocus();
    SendMessage(hWnd, EM_SETINPUTMODE, 0, EIM_NUMBERS);
    txtAmount.SelectionStart = txtAmount.Text.Length;
    }

×îиüÐÂ
¡¤C#ÖÐʹÓÃSplit·Ö¸ô×Ö·û´®µÄ¼¼
¡¤VS2008¿ª·¢ÖÐWindows Mobile
¡¤PC»úºÍÒÆ¶¯É豸ÉϾø¶Ô·¾¶µÄ
¡¤C#³ÌÐò¼Ó¿ÇµÄ·½·¨£¨Ê¹ÓÃSixx
¡¤µ±Ç°ÉÏÏÂÎÄÖв»´æÔÚÃû³ÆConf
¡¤Çë²åÈë´ÅÅÌ:Visual Studio 2
¡¤ÓÃVS.NET¶ÁÈ¡Flash¸ñʽÎļþÐÅ
¡¤ÔÚASP.NETÖÐʹÓÃAJAXµÄ¼òµ¥·½
¡¤VS.NET 2005Öг£ÓõÄһЩ´úÂë
¡¤°²×°VS.NET 2005 SP1²¹¶¡È«¹¥
Ïà¹ØÐÅÏ¢
¡¤.NET CF2.0ºÍSqlCE3.0ÔÚPocket PCµÄ°²×°Îļþ
¡¤.NET CF 2.0µÄ¸÷°æ±¾°²×°Îļþ˵Ã÷
 »­ÐÄ
 ÓÞ°®
 Æ«°®
 »ðÃç
 °×ºü
 »­É³
 ·¸´í
 ¸èÇú
 ³ÃÎÒ
 µ¾Ïã
 Ð¡¾ÆÎÑ
 Ê¨×Ó×ù
 Ð¡Çé¸è
 È«Êǰ®
 ÃÞ»¨ÌÇ
 ÎÒÖªµÀ
 ×êʯÌÇ
 Nobody
 ÎÒ°®Ëû
 Ì×Âí¸Ë
 ÐÇ¿ÕÎïÓï
 ×îºóÒ»´Î
 ÉÙŮʱ´ú
 ´©Ô½È˺£
 ¶ÏÇŲÐÑ©
 ÃÀÁËÃÀÁË
 Ã÷Ìì¹ýºó
 ÎҺܿìÀÖ
 µ½ÁËÃ÷Ìì
 ÐÄÍ´2009
 °®Ñ¾°®Ñ¾
 ¼ÅįºÃÁË
 ¸Ò²»¸Ò°®
 ÀɵÄÓÕ»ó
 °®ÇéÂòÂô
 super girl
 ÎÒ½ÐСÉòÑô
 i miss you
 ¹ÃÄïÎÒ°®Äã
 ÎÒÃǶ¼Ò»Ñù
 ÆäʵºÜ¼Åį
 Ï°¹ßÁ˼Åį
 ÎÒÒªµÄ·ÉÏè
 ÎҵĺÃÐÖµÜ
 °®µÄ»ª¶û×È
 ÀîÀ׺ͺ«Ã·Ã·
 ±´¶à·ÒµÄ±¯ÉË
 °®ÎҾ͸úÎÒ×ß
 ¶ªÁËÐÒ¸£µÄÖí
 ÎÒÖ»ÊǸö´«Ëµ
 Òª¼Þ¾Í¼Þ»ÒÌ«ÀÇ
 ¼´Ê¹ÖªµÀÒª¼ûÃæ
 Èç¹ûÎÒ±ä³É»ØÒä
 ¿´µÃ×îÔ¶µÄµØ·½
 Ë¹ÇÙ¸ßÀöµÄÉËÐÄ
 ±ðÔÚÎÒÀ뿪֮ǰÀ뿪
 ²»ÊÇÒòΪ¼Åį²ÅÏëÄã
 °®ÉÏÄãµÈÓÚ°®ÉÏÁË´í
 ÔÚÐÄÀï´Ó´ËÓÀÔ¶ÓиöÄã
 Ò»¸öÈ˵ļÅįÁ½¸öÈ˵Ĵí