在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默认是不透明的颜色,所以解决方法是 让 ...
随机推荐
- Redis数据类型及常用命名总结
Redis数据类型: Redis支持五种数据类型:string(字符串),hash(哈希),list(列表),set(集合)及zset(sorted set:有序集合). 1.String(字符串) ...
- flask-login的简单实用
# encoding: utf-8 from flask import Flask, Blueprint from flask_login import (LoginManager, login_re ...
- 数组之reduce()和reduceRight()
1.reduce()和reduceRight()方法使用指定的函数将数组元素进行组合,生成单个值. reduce()可以传入两个参数,第一个是执行化简操作的函数.同样这个函数可以有参数,第一个参数代表 ...
- Unicode汉字转码小工具
点击按钮即可使用! 在这里粘贴或输入 转换结果:
- Java的Final和C#的Const,Readonly比较分析(转载)
Java里面没有readonly关键字,预留了const的关键字,目前还没有实际用途,在Java中,跟这两个关键字比较接近的是final; C#中,两者都存在并可用.两者修饰的全局变量或局部变量都不能 ...
- 轻松看懂机器学习十大常用算法 (Machine Learning Top 10 Commonly Used Algorithms)
原文出处: 不会停的蜗牛 通过本篇文章可以对ML的常用算法有个常识性的认识,没有代码,没有复杂的理论推导,就是图解一下,知道这些算法是什么,它们是怎么应用的,例子主要是分类问题. 每个算法都看了 ...
- AndroidStudio安装教程
Android studio安装与配置 1.首先下载Android studio安装包,可以从http://www.android-studio.org/ 2.下载好该安装包之后,点击进行安装,依次出 ...
- python SQLAchemy多外键关联
关联同一张表的两个字段 Customer表有2个字段都关联了Address表 创建表结构 orm_many_fk.py 只创建表结构 from sqlalchemy import Integer, F ...
- js if语句只写一个参数是什么意思?
如 var a=0:if(!a){...}; avascript中以下值会被转换为false false undefined null 0 -0 NaN ""
- char和varchar的区别
在建立数据库表结构的时候,为了给一个String类型的数据定义一个数据库的数据库类型,一般参考的都是char或者varchar,这两种选择有时候让人很纠结,今天想总结一下它们两者的区别,明确一下两者的 ...