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. Javascript之封装运动函数

    @ 目录 阶段一.仅适用单位带px属性的匀速运动 阶段二.可适用单位不带px属性(如opacity)的匀速运动 阶段三.适用于多元素单一属性的匀速运动 阶段四.适用于多元素单一属性的匀速或缓冲运动 阶 ...

  2. vue2.0开发环境下解决跨域问题

    1.找到vue 项目下的配置文件 /config/index.js 2.找到 proxyTable 配置项 proxyTable: { '/api': { target: 'http://www.xx ...

  3. Oracle12C的卸载过程

    1.找到自己的Oracle12C安装目录,一般的安装目录为D:\app\u01\product\12.1.0\dbhome_1\deinstall ,双击deintall.dat文件进行卸载. 2.耐 ...

  4. python pdb 转载:https://www.linuxidc.com/Linux/2017-11/148329.htm

    最近在为一个监控系统开发agent,需要支持Linux.FreeBSD及Windows等操作系统.复杂的线上环境,带来了一系列诡异的问题,尽管代码上线前在为数不少的测试机器验证过. Python程序吐 ...

  5. mac 中使用git 和pycharm提交项目

    一.安装Git 1.验证git是否安装: 终端中输入: git 如果安装过出现: 2.安装git: 进入https://git-scm.com: 点击 Download 2.23.0 for Mac ...

  6. Python——图像手绘效果

    1.图像的RGB色彩模式 PIL PIL, Python Image Library PIL库是一个具有强大图像处理能力的第三方库 在命令行下的安装方法: pip install pillow fro ...

  7. pycharm 秘籍:快捷键技巧等

    Pycharm基本使用 安装 下载地址:https://www.jetbrains.com/pycharm/download 选择Professional 专业版 Comunnity社区版是免费的,但 ...

  8. cxk不会二进制 (贪心)

    cxk不会二进制 Description 最近cxk迷上了二进制,他很菜,有道简单的题不会做,挂在这里求大佬做一下: 以二进制形式给出两个数字:x,y.令s = x + y * 2 ^ k.输出能使 ...

  9. 人生靠反省,Java靠泛型

    昨天有同事问 UserService.XxxService 都会调用 Dao 的 insert.update ... ...,这些重复的代码,有没有办法变得灵活一些? 巧了,和咱们分享的主题刚好碰上, ...

  10. 从 Linux 操作系统谈谈 IO 模型(终)

    Linux 为什么要区分内核空间与用户空间? Linux 操作系统的 IO 模型有哪几种?有啥区别? 常说的阻塞现象,到底是咋回事? 网络编程研发时,那块到底耗时最多,代码是否还有优化空间? 前几期的 ...