记录一下用到的C#在WinCE平台上的相关技巧备查

1。C#在WinCE上实现透明图片

1
2
3
4
5
6
7
8
9
using System.Drawing.Imaging;
     
public static void DrawImageTransparent(Graphics gx, Image image, Rectangle destRect)
{
    ImageAttributes imageAttr = new ImageAttributes();
    Color transpColor = ((Bitmap)image).GetPixel(image.Width - 1, image.Height - 1);
    imageAttr.SetColorKey(transpColor, transpColor);
    gx.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttr);
}

2。WinCE上播放声音文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
public enum Flags
{
    SND_SYNC = 0x0000,  /* play synchronously (default) */
    SND_ASYNC = 0x0001,  /* play asynchronously */
    SND_NODEFAULT = 0x0002,  /* silence (!default) if sound not found */
    SND_MEMORY = 0x0004,  /* pszSound points to a memory file */
    SND_LOOP = 0x0008,  /* loop the sound until next sndPlaySound */
    SND_NOSTOP = 0x0010,  /* don't stop any currently playing sound */
    SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */
    SND_ALIAS = 0x00010000, /* name is a registry alias */
    SND_ALIAS_ID = 0x00110000, /* alias is a predefined ID */
    SND_FILENAME = 0x00020000, /* name is file name */
    SND_RESOURCE = 0x00040004  /* name is resource name or atom */
}
[DllImport("CoreDll.DLL", EntryPoint = "PlaySound", SetLastError = true)]
public extern static int WCE_PlaySound(string szSound, IntPtr hMod, int flags);
     
/// <summary>
/// 同步播放声音文件
/// </summary>
/// <param name="filename"></param>
public static void PlaySYNCSound(string filename)
{
    if (!string.IsNullOrEmpty(filename))
    {
        if (File.Exists(filename))
        {
            WCE_PlaySound(filename, IntPtr.Zero, (int)(SendClass.Flags.SND_SYNC | SendClass.Flags.SND_FILENAME));
        }
    }
}
     
/// <summary>
/// 异步播放声音文件
/// </summary>
/// <param name="filename"></param>
public static void PlaySound(string filename)
{
    if (!string.IsNullOrEmpty(filename))
    {
        if (File.Exists(filename))
        {
            WCE_PlaySound(filename, IntPtr.Zero, (int)(SendClass.Flags.SND_ASYNC | SendClass.Flags.SND_FILENAME));
        }
    }
}

3。获取 / 设置WinCE系统音量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/// <summary>
/// 获取系统音量
/// </summary>
/// <returns></returns>
public static int GetVolume()
{
   // By the default set the volume to 0
   uint CurrVol = 0;
   // At this point, CurrVol gets assigned the volume
   SendClass.Common.waveOutGetVolume(IntPtr.Zero, ref CurrVol);
   // Calculate the volume
   ushort CalcVol = (ushort)(CurrVol & 0x0000ffff);
   // Get the volume on a scale of 1 to 20 (to fit the trackbar)
   return CalcVol / (ushort.MaxValue / 20);
}
/// <summary>
/// 设置系统音量
/// </summary>
/// <param name="value">要设置的音量值</param>
public static void SetVolume(int value)
{
   int volume = CalcVolumeValue(value);
   SendClass.Common.waveOutSetVolume(IntPtr.Zero, (uint)volume);
   RegistryKey hUSER = Registry.CurrentUser.OpenSubKey(@"ControlPanel\Volume"true);
   hUSER.SetValue("Volume", volume, RegistryValueKind.DWord);
   hUSER.Flush();
   hUSER.Close();
}
private static int CalcVolumeValue(int value)
{
   // Calculate the volume that's being set
   int NewVolume = (ushort.MaxValue * value / 20);
   // Set the same volume for both the left and the right channels
   return ((NewVolume & 0x0000ffff) | (NewVolume << 16));
}

4。设定WinCE屏幕背光变暗的等待时间,以及唤醒屏幕背光

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
public enum EventFlags
{
    EVENT_PULSE = 1,
    EVENT_RESET = 2,
    EVENT_SET = 3
}
[DllImport("coredll.dll")]
public static extern IntPtr CreateEvent(IntPtr lpEventAttributes, bool bManualReset, bool bInitialState, String lpName);
[DllImport("coredll.dll")]
private static extern void EventModify(IntPtr h, int p);
[DllImport("coredll.dll")]
public static extern void CloseHandle(IntPtr h);
     
     
public static void CreateChangeEvent(String EventName, bool bInitialState)
{
    IntPtr hEvent = IntPtr.Zero;
    try
    {
        hEvent = CreateEvent(IntPtr.Zero, false, bInitialState, EventName);
        if (hEvent != IntPtr.Zero)
        {
            EventModify(hEvent, (int)EventFlags.EVENT_SET);
        }
    }
    catch { }
    finally
    {
        CloseHandle(hEvent);
    }
}
/// <summary>
/// 设定背光超时时间
/// </summary>
/// <param name="Seconds">背光超时时间(秒)</param>
/// <param name="IsAC">设定交流供电还是电池供电</param>
/// <returns></returns>
public static bool SetBackLightTimeOut(int Seconds, bool IsAC)
{
    Boolean returnvalue = false;
    try
    {
        using (RegistryKey key = Registry.CurrentUser.OpenSubKey("ControlPanel\\Backlight"true))
        {
            if (key != null)
            {
                if (IsAC)
                {
                    key.SetValue("ACTimeout", Seconds, RegistryValueKind.DWord);
                    key.SetValue("UseExt", 1, RegistryValueKind.DWord);
                }
                else
                {
                    key.SetValue("BatteryTimeout", Seconds, RegistryValueKind.DWord);
                    key.SetValue("UseBattery", 1, RegistryValueKind.DWord);
                }
                // 创建事件通知
                CreateChangeEvent("BackLightChangeEvent"true);
            }
            else
                returnvalue = false;
        }
    }
    catch
    {
        returnvalue=false;
    }          
    return returnvalue;
}
     
/// <summary>
/// 如果屏幕背光是变暗的状态,则亮起屏幕背光
/// </summary>
public static void SetBackLightOn()
{
    CreateChangeEvent("BackLightChangeEvent"false);
}

在WinCE上播放声音、设置透明图片、系统音量 C#的更多相关文章

  1. png透明图片

    2. JS处理 使用DD_belatedPNG(http://www.dillerdesign.com/experiment/DD_belatedPNG/),可以很简单的对界面上所有的透明图片进行同一 ...

  2. android设置背景图片透明

    设置Activiyt为透明可以在Activity中引用系统透明主题android:theme="@android:style/Theme.Translucent" 设置背景图片透明 ...

  3. WebView设置透明和设置背景图片的方法

    http://blog.csdn.net/Vincent20111024/article/details/8478219 1. WebView若要设置背景图,直接设置web .setBackgroun ...

  4. qt 设置背景图片

    博客出处:http://www.cppblog.com/qianqian/archive/2010/07/25/121238.htm 工作似乎走上正轨了,上周五的工作是做一个界面,用到QFrame和Q ...

  5. 多媒体开发(4):在视频上显示文字或图片--ffmpeg命令

    小白:我录了段视频,里面用的音乐是有版权的,而且快过期了,能把音乐去掉吗? 小程拿到视频后,一个快捷键打开命令终端,快速打下一行命令: ffmpeg -i 小白.flv -vcodec copy -a ...

  6. 让ie6对png透明图片支持起来

    [声明:此文仅是对低版本ie使用透明图片的一个研究,当时出于工作要求,所以花费了一番心思在兼容旧版本ie上,现在对ie8都是做降级处理了.不培养用户坏习惯.引导用户跟随潮流体验新技术应是我们前端开发者 ...

  7. .Net简单图片系统-使用说明

    使用说明 1. 从github上获取代码,并部署到IIS中,应用程序池选择4.0. 2. 打开配置文件,在AppSettings中,设置SaveMode模式,如果选择的Distributed模式,需要 ...

  8. QT:给Widget设置背景图片——设置Widget的调色板,调色板使用图片和背景色

    QT:给Widget设置背景图片 1 /*2 * set background image3 */4 QPixmap bgImages(":/images/bg.png");5 Q ...

  9. 给tableView设置背景图片

    经常遇到要给tableView设置背景图片的问题,但如果直接设置背景  backgroundView的话,背景图不会显示,原因是  tableView上的cell默认是不透明的颜色,所以解决方法是 让 ...

随机推荐

  1. springboot伪静态

    在日常网站访问中,会把动态地址改造成伪静态地址. 例如: 访问新闻栏目 /col/1/,这是原有地址,如果这样访问,不利于搜索引擎检索收录,同时安全性也不是很好. 改造之后: /col/1.html. ...

  2. java温故而知新(9)OOP(面向对象编程)理念

    Object   Oriented   Programming   (面向对象的程序设计) 1.定义 面向对象程序设计(OOP)的具体定义很难下,也很容易因此而引起争论,在   Object-Orie ...

  3. 配置Spring

    搭建Springmvc的时候,出现异常: IOException parsing XML document from ServletContext resource [/WEB-INF/applica ...

  4. Django 中间件实现用户认证与IP频率限制

    1.URL访问过滤 通过装饰器进行用户认证非常方便,但是在添加部分需要认证的功能时,就需要再次添加装饰器,如果通过中间件来实现,就不需要再进行添加的操作. import re LOGIN_URL = ...

  5. [转]纯js导出json到excel(支持chrome)

    转自:http://blog.csdn.net/educast/article/details/52775559 function JSONToExcelConvertor(JSONData, Fil ...

  6. webapi下载文件

    [HttpGet] public IHttpActionResult ExportData() { ... var dt = ExcelHelper.ListToDataTable(list); va ...

  7. npm安装指定版本

    今天犯了一个低级错误,在npm安装依赖时,命令写成下了格式 npm i --save iview 2.0.0 要安装指定版本应该使用 npm i --save iview@2.0.0 谨记

  8. js基本数据类型和引用类型的区别详解-笔记

    原文参考http://mp.weixin.qq.com/s/apFyUgqT5N-bsDUjP4Eryg 笔记总结 首先记住js中的基础数据类型undefined,null,boolean,strin ...

  9. 项目经验:GIS<MapWinGIS>建模第四天

    实现了查询,与定位功能

  10. hdu 1102 Constructing Roads (Prim算法)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1102 Constructing Roads Time Limit: 2000/1000 MS (Jav ...