fadyg
asked on
grayscale MDIChild form when it becomes inactive
Hello,
I have an application with many MDIChild forms. I would like that these forms become grayscaled (a bit like XP desktop before closing Windows) when inactive. Only the active form will remain colored.
is it possible ?
I have an application with many MDIChild forms. I would like that these forms become grayscaled (a bit like XP desktop before closing Windows) when inactive. Only the active form will remain colored.
is it possible ?
procedure TForm2.FormActivate(Sender : TObject);
begin
Color := clBtnFace;
Memo1.Color := clWindow;
Memo1.Font.Color := clWindowText;
end;
procedure TForm2.FormDeactivate(Send er: TObject);
begin
Color := clInactiveBorder;
Memo1.Color := clScrollBar;
Memo1.Font.Color := clGrayText;
end;
begin
Color := clBtnFace;
Memo1.Color := clWindow;
Memo1.Font.Color := clWindowText;
end;
procedure TForm2.FormDeactivate(Send
begin
Color := clInactiveBorder;
Memo1.Color := clScrollBar;
Memo1.Font.Color := clGrayText;
end;
ASKER
This is not what I meant:
What is needed is that all the form appears in grayscale (even images on it) as if a colored photo is turned into grayscale.
What is needed is that all the form appears in grayscale (even images on it) as if a colored photo is turned into grayscale.
It could be something like this:
unit Unit1;
interface
uses
Windows, Classes, Forms, Graphics;
type
TForm1 = class(TForm)
procedure ApplicationEventsMessage(v ar Msg: tagMSG; var Handled: Boolean);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
GrayBMP : TBitmap;
implementation
{$R *.dfm}
procedure TForm1.ApplicationEventsMe ssage(var Msg: tagMSG; var Handled: Boolean);
type
TLine = array [0..32767] of TRGBTriple;
PLine = ^TLine;
var
l : PLine;
w, h : integer;
begin
if msg.message = 45057 then begin
GrayBMP := Form1.GetFormImage;
GrayBMP.PixelFormat := pf24bit;
for h := 0 to GrayBMP.Height - 1 do begin
l := GrayBMP.ScanLine[h];
for w := 0 to GrayBMP.Width - 1 do with l[w] do begin
rgbtRed := (rgbtRed + rgbtGreen + rgbtBlue) div 3;
rgbtGreen := rgbtRed;
rgbtBlue := rgbtRed;
end;
end;
msg.message := 15;
end else if msg.message = 45056 then Form1.Refresh;
if (Msg.message = 15) and not Form1.Active then Canvas.Draw(0,0,GrayBMP);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := ApplicationEventsMessage;
end;
unit Unit1;
interface
uses
Windows, Classes, Forms, Graphics;
type
TForm1 = class(TForm)
procedure ApplicationEventsMessage(v
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
GrayBMP : TBitmap;
implementation
{$R *.dfm}
procedure TForm1.ApplicationEventsMe
type
TLine = array [0..32767] of TRGBTriple;
PLine = ^TLine;
var
l : PLine;
w, h : integer;
begin
if msg.message = 45057 then begin
GrayBMP := Form1.GetFormImage;
GrayBMP.PixelFormat := pf24bit;
for h := 0 to GrayBMP.Height - 1 do begin
l := GrayBMP.ScanLine[h];
for w := 0 to GrayBMP.Width - 1 do with l[w] do begin
rgbtRed := (rgbtRed + rgbtGreen + rgbtBlue) div 3;
rgbtGreen := rgbtRed;
rgbtBlue := rgbtRed;
end;
end;
msg.message := 15;
end else if msg.message = 45056 then Form1.Refresh;
if (Msg.message = 15) and not Form1.Active then Canvas.Draw(0,0,GrayBMP);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := ApplicationEventsMessage;
end;
unit Unit_Child;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
const
First_Child = 1;
Last_Child = 8;
type
TPaintMode = (pmColorful, pmGrayScale);
TForm2 = class(TForm)
Memo1: TMemo;
Image1: TImage;
procedure FormActivate(Sender: TObject);
procedure FormDeactivate(Sender: TObject);
procedure FormPaint(Sender: TObject);
private { Private declarations }
PaintMode:TPaintMode;
public { Public declarations }
end;
var
Form_2_arr: array[First_Child..Last_Ch ild] of TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormActivate(Sender : TObject);
var
I: Integer;
begin
PaintMode := pmColorful;
with Parent do
for I := MDIChildCount-1 downto 0 do
MDIChildren[I].Repaint;
for I := 0 to ComponentCount-1 do
if (Components[I] is TWinControl) then
(Components[I] as TWinControl).Repaint;
Repaint;
end;
procedure TForm2.FormDeactivate(Send er: TObject);
var
I: Integer;
begin
PaintMode := pmGrayScale;
with Parent do
for I := MDIChildCount-1 downto 0 do
MDIChildren[I].Repaint;
Repaint;
end;
procedure TForm2.FormPaint(Sender: TObject);
var
FmDc: HDC;
begin
if (PaintMode=pmGrayScale) then
begin
FmDc := GetWindowDC(Self.Handle);
SelectObject(FmDc, GetStockObject(GRAY_BRUSH) );
PatBlt(FmDc, 0, 0, Width,Height,$A000C9);
ReleaseDC(Self.Handle, FmDc);
end;
end;
var
I: Integer;
initialization
for I := First_Child to Last_Child do
Form_2_arr[I] := nil;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
const
First_Child = 1;
Last_Child = 8;
type
TPaintMode = (pmColorful, pmGrayScale);
TForm2 = class(TForm)
Memo1: TMemo;
Image1: TImage;
procedure FormActivate(Sender: TObject);
procedure FormDeactivate(Sender: TObject);
procedure FormPaint(Sender: TObject);
private { Private declarations }
PaintMode:TPaintMode;
public { Public declarations }
end;
var
Form_2_arr: array[First_Child..Last_Ch
implementation
{$R *.dfm}
procedure TForm2.FormActivate(Sender
var
I: Integer;
begin
PaintMode := pmColorful;
with Parent do
for I := MDIChildCount-1 downto 0 do
MDIChildren[I].Repaint;
for I := 0 to ComponentCount-1 do
if (Components[I] is TWinControl) then
(Components[I] as TWinControl).Repaint;
Repaint;
end;
procedure TForm2.FormDeactivate(Send
var
I: Integer;
begin
PaintMode := pmGrayScale;
with Parent do
for I := MDIChildCount-1 downto 0 do
MDIChildren[I].Repaint;
Repaint;
end;
procedure TForm2.FormPaint(Sender: TObject);
var
FmDc: HDC;
begin
if (PaintMode=pmGrayScale) then
begin
FmDc := GetWindowDC(Self.Handle);
SelectObject(FmDc, GetStockObject(GRAY_BRUSH)
PatBlt(FmDc, 0, 0, Width,Height,$A000C9);
ReleaseDC(Self.Handle, FmDc);
end;
end;
var
I: Integer;
initialization
for I := First_Child to Last_Child do
Form_2_arr[I] := nil;
end.
ASKER
The solution of esoftbg darkens the form but does not convert it to grayscale
The solution of ZhaawZ seems to be a good one BUT: the controls are being re-drawn over their grayscale image, thus effect is lost. The only way I could decide it was the beginning of good solution is by changing the Canvas.Draw(0,0,GrayBMP) to Canvas.Draw(10,10,GrayBMP) (i.e shifted) and see that controls are being painted in grayscale, but then overriden by the redraw of real controls themselves.
so ZhaawZ, any solution for that ?
The solution of ZhaawZ seems to be a good one BUT: the controls are being re-drawn over their grayscale image, thus effect is lost. The only way I could decide it was the beginning of good solution is by changing the Canvas.Draw(0,0,GrayBMP) to Canvas.Draw(10,10,GrayBMP)
so ZhaawZ, any solution for that ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This should do... thanks
I will accept this as a good answer
I will accept this as a good answer
ooops,
i am late
i am late
procedure TForm2.FormActivate(Sender
begin
Color := clBtnFace;
end;
procedure TForm2.FormDeactivate(Send
begin
Color := clInactiveBorder
end;
emil