那位可以帮助我解释一下(100分)

陈晨

Unregistered / Unconfirmed
GUEST, unregistred user!
type
TSetLayeredWindowAttributes = function (Hwnd: THandle; crKey: COLORREF; bAlpha: Byte; dwFlags: DWORD): Boolean; stdcall;
;
;
procedure TCustomForm.SetLayeredAttribs;
const
cUseAlpha: array [Boolean] of Integer = (0, LWA_ALPHA);
cUseColorKey: array [Boolean] of Integer = (0, LWA_COLORKEY);
var
AStyle: Integer;
begin
if not (csDesigning in ComponentState) and
(Assigned(SetLayeredWindowAttributes)) and HandleAllocated then
begin
AStyle := GetWindowLong(Handle, GWL_EXSTYLE);
if FAlphaBlend or FTransparentColor then
begin
if (AStyle and WS_EX_LAYERED) = 0 then
SetWindowLong(Handle, GWL_EXSTYLE, AStyle or WS_EX_LAYERED);
SetLayeredWindowAttributes(Handle, FTransparentColorValue, FAlphaBlendValue,
cUseAlpha[FAlphaBlend] or cUseColorKey[FTransparentColor]);
end
else
begin
SetWindowLong(Handle, GWL_EXSTYLE, AStyle and not WS_EX_LAYERED);
RedrawWindow(Handle, nil, 0, RDW_ERASE or RDW_INVALIDATE or RDW_FRAME or RDW_ALLCHILDREN);
end;
end;
end;

 
设置窗体透明用的.
 
我知道,但是我对这种类型格式 没有见到过,
SetLayeredWindowAttributes(Handle, FTransparentColorValue, FAlphaBlendValue,
cUseAlpha[FAlphaBlend] or cUseColorKey[FTransparentColor]);

type
TSetLayeredWindowAttributes = function (Hwnd: THandle; crKey: COLORREF; bAlpha: Byte; dwFlags: DWORD): Boolean; stdcall

这两句让我头大了,看了一天多的资料也没有找到相关介绍的麻烦能给我介绍一下吗?

 
cUseAlpha[FAlphaBlend] 和 cUseColorKey[FTransparentColor]就是简单的数组而已.
TSetLayeredWindowAttributes = function (Hwnd: THandle; crKey: COLORREF; bAlpha: Byte; dwFlags: DWORD): Boolean; stdcall
是为了实现对SetLayeredWindowAttributes的动态调用,因为在win2k之前的操作系统中,没有
这个函数,所以静态调用可能会出错.
 
麻烦老兄详细一点。
或者可以告诉我动态调用函数那本书上有讲的好吗?

最好能再我理解范围内。谢谢了!,
因为不懂所以不知道那里不懂
 
不用看别的书,看我自己总结的就可以啦[:D]

动态调用DLL的具体步骤:
1. 声明与引入例程原型一致的过程类型
TDLLFunc = function(xxx: Txxx): Txxx; stdcall;
TDLLProc = procedure(xxx: Txxx); stdcall;
2. 声明一个THandle类型的变量,用来安全地装入和释放DLL
DLLHandle: THandle;
3. 将THandle类型的变量初始化为0
DLLHandle := 0;
4. 装入DLL,并引入所用到的例程
{ 对DLLHandle的判断,可以DLL的装入更安全可靠 }
if DLLHandle = 0 then
begin
DLLHandle := LoadLibrary('DLLFile.dll');
try
if DLLHandle = 0 then
raise Exception.Create('装入动态链接库DLLFile.dll失败!');
{ 在这里,将本次要用到的例程全部引入。对于某些必须成功装入的例程来说,如果
装入失败,则立即释放DLL }
@DLLFunc := GetProcAddress(DLLHandle, 'DLLFunc');
if @DLLFunc = nil then
Abort;
@DLLProc := GetProcAddress(DLLHandle, 'DLLProc');
if @DLLProc = nil then
Abort;
except
FreeLibrary(DLLHandle);
DLLHandle := 0;
end;
end;
5. 使用例程
DLLProc;
6. 释放DLL
{ 对DLLHandle的判断,可以安全地释放DLL }
if DLLHandle <> 0 then
begin
FreeLibrary(DLLHandle);
DLLHandle := 0;
end;
 
procedure InitProcs;
const
sUser32 = 'User32.dll';
var
ModH: HMODULE;
begin
ModH := GetModuleHandle(sUser32);
if ModH <> 0 then
@SetLayeredWindowAttributes := GetProcAddress(ModH, 'SetLayeredWindowAttributes');
end;
 
谢谢二位呵呵呵

明白了
 
接受答案
 
顶部