windows mobile 开发实例wi ndows mobile 开发实例

源代码在线查看: yaodurant.drawing.fontcollection.cs

软件大小: 1322 K
上传用户: dan_che
关键词: mobile windows ndows 开发实例
下载地址: 免注册下载 普通下载 VIP

相关代码

				// YaoDurant.Drawing.FontCollection.cs - Font enumeration 
				// wrapper class for FONTLIST.DLL.
				//
				// Code from _Programming the .NET Compact Framework with C#_
				// and _Programming the .NET Compact Framework with VB_
				// (c) Copyright 2002-2004 Paul Yao and David Durant. 
				// All rights reserved.
				
				using System;
				using System.Collections;
				using System.Runtime.InteropServices;
				
				namespace YaoDurant.Drawing
				{
				   /// 
				   /// Summary description for YaoDurant.
				   /// 
				   public class FontCollection
				   {
				      // Constructor.
				      public FontCollection()
				      {
				         IntPtr hFontList = FontList_Create();
				         int count = FontList_GetCount(hFontList);
				         int i;
				         string strFace;
				         IntPtr ip;
				         for (i = 0; i < count; i++)
				         {
				            ip = FontList_GetFace(hFontList, i);
				            strFace = Marshal.PtrToStringUni(ip);
				            m_alFaceNames.Add(strFace);
				         }
				         
				         FontList_Destroy(hFontList);
				      }
				      
				      public void Dispose()
				      {
				         m_alFaceNames.Clear();
				      }
				
				      // P/Invoke declarations for fontlist.dll
				      [DllImport("fontlist.DLL")]
				      public static extern IntPtr FontList_Create ();
				
				      [DllImport("fontlist.DLL")]
				      public static extern 
				      int FontList_GetCount (IntPtr hFontList);
				
				      [DllImport("fontlist.DLL")]
				      public static extern 
				      IntPtr FontList_GetFace (IntPtr hFontList, int iFace);
				
				      [DllImport("fontlist.DLL")]
				      public static extern 
				      int FontList_Destroy (IntPtr hFontList);
				      
				      // Count of available face names.
				      public int Count
				      {
				         get { return m_alFaceNames.Count; }
				      }
				
				      private ArrayList m_alFaceNames = new ArrayList();
				      
				      public string this [int index]
				      {
				         get
				         {
				            if (index < 0 || index >= m_alFaceNames.Count)
				               return string.Empty;
				            else
				               return (string)m_alFaceNames[index];
				         }
				      }
				
				   } // class
				} // namespace
							

相关资源