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 半透明窗体的更多相关文章

  1. Windows Mobile X图标如何销毁窗体而非隐藏

    在Windows Mobile窗体上,有“OK”和“X”两种形式按钮.1.在Form的属性里,设置“MinimizeBox=false”,则窗体显示”OK”,点击该按钮窗体销毁并退出.2.设置“Min ...

  2. windows mobile 共享PC网络(win7)

    win7系统安装windows mobile,将设备插入底座后,设备并不能直接共享pc的网络直接上网.原来,当插入底座后,需要打开mobile设备中心,切换一下连接网络,或者打开此窗体后确定一下,即可 ...

  3. 使用Visual Studio 2008创建你的第一个Windows Mobile程序介绍

    使用Visual Studio 2008创建你的第一个Windows Mobile程序介绍 Windows MobileMobileWindowsMicrosoftWinForm 介绍 Microso ...

  4. Windows Mobile入门

    转自 http://www.cnblogs.com/peterzb/archive/2009/05/12/1455256.html [准备篇]        最近安排做手机视频监控方面开发,这个对我来 ...

  5. delphi 半透明窗体类

    {******************************************************************************* 半透明窗体控件 版本:1.0 功能说明 ...

  6. 转载扩展Windows Mobile模拟器存储空间的方法

    扩展Windows Mobile模拟器存储空间的方法 在Windows Mobile应用程序开发的初期,可以使用SDK自带的模拟器来进行调试,这给我们开发人员提供了一种方便的途径.一般的应用程序,占用 ...

  7. 解决VS2008 开发Windows Mobile 项目生成速度慢的问题(转)

    最近用VS2008开发Windows Mobile程序,使用C#..NET Compact Framework,发现项目生成速度比较慢.用VS2008打开项目后,开始一段时间生成速度还能忍受,时间一长 ...

  8. VS连接Windows Mobile模拟器

    原文:http://www.cnblogs.com/xjimmyshcn/archive/2011/07/19/2111087.html 一.WinCE 模拟器通过ActiveSync 6.1(即Wi ...

  9. 解决VS2008 开发Windows Mobile 项目生成速度慢的问题

    最近用VS2008开发Windows Mobile程序,使用C#..NET Compact Framework,发现项目生成速度比较慢.用VS2008打开项目后,开始一段时间生成速度还能忍受,时间一长 ...

随机推荐

  1. js利用cookie登录网站

    如上图,我们获取到了cookie,接下来利用cookie登录相应的网站. 我用的浏览器是火狐,首先在特定的网站(也就是我们发现XSS漏洞的网站,这里指的是pikachu)F12打开开发者工具,找到控制 ...

  2. MySql查询当天、本周、本月、本季度、本年的数据

    1.今天 SELECT * FROM 表名 WHERE TO_DAYS(时间字段名) = TO_DAYS(NOW()); 2.昨天 ; 3.本周 SELECT * FROM 表名 WHERE YEAR ...

  3. SimpleITK 和 Nibabel 读取医学图像 nii 数据(2D显示)

    SimpleITK 和 Nibabel 区别在于:(nii图像可以看成2维,也可以看成三维) SimpleITK读取数据是(X,Y,Z)显示,Nibabel读取图像是(Z,Y,X)显示,也就是Niba ...

  4. qt creator源码全方面分析(3-8)

    目录 项目文件工作流程 多层目录模式 依赖解析模式 包含,链接和输出 包含 链接 输出 构建目录架构 项目文件工作流程 我们在前面已经讨论了所有的项目文件, qtcreator.pro qtcreat ...

  5. Q - 迷宫问题 POJ - 3984(BFS / DFS + 记录路径)

    Q - 迷宫问题 POJ - 3984 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, ...

  6. linux系统部署安装过程

    1. 虚拟环境安装 1.新建虚拟机   2.虚拟机设置 2.系统历程 1.进入系统引导界面进行配置 引导项说明:            1.安装centos 系统                    ...

  7. Socket探索1-两种Socket服务端实现

    介绍 一次简单的Socket探索之旅,分别对Socket服务端的两种方式进行了测试和解析. CommonSocket 代码实现 实现一个简单的Socket服务,基本功能就是接收消息然后加上结束消息时间 ...

  8. SSM 三大框架系列:Spring 5 + Spring MVC 5 + MyBatis 3.5 整合(附源码)

    之前整理了一下新版本的 SSM 三大框架,这篇文章是关于它的整合过程和项目源码,版本号分别为:Spring 5.2.2.RELEASE.SpringMVC 5.2.2.RELEASE.MyBatis ...

  9. 2017蓝桥杯最大公共子串(C++B组)

    题目: 最大公共子串长度问题就是:求两个串的所有子串中能够匹配上的最大长度是多少.比如:"abcdkkk" 和 "baabcdadabc",可以找到的最长的公共 ...

  10. 程序员的 Ubuntu 19.10 配置与优化指南

    原文地址:程序员的 Ubuntu 19.10 配置与优化指南 0x00 环境 CPU: Intel Core i9-9900k GPU: GeForce RTX 2070 SUPER RAM: DDR ...