Browse Source

This should have already existed!


git-svn-id: http://svn.dmdirc.com/trunk@4182 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Shane Mc Cormack 16 years ago
parent
commit
6f08f05ae5
1 changed files with 200 additions and 0 deletions
  1. 200
    0
      installer/windows/Vista.pas

+ 200
- 0
installer/windows/Vista.pas View File

@@ -0,0 +1,200 @@
1
+{*
2
+ * Vista image improvements from http://www.installationexcellence.com/articles/VistaWithDelphi/Original/Index.html
3
+ * and http://www.installationexcellence.com/articles/VistaWithDelphi/Index.html
4
+ *}
5
+unit Vista;
6
+
7
+//{$IFDEF LAZARUS}
8
+//	{$DEFINE MESSAGEDLG}
9
+// {$ENDIF}
10
+
11
+interface
12
+
13
+uses {$IFDEF LAZARUS}Forms, Graphics, Controls,{$IFDEF MESSAGEDLG} Dialogs,{$ENDIF}{$ENDIF} Windows, SysUtils;
14
+
15
+function IsWindowsVista: Boolean;
16
+function TaskDialog(const AHandle: THandle; const ATitle, ADescription, AContent: WideString; const Icon, Buttons: integer; includeDescInXP: boolean = false; stripLineFeed: boolean = true): Integer;
17
+{$IFDEF LAZARUS}
18
+procedure SetVistaFonts(const AForm: TCustomForm);
19
+{$ENDIF}
20
+
21
+const
22
+	VistaFont = 'Segoe UI'; 
23
+	VistaContentFont = 'Calibri';
24
+	XPContentFont = 'Verdana';
25
+	XPFont = 'Tahoma';
26
+
27
+	TD_ICON_BLANK = 0;
28
+	TD_ICON_WARNING = 84;
29
+	TD_ICON_QUESTION = 99;
30
+	TD_ICON_ERROR = 98;
31
+	TD_ICON_INFORMATION = 81;
32
+	TD_ICON_SHIELD_QUESTION = 104;
33
+	TD_ICON_SHIELD_ERROR = 105;
34
+	TD_ICON_SHIELD_OK = 106;
35
+	TD_ICON_SHIELD_WARNING = 107;
36
+
37
+	TD_BUTTON_OK = 1;
38
+	TD_BUTTON_YES = 2;
39
+	TD_BUTTON_NO = 4;
40
+	TD_BUTTON_CANCEL = 8;
41
+	TD_BUTTON_RETRY = 16;
42
+	TD_BUTTON_CLOSE = 32;
43
+
44
+	TD_RESULT_OK = 1;
45
+	TD_RESULT_CANCEL = 2;
46
+	TD_RESULT_RETRY = 4;
47
+	TD_RESULT_YES = 6;
48
+	TD_RESULT_NO = 7;
49
+	TD_RESULT_CLOSE = 8;
50
+	
51
+	{$IFNDEF LAZARUS}
52
+		mrNone = 0;
53
+		mrOK = mrNone + 1;
54
+		mrCancel = mrNone + 2;
55
+		mrAbort = mrNone + 3;
56
+		mrRetry = mrNone + 4;
57
+		mrYes = mrNone + 6;
58
+		mrNo = mrNone + 7;
59
+	{$ENDIF}
60
+
61
+implementation
62
+
63
+{$IFDEF LAZARUS}
64
+procedure SetVistaFonts(const AForm: TCustomForm);
65
+begin
66
+	if IsWindowsVista and not SameText(AForm.Font.Name, VistaFont) and (Screen.Fonts.IndexOf(VistaFont) >= 0) then
67
+	begin
68
+		AForm.Font.Size := AForm.Font.Size + 1;
69
+		AForm.Font.Name := VistaFont;
70
+	end;
71
+end;
72
+{$ENDIF}
73
+
74
+function IsWindowsVista: Boolean;
75
+var
76
+	VerInfo: TOSVersioninfo;
77
+begin
78
+	VerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
79
+	GetVersionEx(VerInfo);
80
+	Result := VerInfo.dwMajorVersion >= 6;
81
+end;
82
+
83
+// http://www.swissdelphicenter.ch/en/showcode.php?id=1692
84
+{:Converts Unicode string to Ansi string using specified code page.
85
+  @param   ws       Unicode string.
86
+  @param   codePage Code page to be used in conversion.
87
+  @returns Converted ansi string.
88
+}
89
+function WideStringToString(const ws: WideString; codePage: Word): AnsiString;
90
+var
91
+  l: integer;
92
+begin
93
+	if ws = '' then begin
94
+		Result := ''
95
+	end
96
+	else begin
97
+		l := WideCharToMultiByte(codePage, WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR, @ws[1], - 1, nil, 0, nil, nil);
98
+		SetLength(Result, l - 1);
99
+		if l > 1 then begin
100
+			WideCharToMultiByte(codePage, WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR, @ws[1], - 1, @Result[1], l - 1, nil, nil);
101
+		end;
102
+	end;
103
+end;
104
+
105
+
106
+//from http://www.tmssoftware.com/atbdev5.htm
107
+function TaskDialog(const AHandle: THandle; const ATitle, ADescription, AContent: WideString; const Icon, Buttons: integer; includeDescInXP: boolean = false; stripLineFeed: boolean = true): Integer;
108
+var
109
+	DLLHandle: THandle;
110
+	res: integer;
111
+	wS: WideString;
112
+	S: String;
113
+	{$IFDEF MESSAGEDLG}
114
+	Btns: TMsgDlgButtons;
115
+	DlgType: TMsgDlgType;
116
+	{$ELSE}
117
+	Btns: Integer;
118
+	myIcon: Integer;
119
+	{$ENDIF}
120
+	TaskDialogFound: boolean;
121
+	TaskDialogProc: function(HWND: THandle; hInstance: THandle; cTitle, cDescription, cContent: pwidechar; Buttons: Integer; Icon: integer; ResButton: pinteger): integer; stdcall;
122
+begin
123
+	TaskDialogFound := false;
124
+	Result := 0;
125
+	if IsWindowsVista then begin
126
+		DLLHandle := LoadLibrary('comctl32.dll');
127
+		if DLLHandle >= 32 then begin
128
+			@TaskDialogProc := GetProcAddress(DLLHandle,'TaskDialog');
129
+			
130
+			if Assigned(TaskDialogProc) then begin
131
+				
132
+				if stripLineFeed then begin
133
+					wS := StringReplace(AContent, #10, '', [rfReplaceAll]);
134
+					wS := StringReplace(wS, #13, '', [rfReplaceAll]);
135
+				end
136
+				else begin
137
+					wS := AContent;
138
+				end;
139
+
140
+				TaskDialogProc(AHandle, 0, PWideChar(ATitle), PWideChar(ADescription), PWideChar(wS), Buttons, Icon, @res);
141
+				TaskDialogFound := true;
142
+				Result := mrOK;
143
+				case res of
144
+					TD_RESULT_CANCEL : Result := mrCancel;
145
+					TD_RESULT_RETRY : Result := mrRetry;
146
+					TD_RESULT_YES : Result := mrYes;
147
+					TD_RESULT_NO : Result := mrNo;
148
+					TD_RESULT_CLOSE : Result := mrAbort;
149
+				end;
150
+			end;
151
+			FreeLibrary(DLLHandle);
152
+		end;
153
+	end;
154
+	
155
+	if not TaskDialogFound then begin
156
+		S := '';
157
+		if includeDescInXP then S := ADescription + #10#13 + #10#13 + AContent else S := AContent;
158
+		
159
+		{$IFDEF MESSAGEDLG}
160
+			Btns := [];
161
+			if Buttons and TD_BUTTON_OK = TD_BUTTON_OK then Btns := Btns + [MBOK];
162
+			if Buttons and TD_BUTTON_YES = TD_BUTTON_YES then Btns := Btns + [MBYES];
163
+			if Buttons and TD_BUTTON_NO = TD_BUTTON_NO then Btns := Btns + [MBNO];
164
+			if Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL then Btns := Btns + [MBCANCEL];
165
+			if Buttons and TD_BUTTON_RETRY = TD_BUTTON_RETRY then Btns := Btns + [MBRETRY];
166
+	
167
+			if Buttons and TD_BUTTON_CLOSE = TD_BUTTON_CLOSE then Btns := Btns + [MBABORT];
168
+	
169
+			DlgType := mtCustom;
170
+	
171
+			case Icon of
172
+				TD_ICON_WARNING : DlgType := mtWarning;
173
+				TD_ICON_QUESTION : DlgType := mtConfirmation;
174
+				TD_ICON_ERROR : DlgType := mtError;
175
+				TD_ICON_INFORMATION: DlgType := mtInformation;
176
+			end;
177
+	
178
+			Result := MessageDlg(S, DlgType, Btns, 0);
179
+		{$ELSE}
180
+			Btns := 0;
181
+			if Buttons and TD_BUTTON_OK = TD_BUTTON_OK then Btns := MB_OK;
182
+			if (Buttons and TD_BUTTON_YES = TD_BUTTON_YES) and (Buttons and TD_BUTTON_NO = TD_BUTTON_NO) then Btns := MB_YESNO;
183
+			if (Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL) and (Buttons and TD_BUTTON_YES = TD_BUTTON_YES) and (Buttons and TD_BUTTON_NO = TD_BUTTON_NO) then Btns := MB_YESNOCANCEL;
184
+			if (Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL) and (Buttons and TD_BUTTON_OK = TD_BUTTON_OK) then Btns := MB_OKCANCEL;
185
+			if (Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL) and (Buttons and TD_BUTTON_RETRY = TD_BUTTON_RETRY) then Btns := MB_RETRYCANCEL;
186
+			
187
+			myIcon := 0;
188
+			case Icon of
189
+				TD_ICON_QUESTION : myIcon := MB_ICONQUESTION;
190
+				TD_ICON_ERROR : myIcon := MB_ICONSTOP;
191
+				TD_ICON_INFORMATION: myIcon := MB_ICONINFORMATION;
192
+			end;
193
+			
194
+			Result := MessageBox(0, pchar(S), pchar(String(ATitle)), Btns + myIcon);
195
+		{$ENDIF}
196
+	end;
197
+end;
198
+
199
+end.
200
+

Loading…
Cancel
Save