在WinCE上播放声音、设置透明图片、系统音量 C#
记录一下用到的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#的更多相关文章
- png透明图片
2. JS处理 使用DD_belatedPNG(http://www.dillerdesign.com/experiment/DD_belatedPNG/),可以很简单的对界面上所有的透明图片进行同一 ...
- android设置背景图片透明
设置Activiyt为透明可以在Activity中引用系统透明主题android:theme="@android:style/Theme.Translucent" 设置背景图片透明 ...
- WebView设置透明和设置背景图片的方法
http://blog.csdn.net/Vincent20111024/article/details/8478219 1. WebView若要设置背景图,直接设置web .setBackgroun ...
- qt 设置背景图片
博客出处:http://www.cppblog.com/qianqian/archive/2010/07/25/121238.htm 工作似乎走上正轨了,上周五的工作是做一个界面,用到QFrame和Q ...
- 多媒体开发(4):在视频上显示文字或图片--ffmpeg命令
小白:我录了段视频,里面用的音乐是有版权的,而且快过期了,能把音乐去掉吗? 小程拿到视频后,一个快捷键打开命令终端,快速打下一行命令: ffmpeg -i 小白.flv -vcodec copy -a ...
- 让ie6对png透明图片支持起来
[声明:此文仅是对低版本ie使用透明图片的一个研究,当时出于工作要求,所以花费了一番心思在兼容旧版本ie上,现在对ie8都是做降级处理了.不培养用户坏习惯.引导用户跟随潮流体验新技术应是我们前端开发者 ...
- .Net简单图片系统-使用说明
使用说明 1. 从github上获取代码,并部署到IIS中,应用程序池选择4.0. 2. 打开配置文件,在AppSettings中,设置SaveMode模式,如果选择的Distributed模式,需要 ...
- QT:给Widget设置背景图片——设置Widget的调色板,调色板使用图片和背景色
QT:给Widget设置背景图片 1 /*2 * set background image3 */4 QPixmap bgImages(":/images/bg.png");5 Q ...
- 给tableView设置背景图片
经常遇到要给tableView设置背景图片的问题,但如果直接设置背景 backgroundView的话,背景图不会显示,原因是 tableView上的cell默认是不透明的颜色,所以解决方法是 让 ...
随机推荐
- C10K问题摘要
本文的内容是下面几篇文章阅读后的内容摘要: http://www.kegel.com/c10k.html (英文版) http://www.oschina.net/translate/c10k (中文 ...
- struts2 执行流程及工作原理
在Struts2框架中的处理大概分为以下的步骤 1 用户发送请求: 2 这个请求经过一系列的过滤器(Filter)(这些过滤器中有一个叫做ActionContextCleanUp的可选过滤器,这个过 ...
- 关于div设置display: inline-block之后盒子之间间距的处理
当两个盒子都设置display: inline-block之后并且css也清除了默认样式 这时候会发现div盒子之间仍然存在间隙 将font-size清0间距就会取消
- 20个实用javascript技巧及实践(二)
21. 使用逻辑AND/OR来处理条件语句 var foo =10; foo ==10&& doSomething();// is the same thing as if (foo ...
- node定时任务
var schedule = require('node-schedule') require('shelljs/global'); function scheduleCronstyle(){ sch ...
- linux多线程编程——读者优先、写者优先问题
读者优先描述 如果读者来: 1) 无读者.写着,新读者可以读: 2) 无写者等待,但有其他读者正在读,新读者可以读: 3) 有写者等待,但有其他读者正在读,新读者可以读: 4) 有写者写,新读者等 如 ...
- 04_zookeeper的watcher机制
[watcher简述] * zk针对每个节点的操作,都会有一个监督者:watcher * 当监控的某个对象(znode)发生了变化,则出发watcher * zk中的watcher是一次性的,出发后立 ...
- Office - Word 2013
1. 使用 Quick Parts 向Word中添加自定义属性: 2.
- sqlserver查询当月数据
SELECT * FROM table WHERE datediff(month,LoginTime,getdate())=0 ORDER BY LoginTime SELECT * FROM tab ...
- 动态注册broadcast的安全考虑
一.android service通知activity更新方式有1. service 通过广播的形式发送broadcast,向这个activity的内部类发广播的消息来更新界面2. service直接 ...