VC语言

本类阅读TOP10

·VC++ 学习笔记(二)
·用Visual C++打造IE浏览器(1)
·每个开发人员现在应该下载的十种必备工具
·教你用VC6做QQ对对碰外挂程序
·Netmsg 局域网聊天程序
·Windows消息大全
·VC++下使用ADO编写数据库程序
·VC++学习笔记(四)
·非法探取密码的原理及其防范
·怎样在VC++中访问、修改注册表

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
在Win2k下实现半透明窗口的两个步骤(修补稿1.2)

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

 

现在有不少软件都采用了透明的窗口作为界面,如何在你的程序中实现呢?我发现在Win2k中提供了这种支持,只要简单的几行代码就可实现。(本例子目前只适用于Win2k )

拿一个对话框为例:

第一步 定义功能

typedef BOOL (FAR PASCAL * FUNC1)(
  HWND hwnd,           // handle to the layered window
  COLORREF crKey,      // specifies the color key
  BYTE bAlpha,         // value for the blend function
  DWORD dwFlags        // action
);

第二步 实现代码

在OnInitDialog中加入下列代码

.....
 HMODULE hModule = GetModuleHandle("user32.dll");
 FUNC1 SetLayeredWindowAttributes;
 SetLayeredWindowAttributes =  (FUNC1) GetProcAddress (hModule, _T( "SetLayeredWindowAttributes" ) );

 // 设置分层扩展标记
 SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE) | 0x80000L);
 // 70% alpha
 SetLayeredWindowAttributes(GetSafeHwnd(), 0, (255 * 70) / 100, 0x2);

工作完成,怎么样,现在你可以运行你的程序来查看效果,即使背景变化也能立刻反映到你的窗口当中,这一点比金山词霸的效果要好。

 

看到下面这段文章的人有福了,这是新加入的:

第三步:如何除去透明选项?

 // 除去分层扩展标记
SetWindowLong(GetSafeHwnd(),, GWL_EXSTYLE,
        GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE) & ~ 0x80000L);
 // 重画窗口
RedrawWindow();

第四部:VB的透明窗口(摘自MSDN)

Private Declare Function GetWindowLong Lib "user32" Alias _
  "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias _
  "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
  ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" _
  (ByVal hwnd As Long, ByVal crey As Byte, ByVal bAlpha As Byte, _
  ByVal dwFlags As Long) As Long

Private Const GWL_EXSTYLE = (-20)
Private Const WS_EX_LAYERED = &H80000
Private Const WS_EX_TRANSPARENT = &H20&
Private Const LWA_ALPHA = &H2&

Option Explicit

Private Sub Form_Load()
    Dim lOldStyle As Long
    Dim bTrans As Byte ' The level of transparency (0 - 255)

    bTrans = 128
    lOldStyle = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
    SetWindowLong Me.hWnd, GWL_EXSTYLE, lOldStyle Or WS_EX_LAYERED
     SetLayeredWindowAttributes Me.hWnd, 0, bTrans, LWA_ALPHA
End Sub

总算完整了一点。多谢观看。




相关文章

相关软件