如何在Delphi 2009中淡化/淡化应用程序的所有其他窗口.
表单具有AlphaBlend属性,但它仅控制透明度级别.但是如果我们可以有这样的话,这将是很好的
(Concentrated window).甚至stackoverflow.com这样做,当我们尝试插入一个链接/图像等在帖子中.
我们如何在delphi应用程序中实现这一点?
解决方法
这是我刚刚为你敲门的单位.
要使用此单元,在主窗体和OnModalBegin调用_GrayForms中放置一个TApplication组件,然后在OnMoDalend中调用_normalForms方法.
这是一个非常简单的例子,可以很容易地复杂化.检查多个通话级别等….
对于诸如系统(打开,保存等)对话框,您可以在try …中封装对话框execute方法,最后阻止调用相应的函数以获得类似的反应.
该单元应该在Win2k,WinXP,Vista上工作,甚至可以在Win7上工作.
瑞安.
unit GrayOut;
interface
procedure _GrayForms;
procedure _GrayDesktop;
procedure _normalForms;
implementation
uses windows,classes,forms,Contnrs,Types,Graphics,sysutils;
var
gGrayForms : TComponentList;
procedure _GrayDesktop;
var
loop : integer;
wScrnFrm : TForm;
wForm : TForm;
wPoint : TPoint;
begin
if not assigned(gGrayForms) then
begin
gGrayForms := TComponentList.Create;
gGrayForms.OwnsObjects := true;
for loop := 0 to Screen.MonitorCount - 1 do
begin
wForm := TForm.Create(nil);
gGrayForms.Add(wForm);
wForm.Position := podesigned;
wForm.AlphaBlend := true;
wForm.AlphaBlendValue := 64;
wForm.Color := clBlack;
wForm.BorderStyle := bsNone;
wForm.Enabled := false;
wForm.BoundsRect := Screen.Monitors[loop].BoundsRect;
SetwindowPos(wForm.handle,HWND_TOP,SWP_NOSIZE or SWP_NOMOVE);
wForm.Visible := true;
end;
end;
end;
procedure _GrayForms;
var
loop : integer;
wScrnFrm : TForm;
wForm : TForm;
wPoint : TPoint;
wScreens : TList;
begin
if not assigned(gGrayForms) then
begin
gGrayForms := TComponentList.Create;
gGrayForms.OwnsObjects := true;
wScreens := TList.create;
try
for loop := 0 to Screen.FormCount - 1 do
wScreens.Add(Screen.Forms[loop]);
for loop := 0 to wScreens.Count - 1 do
begin
wScrnFrm := wScreens[loop];
if wScrnFrm.Visible then
begin
wForm := TForm.Create(wScrnFrm);
gGrayForms.Add(wForm);
wForm.Position := poOwnerFormCenter;
wForm.AlphaBlend := true;
wForm.AlphaBlendValue := 64;
wForm.Color := clBlack;
wForm.BorderStyle := bsNone;
wForm.Enabled := false;
wForm.BoundsRect := wScrnFrm.BoundsRect;
SetwindowLong(wForm.Handle,GWL_HWNDPARENT,wScrnFrm.Handle);
SetwindowPos(wForm.handle,wScrnFrm.handle,SWP_NOSIZE or SWP_NOMOVE);
wForm.Visible := true;
end;
end;
finally
wScreens.free;
end;
end;
end;
procedure _normalForms;
begin
FreeAndNil(gGrayForms);
end;
initialization
gGrayForms := nil;
end.