c# wince 获取外部程序的图标

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Media;
using System.IO;
using Microsoft.Win32;
using System.Drawing;
using System.Runtime.InteropServices;
namespace CE_APP
{
    class CommonClass
    {


#region 获取文件的icon


        /// <summary>
        /// 获取文件类型的关联图标
        /// </summary>
        /// <param name="fileName">文件类型的扩展名或文件的绝对路径</param>
        /// <param name="isLargeIcon">是否返回大图标</param>
        /// <returns>获取到的图标</returns>
        public static Icon GetIcon(string fileName, bool isLargeIcon)
        {
            SHFILEINFO shfi = new SHFILEINFO();
            IntPtr hI;


            if (isLargeIcon)
                hI = SHGetFileInfo(fileName, 0, ref shfi, (uint)Marshal.SizeOf(shfi), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES | SHGFI_LARGEICON);
            else
                hI = SHGetFileInfo(fileName, 0, ref shfi, (uint)Marshal.SizeOf(shfi), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES | SHGFI_SMALLICON);


            Icon icon = Icon.FromHandle(shfi.hIcon).Clone() as Icon;


            DestroyIcon(shfi.hIcon); //释放资源
            return icon;
        }










        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        struct SHFILEINFO
        {
            public IntPtr hIcon;
            public int iIcon;
            public uint dwAttributes;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
            public string szDisplayName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
            public string szTypeName;
        }


        [DllImport("coredll.dll", EntryPoint = "SHGetFileInfo", SetLastError = true, CharSet = CharSet.Auto)]
        private static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, uint uFlags);


        [DllImport("coredll.dll", EntryPoint = "DestroyIcon")]
        public static extern int DestroyIcon(IntPtr hIcon);


        #region API 参数的常量定义


        public const uint SHGFI_ICON = 0x100;
        public const uint SHGFI_LARGEICON = 0x0; //大图标 32×32
        public const uint SHGFI_SMALLICON = 0x1; //小图标 16×16
        public const uint SHGFI_USEFILEATTRIBUTES = 0x10;


        #endregion


        //private Icon iconPic;






        /// <summary>
        /// 使用选定的刷子、源位图和ROP3码绘制选定的矩形
        /// 获得屏幕图形并将它写入内存中的一个位图中(截屏)
        /// </summary>
        /// <param name="hdcDest">目的上下文设备的句柄 </param>
        /// <param name="nXDest">目的图形的左上角的x坐标 </param>
        /// <param name="nYDest">目的图形的左上角的y坐标 </param>
        /// <param name="nWidth">目的图形的矩形宽度 </param>
        /// <param name="nHeight">目的图形的矩形高度 </param>
        /// <param name="hdcSrc">源上下文设备的句柄</param>
        /// <param name="nXSrc">源图形的左上角的x坐标</param>
        /// <param name="nYSrc">源图形的左上角的x坐标</param>
        /// <param name="dwRop">光栅操作代码 </param>
        /// <returns></returns>
        [DllImport("CoreDLL.dll")]
        public static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
#endregion




#region 引用coredll
        [DllImport("coredll.dll")]
        public static extern void GwesPowerOffSystem();     //程序控制设备进入待机状态 Stand by mode


        [DllImport("coredll.dll")]
        public static extern void TouchCalibrate();         //弹出触摸笔校准界面




        //ChangeDisplaySettingsEx 旋转屏幕的函数


#endregion


   


        private const string filePath = @"\windows\Barcodebeep.wav";


        /// <summary>
        /// 获取当前程序的路径
        /// </summary>
        /// <returns></returns>
        public static string getCurPath()
        {
            return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
        }


        public static bool PlaySound()
        {
            try
            {
                if (File.Exists(filePath))
                {
                    SoundPlayer player = new SoundPlayer(filePath);
                    player.Play();
                }
                return true;
                
            }
            catch (System.Exception)
            {
                return false;
            }
            
        }




        /// <summary>
        /// 调用触摸笔校准程序,直接进入触摸笔校准界面
        /// </summary>
        public static void TouchTest()
        {
            TouchCalibrate();
        }


        /// <summary>
        /// 系统进入待机状态
        /// </summary>
        public static void PowerOffSystem()
        {
            GwesPowerOffSystem();
        }




     
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值