(一)C# Windows Mobile 半透明窗体
Windows Mobile,个人心中臻至完美的系统。
不忍自己对WM的钻研成果消逝,故留作纪念。
系列开篇,便是一个曾令自己困扰很久的问题:如何实现半透明窗体。
如果了解Win32编程,其实很简单。
主要用到了三个方法:
SetLayeredWindowAttributes
GetWindowLong
SetWindowLong
核心代码:
private void SetWindowTransparent(byte bAlpha)
{
SetWindowLong(this.Handle, (int)WindowStyle.GWL_EXSTYLE,
GetWindowLong(this.Handle, (int)WindowStyle.GWL_EXSTYLE) | (uint)ExWindowStyle.WS_EX_LAYERED); SetLayeredWindowAttributes(this.Handle, , bAlpha, LWA_ALPHA);
}
效果:
完整代码:
using System; using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; namespace Demo01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} [DllImport("coredll.dll")]
public extern static IntPtr GetDesktopWindow(); [DllImport("coredll.dll")]
public extern static bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
public static uint LWA_COLORKEY = 0x00000001;
public static uint LWA_ALPHA = 0x00000002; [DllImport("coredll.dll")]
public extern static uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong);
[DllImport("coredll.dll")]
public extern static uint GetWindowLong(IntPtr hwnd, int nIndex); public enum WindowStyle : int
{
GWL_EXSTYLE = -
} public enum ExWindowStyle : uint
{
WS_EX_LAYERED = 0x00080000
} private void SetWindowTransparent(byte bAlpha)
{
try
{
SetWindowLong(this.Handle, (int)WindowStyle.GWL_EXSTYLE,
GetWindowLong(this.Handle, (int)WindowStyle.GWL_EXSTYLE) | (uint)ExWindowStyle.WS_EX_LAYERED); SetLayeredWindowAttributes(this.Handle, , bAlpha, LWA_ALPHA); }
catch
{
}
} private void button1_Click(object sender, EventArgs e)
{
this.Close();
} private void trackBar1_ValueChanged(object sender, EventArgs e)
{
label1.Text = "透明度(0~255): " + trackBar1.Value.ToString();
SetWindowTransparent(Convert.ToByte(trackBar1.Value));
} private void Form1_Load(object sender, EventArgs e)
{
Rectangle rf = Screen.PrimaryScreen.WorkingArea; this.Location = new Point((rf.Width - this.Width) / , (rf.Height - this.Height) / ); //SetWindowTransparent(136);
}
}
}
全部代码
工程文件:
https://files.cnblogs.com/files/lesliexin/01.%E5%8D%8A%E9%80%8F%E6%98%8E%E7%AA%97%E4%BD%93.7z
(一)C# Windows Mobile 半透明窗体的更多相关文章
- Windows Mobile X图标如何销毁窗体而非隐藏
在Windows Mobile窗体上,有“OK”和“X”两种形式按钮.1.在Form的属性里,设置“MinimizeBox=false”,则窗体显示”OK”,点击该按钮窗体销毁并退出.2.设置“Min ...
- windows mobile 共享PC网络(win7)
win7系统安装windows mobile,将设备插入底座后,设备并不能直接共享pc的网络直接上网.原来,当插入底座后,需要打开mobile设备中心,切换一下连接网络,或者打开此窗体后确定一下,即可 ...
- 使用Visual Studio 2008创建你的第一个Windows Mobile程序介绍
使用Visual Studio 2008创建你的第一个Windows Mobile程序介绍 Windows MobileMobileWindowsMicrosoftWinForm 介绍 Microso ...
- Windows Mobile入门
转自 http://www.cnblogs.com/peterzb/archive/2009/05/12/1455256.html [准备篇] 最近安排做手机视频监控方面开发,这个对我来 ...
- delphi 半透明窗体类
{******************************************************************************* 半透明窗体控件 版本:1.0 功能说明 ...
- 转载扩展Windows Mobile模拟器存储空间的方法
扩展Windows Mobile模拟器存储空间的方法 在Windows Mobile应用程序开发的初期,可以使用SDK自带的模拟器来进行调试,这给我们开发人员提供了一种方便的途径.一般的应用程序,占用 ...
- 解决VS2008 开发Windows Mobile 项目生成速度慢的问题(转)
最近用VS2008开发Windows Mobile程序,使用C#..NET Compact Framework,发现项目生成速度比较慢.用VS2008打开项目后,开始一段时间生成速度还能忍受,时间一长 ...
- VS连接Windows Mobile模拟器
原文:http://www.cnblogs.com/xjimmyshcn/archive/2011/07/19/2111087.html 一.WinCE 模拟器通过ActiveSync 6.1(即Wi ...
- 解决VS2008 开发Windows Mobile 项目生成速度慢的问题
最近用VS2008开发Windows Mobile程序,使用C#..NET Compact Framework,发现项目生成速度比较慢.用VS2008打开项目后,开始一段时间生成速度还能忍受,时间一长 ...
随机推荐
- Leetcode_474. 一和零(二维01背包)
每个字符串看成一个物品,两个属性是0和1的个数,转换为01背包. code class Solution { public: int w[605][2]; int dp[105][105]; int ...
- 「面试指南」JS数组Array常用算法,Array算法的一般解答思路
先看一道面试题 在 LeetCode 中有这么一道简单的数组算法题: // 给定一个整数数组 nums 和一个目标值 target, // 请你在该数组中找出和为目标值的那两个整数,并返回他们的数组下 ...
- element-ui 的 单选按钮(Radio) 怎么取消文本显示?
方法一:<el-radio class="radio" v-model="radio" :label="1"> </el- ...
- 干货 | Python进阶系列之学习笔记(四)
目录 Python条件判断 Python循环语句 Python循环控制 迭代器与生成器 异常 一.Python 条件判断 如果某些条件满足,才能做某件事情:条件不满足时,则不能做,这就是所谓的判断. ...
- ES6语法:函数新特性(一)
ES6 函数 引言: 函数在任何语言中偶读很重要,java里面的函数通常叫做方法,其实是一个东西,使用函数可以简化更多的代码,代码结构看着更加清晰.今天我们来学学ES6语法中,函数有什么变化. 虽然现 ...
- RabbitMQ 交换机类型
1,扇形交换机 fanout 2, 直连交换机 direct 3, 通配符交换机 topic
- iOS 架构
一.MVC MVC 全名 Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一种业务逻辑.数据.界面显示分离 ...
- iOS UmbrellaHeader
Lexical or Preprocessor Issue - Umbrella header for module 'xxx' does not include header 'xxx.h' fra ...
- 模块 subprocess 交互shell
subprocess 交互shell 执行shell命令, 与操作系统交互 三种执行命令的方法 subprocess.run(*popenargs, input=None, timeout=None, ...
- USCOSII
一.要求 下载附件,尝试在vc6.0中编译运行ucos 下载附件,尝试在vs2017中编译运行ucos,给出你遇到的问题和解决方式 ucos是如何分层的? HAL都有哪些代码? 分析任务是如何切换的? ...