Vc7+WindowsXP+透明窗口问题????

ztuan 2002-04-01 09:19:29
我在Vc7+WindowsXP环境下做一个基于
SDK的程序想使用透明窗口
加入如下代码:

...

SetWindowLong(hwnd, GWL_EXSTYLE,
GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED);
RedrawWindow(hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME |
RDW_ALLCHILDREN);

...
但编译通不过: 'WS_EX_LAYERED' : undeclared identifier
而 WS_EX_LAYERED 是在Winuser.h中定义的,
我看了一下,是一个有条件的宏定义:

...
#if(_WIN32_WINNT >= 0x0500)
#define WS_EX_LAYERED 0x00080000

#endif /* _WIN32_WINNT >= 0x0500 */
...

谁能帮我解释一下是怎么回事,应该如何使用 Layered Windows 接口?
还有:_WIN32_WINNT 代表什么?
...全文
335 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ztuan 2002-04-01
  • 打赏
  • 举报
回复
Thank you all very much!!!
anywn_cwh 2002-04-01
  • 打赏
  • 举报
回复
0x0500是win2k的版本号?
5.1是XP的。
anywn_cwh 2002-04-01
  • 打赏
  • 举报
回复
This article shows how you can make your apps transparent using the new functions provided with Win2K. If you download the Platform SDK from Microsoft then these functions will be available, but those of you without fast Internet connections this article could be useful.

This is a mix of stuff I found on the net so if anyone feels that I have stolen something and should get the credit, sorry...

The functions you want are included in the USER32.DLL in Win2K, but the SDK provides the header files and the source code in libraries. But to use the functions one could just import the functions from the USER32.DLL. So here it goes...

First some constants must be declared:

#ifndef WS_EX_LAYERED
#define WS_EX_LAYERED 0x00080000
#define LWA_COLORKEY 0x00000001
#define LWA_ALPHA 0x00000002
#endif // ndef WS_EX_LAYERED

Then some declarations in the header-file:

// Preparation for the function we want to import from USER32.DLL
typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);

lpfnSetLayeredWindowAttributes m_pSetLayeredWindowAttributes

That is all for the header file, now to the implementation!

// Here we import the function from USER32.DLL
HMODULE hUser32 = GetModuleHandle(_T("USER32.DLL"));
m_pSetLayeredWindowAttributes = (lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32, "SetLayeredWindowAttributes");

// If the import did not succeed, make sure your app can handle it!
if (NULL == m_pSetLayeredWindowAttributes)
return FALSE; //Bail out!!!

If the function was imported correctly we must set the dialog we want to make transparent into "transparent-mode". E.G. Set the style for the dialog so that it can be transparent, and that is done with the flag WS_EX_LAYERED defined earlier.

// Check the current state of the dialog, and then add the WS_EX_LAYERED attribute
SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);


Now when that is done its time to describe the function we imported, and to tell you the truth I'm not 100% sure about all of the parameters...

hwnd [in] Handle to the layered window.

crKey [in] Pointer to a COLORREF value that specifies the transparency color key to be used. (When making a certain color transparent...)

bAlpha [in] Alpha value used to describe the opacity of the layered window. 0 = Invisible, 255 = Fully visible

dwFlags [in] Specifies an action to take. This parameter can be LWA_COLORKEY (When making a certain color transparent...) or LWA_ALPHA.

// Sets the window to 70% visibility.
m_pSetLayeredWindowAttributes(m_hWnd, 0, (255 / 70) * 100, LWA_ALPHA);

One thing you must make sure of is to disable this function if the app is running under any OS other then Win2K. And there is probably some very easy way to do that, but here is how I did it:

OSVERSIONINFO os = { sizeof(os) };
GetVersionEx(&os);
// use m_bWin2k before any call to the m_pSetLayeredWindowAttributes to make sure we are runninng Win2K
BOOL m_bWin2K = ( VER_PLATFORM_WIN32_NT == os.dwPlatformId && os.dwMajorVersion >= 5 );

That's about it!
Flysnow 2002-04-01
  • 打赏
  • 举报
回复
_WIN32_WINNT 应该代表版本号,不是默认的也是0x0400吧

去年装了VC7,用过一段,还可以,一直没用了,XP也没装,所以没机会试

听一会儿课来
Flysnow 2002-04-01
  • 打赏
  • 举报
回复
应该和特效窗口一样,需要在StdAfx.h加一句话的

其实好像就应该是这句
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500 /* version 5.0 */
#endif /* !_WIN32_WINNT */

加上就可以了,我是根据6.0改的,应该不会有错的

16,550

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧