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


最新文章

  1. Windows下快速安装Flask的一次经历
  2. Win10 QQ五笔默认中文,InputMode默认中文
  3. hduacm 3183 rmq
  4. PHP图像处理之在原图像处理
  5. [leetcode]_Palindrome Number
  6. fineuploader 上传jquery 控件
  7. vim配置-程序员【转】
  8. ASP.NET中使用Server.Transfer()方法在页间传值 实例
  9. TypeScript02 方法特性【参数种类、参数个数】、generate方法、析构表达式、箭头表达式、循环
  10. CentOS下将php和mysql命令加入到环境变量中的几种方法
  11. 使用 Java8 Optional 的正确姿势(转)
  12. Go Deeper HDU - 3715(2 - sat 水题 妈的 智障)
  13. maven 中的mirror详解
  14. 20155332 2016-2017-2 《Java程序设计》第9周学习总结
  15. input标签(按钮)
  16. java struts2入门学习---国际化
  17. C++中的#和##运算符
  18. Burp Suite pro 抓包工具配置
  19. [转载] MFC绘制动态曲线,用双缓冲绘图技术防闪烁
  20. LockSupport HotSpot里park/unpark的实现

热门文章

  1. Magento2(麦进斗) docker 安装
  2. Docker镜像拉取慢的解决方法
  3. shell脚本基础知识以及变量
  4. layer弹层插件
  5. 使用PyTorch进行情侣幸福度测试指南
  6. Activiti7流程定义
  7. 在Ngnix中配置支持Websocket
  8. MySql查询当天、本周、本月、本季度、本年的数据
  9. js 调用铃声
  10. 软件——Hexo-NexT配置个人博客