这篇文章不是Windows Mobile的,而是Win32的。这篇文章主要介绍一下C#下如何调用Windows API函数,这里也想说一下,Windows Mobile编程不能把眼光只局限于手机,手机与PC端相结合的程序也是很有挑战力、很有市场的。所以,这也是我写这篇文章的原因之一。
做Delphi的时候,实现窗体透明很简单,因为Delphi对Windows API的封装很好。不只对API函数封装的到位,对API函数所用到的参数封装的也很好。而.net没有对API函数进行封装,对API函数的参数就更没有封装了。调用API函数只能用Invoke的方式,参数也需要我们自己进行相关定义。
DesktopWinAPI.cs类文件,Invoke了窗体透明所需要的API函数:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace DeviceAnywhereDesktop
{
class DesktopWinAPI
{
[DllImport("user32.dll")]
public extern static IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
public extern static bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
public static uint LWA_

本文详细介绍了如何在C#中调用Windows API函数来实现窗体透明效果。通过引入DesktopWinAPI.cs类,使用DllImport注解导入必要的user32.dll函数,如SetLayeredWindowAttributes和SetWindowLong,设置窗体的LWA_COLORKEY和LWA_ALPHA属性以达到透明效果。示例代码展示了在DeviceForm.cs中如何调用这些API,并在窗体加载时设置透明度。
最低0.47元/天 解锁文章
176

被折叠的 条评论
为什么被折叠?



