(一)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打开项目后,开始一段时间生成速度还能忍受,时间一长 ...
随机推荐
- OpenCV-Python 改变颜色空间 | 十三
目标 在本教程中,你将学习如何将图像从一个色彩空间转换到另一个,像BGR↔灰色,BGR↔HSV等 除此之外,我们还将创建一个应用程序,以提取视频中的彩色对象 你将学习以下功能:cv.cvtColor, ...
- 使用DeepWalk从图中提取特征
目录 数据的图示 不同类型的基于图的特征 节点属性 局部结构特征 节点嵌入 DeepWalk简介 在Python中实施DeepWalk以查找相似的Wikipedia页面 数据的图示 当你想到" ...
- 使用PyTorch建立图像分类模型
概述 在PyTorch中构建自己的卷积神经网络(CNN)的实践教程 我们将研究一个图像分类问题--CNN的一个经典和广泛使用的应用 我们将以实用的格式介绍深度学习概念 介绍 我被神经网络的力量和能力所 ...
- Oracle12C的卸载过程
1.找到自己的Oracle12C安装目录,一般的安装目录为D:\app\u01\product\12.1.0\dbhome_1\deinstall ,双击deintall.dat文件进行卸载. 2.耐 ...
- Django安装和使用
Django安装 安装Django Python3在线安装Django pip3 install Django 验证是否安装成功,并查看当前版本 python -m django --version ...
- HashCode()与equals()深入理解
1.hashCode()和equals()方法都是Object类提供的方法, hashCode()返回该对象的哈希码值,该值通常是一个由该对象的内部地址转换而来的int型整数, Object的equa ...
- 「MoreThanJava」计算机发展史—从织布机到IBM
「MoreThanJava」 宣扬的是 「学习,不止 CODE」,本系列 Java 基础教程是自己在结合各方面的知识之后,对 Java 基础的一个总回顾,旨在 「帮助新朋友快速高质量的学习」. 当然 ...
- M - 湫湫系列故事——减肥记I
M - 湫湫系列故事--减肥记I 对于吃货来说,过年最幸福的事就是吃了,没有之一! 但是对于女生来说,卡路里(热量)是天敌啊! 资深美女湫湫深谙"胖来如山倒,胖去如抽丝"的道理,所 ...
- 从上帝视角看Java如何运行
JVM内存结构 可以看出JVM从宏观上可以分为 ‘内部’ 及 ‘外部’ 两个部分(便于记忆理解): ‘内部’包含:线程共享(公有)数据区 和 线程隔离(私有)数据区 ‘外部’包含:类加载子系统.垃 ...
- Fetch+SpringBoot跨域请求设置
两种方法从SpringBoot的方向解决跨域问题 今天搭建博客的时候,尝试性的传递数据,发现浏览器报了这个错误 -blocked by CORS policy: No 'Access-Control- ...