Bonjour,
Quelqu'un à déjà essayer de griser les fenêtres en arrière plan ? J'aimerai assombrir les fenêtres qui sont en arrière plan afin de ne pas surcharger mon application avec des fenêtres superposé.
Merchiche![]()
Bonjour,
Quelqu'un à déjà essayer de griser les fenêtres en arrière plan ? J'aimerai assombrir les fenêtres qui sont en arrière plan afin de ne pas surcharger mon application avec des fenêtres superposé.
Merchiche![]()
Salut,
J'avais prévu de faire paraitre sur les sources de developpez.com une unité avec des fonctions qui permettent justement de griser une fenêtre. Je profite donc de ce message pour diffuser les sources ici, et je pense qu'il serait bien que les modos diffuse ça dans la partie sources Delphi du site.
J'en profite également pour remerciersub0 qui m'a permis grace à ces différentes réponses dans des posts à m'aider a réaliser cette fonction (Rendont à césar ce qui est à césar, une grande partie du mérite de cette fonction lui revient
).
voici donc le source de l'unité :
en fait, au lieu d'appeller un showmodal d'une autre fenêtre il suffit d'appeller la fonction CustomShowModal en lui passant en paramètre la fenêtre que vous souhaitez afficher en showmodal. Et automatiquement la fonction grisera la fenêtre active (Donc celle qui appelle le showmodal) et affichera l'autre fenêtre. il est clair qu'en terme d'ergonomie c'est bien plus pratique pour l'utilisateur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134 {*------------------------------------------------------------------------------ Unité permettant de griser une form lorsqu'elle appelle un showmodal pour en afficher une autre @Author tiki06 @Version 02-août-2006 Version initiale -------------------------------------------------------------------------------} Unit UGriserForm; Interface Uses Windows, Forms, Types, Graphics; const PIXELCOUNTMAX = 32768; WS_EX_LAYERED = $80000; type pRGBArray = ^TRGBArray; TRGBArray = ARRAY[0..PIXELCOUNTMAX-1] OF TRGBTriple; Procedure FusionerImage(FusionForm: TForm; BmpGrise: TBitmap); Function CustomShowModal(Fenetre: TForm):integer; implementation {*------------------------------------------------------------------------------ Fonction pour fusioner la form et l'image grisé @param FusionForm Form a fusioner @param BmpGrise Bitmap de l'image grisé -------------------------------------------------------------------------------} Procedure FusionerImage(FusionForm: TForm; BmpGrise: TBitmap); Var Size : PSIZE; TopLeft, BmpTopLeft : TPoint; Blend : TBlendFunction; Begin With FusionForm Do Begin SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) Or WS_EX_LAYERED); New(Size); Size.cx := Width; Size.cy := Height; TopLeft := BoundsRect.TopLeft; BmpTopLeft := Point(0, 0); With Blend Do Begin BlendOp := 0; BlendFlags := 0; SourceConstantAlpha := 255; AlphaFormat := 0; End; BmpGrise.PixelFormat := pf32bit; UpdateLayeredWindow(Handle, GetDC(0), @TopLeft, Size, BmpGrise.Canvas.handle, @BmpTopLeft, 0, @Blend, 2); End; End; {*---------------------------------------------------------------------------- Fonction pour afficher une fenêtre en showmodal et griser celle qui est active pendant l'appel du showmodal @param Fenetre Form a afficher en Showmodal -----------------------------------------------------------------------------} Function CustomShowModal(Fenetre: TForm):integer; var WindowHandle : THandle; deviceContext : HDC; BitmapForm : Tbitmap; icolor : integer; r,g,b:byte; iheight,iwidth : integer; RowOriginal : pRGBArray; FormGrise : TForm; begin WindowHandle:= Screen.ActiveForm.Handle; deviceContext:= GetWindowDC(WindowHandle); try BitmapForm := Tbitmap.Create; BitmapForm.PixelFormat := pf24bit; BitmapForm.Width := Screen.ActiveForm.Width; BitmapForm.Height := Screen.ActiveForm.Height; BitBlt(BitmapForm.Canvas.Handle, 0, 0, BitmapForm.Width, BitmapForm.Height, deviceContext, 0, 0, SRCCOPY); finally ReleaseDC(WindowHandle, deviceContext); end; for iHeight := 0 to BitmapForm.height-1 do begin RowOriginal := pRGBArray(BitmapForm.Scanline[iHeight]); for iWidth := 0 to BitmapForm.width-1 do begin r:=RowOriginal[iWidth].rgbtRed; g:=RowOriginal[iWidth].rgbtGreen; b:=RowOriginal[iWidth].rgbtBlue; icolor:=(r+g+b) div 3; RowOriginal[iWidth].rgbtRed := icolor; RowOriginal[iWidth].rgbtGreen := icolor; RowOriginal[iWidth].rgbtBlue := icolor; end; end; FormGrise := Tform.Create(Screen.ActiveForm); FormGrise.Name := 'GrayscaleForm'; FormGrise.Left := Screen.ActiveForm.Left; FormGrise.Top := Screen.ActiveForm.Top; FormGrise.Width := Screen.ActiveForm.Width; FormGrise.Height := Screen.ActiveForm.Height; FormGrise.DoubleBuffered := True; FormGrise.BorderIcons := Screen.ActiveForm.BorderIcons; FormGrise.BorderStyle := Screen.ActiveForm.BorderStyle; FormGrise.Show; FusionerImage(FormGrise,BitmapForm); FormGrise.BringToFront; BitmapForm.Free; Result:=Fenetre.ShowModal; if FormGrise<>nil then FormGrise.Release; end; End.
Si vous avez des questions n'hésitez pas.
Chouette, j'ai bien fait de poser la question dans le forum DELPHI. Le petit hic, est que je développe en C++ Builder, et je n'ai jamais fait de pascal. Bon, je vais essayer de transposer tout ça. Quand c'est oki, je fais signe, et je diffuserai le source sur le forum de c++ sans oublier les remerciments à césar...
je suis impatient de tester tout ça.
... Ca ne va pas être facile..........![]()
Alors pourquoi poster sur le forum DelphiEnvoyé par kurkaine
![]()
Modérateur Delphi
Le guide du bon forumeur :
- Les règles du forum tu liras
- La FAQ et les tutoriels tu consulteras
- La fonction Recherche tu utiliseras
- Google tu vénèreras
__________
Rayek World : Youtube Facebook
j'ai bien tester ton code sa marche tres bien j uste que y a le caption de la form en arriere plan qui change le temps d'une fraction de second (assez long pour etre remarquer essai de voir si en peut pas améliorer sa)
j'ai fait une petit modification.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134 {*------------------------------------------------------------------------------ Unité permettant de griser une form lorsqu'elle appelle un showmodal pour en afficher une autre @Author tiki06 @Version 02-août-2006 Version initiale -------------------------------------------------------------------------------} Unit UGriserForm; Interface Uses Windows, Forms, Types, Graphics; const PIXELCOUNTMAX = 32768; WS_EX_LAYERED = $80000; type pRGBArray = ^TRGBArray; TRGBArray = ARRAY[0..PIXELCOUNTMAX-1] OF TRGBTriple; Procedure FusionerImage(FusionForm: TForm; BmpGrise: TBitmap); Function CustomShowModal(Fenetre: TForm):integer; implementation {*------------------------------------------------------------------------------ Fonction pour fusioner la form et l'image grisé @param FusionForm Form a fusioner @param BmpGrise Bitmap de l'image grisé -------------------------------------------------------------------------------} Procedure FusionerImage(FusionForm: TForm; BmpGrise: TBitmap); Var Size : PSIZE; TopLeft, BmpTopLeft : TPoint; Blend : TBlendFunction; Begin With FusionForm Do Begin SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) Or WS_EX_LAYERED); New(Size); Size.cx := Width; Size.cy := Height; TopLeft := BoundsRect.TopLeft; BmpTopLeft := Point(0, 0); With Blend Do Begin BlendOp := 0; BlendFlags := 0; SourceConstantAlpha := 255; AlphaFormat := 0; End; BmpGrise.PixelFormat := pf32bit; UpdateLayeredWindow(Handle, GetDC(0), @TopLeft, Size, BmpGrise.Canvas.handle, @BmpTopLeft, 0, @Blend, 2); End; End; {*---------------------------------------------------------------------------- Fonction pour afficher une fenêtre en showmodal et griser celle qui est active pendant l'appel du showmodal @param Fenetre Form a afficher en Showmodal -----------------------------------------------------------------------------} Function CustomShowModal(Fenetre: TForm):integer; var WindowHandle : THandle; deviceContext : HDC; BitmapForm : Tbitmap; icolor : integer; r,g,b:byte; iheight,iwidth : integer; RowOriginal : pRGBArray; FormGrise : TForm; begin WindowHandle:= Screen.ActiveForm.Handle; deviceContext:= GetWindowDC(WindowHandle); try BitmapForm := Tbitmap.Create; BitmapForm.PixelFormat := pf24bit; BitmapForm.Width := Screen.ActiveForm.Width; BitmapForm.Height := Screen.ActiveForm.Height; BitBlt(BitmapForm.Canvas.Handle, 0, 0, BitmapForm.Width, BitmapForm.Height, deviceContext, 0, 0, SRCCOPY); finally ReleaseDC(WindowHandle, deviceContext); end; for iHeight := 0 to BitmapForm.height-1 do begin RowOriginal := pRGBArray(BitmapForm.Scanline[iHeight]); for iWidth := 0 to BitmapForm.width-1 do begin r:=RowOriginal[iWidth].rgbtRed; g:=RowOriginal[iWidth].rgbtGreen; b:=RowOriginal[iWidth].rgbtBlue; icolor:=(r+g+b) div 3; RowOriginal[iWidth].rgbtRed := icolor; RowOriginal[iWidth].rgbtGreen := icolor; RowOriginal[iWidth].rgbtBlue := icolor; end; end; FormGrise := Tform.Create(Screen.ActiveForm); FormGrise.Name := Screen.ActiveForm.Caption; <- j'ai rajouter sa ********** FormGrise.Left := Screen.ActiveForm.Left; FormGrise.Top := Screen.ActiveForm.Top; FormGrise.Width := Screen.ActiveForm.Width; FormGrise.Height := Screen.ActiveForm.Height; FormGrise.DoubleBuffered := True; FormGrise.BorderIcons := Screen.ActiveForm.BorderIcons; FormGrise.BorderStyle := Screen.ActiveForm.BorderStyle; FormGrise.Show; FusionerImage(FormGrise,BitmapForm); FormGrise.BringToFront; BitmapForm.Free; Result:=Fenetre.ShowModal; if FormGrise<>nil then FormGrise.Release; end; End.
Envoyé par kurkaine
, la vérité j'ai pas compris ce que tu dire ?????
![]()
sa me casse la tete
![]()
En fait, je n'ai toujours pas pu tester votre programme, j'ai des problèmes pour adapter en C++. Mais j'y arriverai... J'espère.kurkaine a écrit :
ne pas surcharger mon application avec des fenêtres superposé.
Ce que je voulais dire, c'est que mon app est MDI. Disons que j'ai une fiche qui gère les clients. Ensuite, l'utilisateur peut ouvrir une fiche pour ajouter des clients (non MDI). Déjà à ce niveau, je souhaiterai griser la fenêtre de gestion des clients, car j'ai remarqué que certain utilisateur (novice) avait du mal à se repérer et aussi pour des raisons d'IHM. Durant la phase d'insertion d'un nouveau client, l'utilisateur peut faire une erreur d'insertion et je lui envoie un messg d'erreur, ce qui fait que j'ai trois fenêtre superposé.
Donc voilà, la fenêtre en premier plan doit être la seule normale. Je suis très très impatient de tester votre programme.
Partager