当显示对话框时,褪色应用程序的所有其他窗口? [英] Fade all other windows of an application when a dialog is shown?

查看:147
本文介绍了当显示对话框时,褪色应用程序的所有其他窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Form有一个AlphaBlend属性,但它只控制透明度级别。但是如果我们可以有这样的东西,那将是很好的
。甚至stackoverflow.com这样做,当我们尝试在帖子中插入一个链接/图像等。



我们如何在delphi应用程序中实现这一点?

解决方案

这是一个单位,我刚刚为你敲门。



要使用此单元,请在主窗体和OnModalBegin调用_GrayForms中放置一个TApplication组件,然后在OnModalEnd中调用_NormalForms方法。



这是一个非常简单的例子,可以很容易地复杂化。检查多个调用级别等....



对于诸如系统(打开,保存等)对话框,您可以在尝试中包装对话框execute方法最后阻止调用相应的函数以获得类似的反应。



本单元应该在Win2k,WinXP,Vista上工作,甚至可以在Win7上工作。



Ryan。

  unit GrayOut; 

接口

程序_GrayForms;
程序_GrayDesktop;
procedure _NormalForms;

实现

使用窗口,类,表单,Contnrs,Types,Graphics,sysutils;

var
gGrayForms:TComponentList;

程序_GrayDesktop;
var
loop:integer;
wScrnFrm:TForm;
wForm:TForm;
wPoint:TPoint;

begin
如果没有分配(gGrayForms)然后
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,0,0,0,0,SWP_NOSIZE或SWP_NOMOVE);
wForm.Visible:= true;
结束
结束
结束

程序_GrayForms;
var
loop:integer;
wScrnFrm:TForm;
wForm:TForm;
wPoint:TPoint;
wScreens:TList;

begin
如果没有分配(gGrayForms)然后
begin
gGrayForms:= TComponentList.Create;
gGrayForms.OwnsObjects = = true;

wScreens:= TList.create;
尝试
for loop:= 0到Screen.FormCount - 1 do
wScreens.Add(Screen.Forms [loop]);

for loop:= 0 to wScreens.Count - 1 do
begin
wScrnFrm:= wScreens [loop];

如果wScrnFrm.Visible然后
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,0,0,0,0,SWP_NOSIZE或SWP_NOMOVE);
wForm.Visible:= true;
结束
结束
finally
wScreens.free;
结束
结束
结束

procedure _NormalForms;
begin
FreeAndNil(gGrayForms);
结束

初始化
gGrayForms:= nil;

结束。


How to dim / fade all other windows of an application in Delphi 2009.

Form has an AlphaBlend property, but it controls only transparency level. But it would be nice if we can have something like this (Concentrated window) . Even stackoverflow.com does that, when we try to insert a link/ image etc in the post.

How can we achieve this in a delphi application?

解决方案

Here is a unit I just knocked together for you.

To use this unit drop a TApplication component on your main form and in the OnModalBegin call _GrayForms and then in the OnModalEnd call the _NormalForms method.

This is a very simple example and could be made to be more complex very easily. Checking for multiple call levels etc....

For things like system (open, save, etc) dialogs you can wrap the dialog execute method in a try...finally block calling the appropriate functions to get a similar reaction.

This unit should work on Win2k, WinXP, Vista and should even work on Win7.

Ryan.

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, 0,0,0,0, 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, 0,0,0,0, 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.

这篇关于当显示对话框时,褪色应用程序的所有其他窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆