微软.net精简框架常见问题及回答(中文版)

FastCounter by bCentral

最常见问题(FAQ)

微软.net精简框架最常见问题。

此FAQ的内容,一部分来自 net精简框架新闻组 (microsoft.public.dotnet.framework.compactframework)张贴和回答的问题。.net精简框架开发小组感谢每一位参与新闻组的人事,感谢他们对FAQ编写的积极参与和对FAQ的投稿。

要申请添加FAQ项目,请发邮件到 [email protected] .

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. 如何调用本地写的DLL中的函数?
> 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. 如何在我的程序中调用另一个应用程序?
> 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数据和XML绑定?
> 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. 为什么当网络协议数超过50个的时候,就不能向设备发布程序?
> 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?
>

> Top of Page Top of Page


**

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系统,MSTV。 各种设备的发布时间待定。

.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精简框架应用程序:

**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. 为什么当网络协议数超过50个的时候,就不能向设备发布程序?" 部分。

**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)

Top of Page Top of Page


**

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.

Top of Page Top of Page


**

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设备的应用程序安装文件。查看示例代码:
<A href="http://s


Published At
Categories with Web编程
Tagged with
comments powered by Disqus