Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Vista.pas 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. * This application launches DMDirc on windows and passes control to the
  6. * update engine as necessary.
  7. *
  8. * DMDirc - Open Source IRC Client
  9. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes,
  10. * Michael Nixon
  11. *
  12. * Permission is hereby granted, free of charge, to any person obtaining a copy
  13. * of this software and associated documentation files (the "Software"), to deal
  14. * in the Software without restriction, including without limitation the rights
  15. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  16. * copies of the Software, and to permit persons to whom the Software is
  17. * furnished to do so, subject to the following conditions:
  18. *
  19. * The above copyright notice and this permission notice shall be included in
  20. * all copies or substantial portions of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  25. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  28. * SOFTWARE.
  29. *}
  30. {* NOTE: The version in the installer/ directory is the one to edit! *}
  31. unit Vista;
  32. interface
  33. uses Windows, SysUtils;
  34. function IsWindowsVista: Boolean;
  35. function TaskDialog(const AHandle: THandle; const ATitle, ADescription, AContent: WideString; const Icon, Buttons: integer; includeDescInXP: boolean = false; stripLineFeed: boolean = true): Integer;
  36. //procedure SetVistaFonts(const AForm: TCustomForm);
  37. const
  38. VistaFont = 'Segoe UI';
  39. VistaContentFont = 'Calibri';
  40. XPContentFont = 'Verdana';
  41. XPFont = 'Tahoma';
  42. TD_ICON_BLANK = 0;
  43. TD_ICON_WARNING = 84;
  44. TD_ICON_QUESTION = 99;
  45. TD_ICON_ERROR = 98;
  46. TD_ICON_INFORMATION = 81;
  47. TD_ICON_SHIELD_QUESTION = 104;
  48. TD_ICON_SHIELD_ERROR = 105;
  49. TD_ICON_SHIELD_OK = 106;
  50. TD_ICON_SHIELD_WARNING = 107;
  51. TD_BUTTON_OK = 1;
  52. TD_BUTTON_YES = 2;
  53. TD_BUTTON_NO = 4;
  54. TD_BUTTON_CANCEL = 8;
  55. TD_BUTTON_RETRY = 16;
  56. TD_BUTTON_CLOSE = 32;
  57. TD_RESULT_OK = 1;
  58. TD_RESULT_CANCEL = 2;
  59. TD_RESULT_RETRY = 4;
  60. TD_RESULT_YES = 6;
  61. TD_RESULT_NO = 7;
  62. TD_RESULT_CLOSE = 8;
  63. mrNone = 0;
  64. mrOK = mrNone + 1;
  65. mrCancel = mrNone + 2;
  66. mrAbort = mrNone + 3;
  67. mrRetry = mrNone + 4;
  68. mrYes = mrNone + 6;
  69. mrNo = mrNone + 7;
  70. implementation
  71. {*
  72. procedure SetVistaFonts(const AForm: TCustomForm);
  73. begin
  74. if IsWindowsVista and not SameText(AForm.Font.Name, VistaFont) and (Screen.Fonts.IndexOf(VistaFont) >= 0) then
  75. begin
  76. AForm.Font.Size := AForm.Font.Size + 1;
  77. AForm.Font.Name := VistaFont;
  78. end;
  79. end;
  80. *}
  81. function IsWindowsVista: Boolean;
  82. var
  83. VerInfo: TOSVersioninfo;
  84. begin
  85. VerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
  86. GetVersionEx(VerInfo);
  87. Result := VerInfo.dwMajorVersion >= 6;
  88. end;
  89. // http://www.swissdelphicenter.ch/en/showcode.php?id=1692
  90. {:Converts Unicode string to Ansi string using specified code page.
  91. @param ws Unicode string.
  92. @param codePage Code page to be used in conversion.
  93. @returns Converted ansi string.
  94. }
  95. function WideStringToString(const ws: WideString; codePage: Word): AnsiString;
  96. var
  97. l: integer;
  98. begin
  99. if ws = '' then begin
  100. Result := ''
  101. end
  102. else begin
  103. l := WideCharToMultiByte(codePage, WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR, @ws[1], - 1, nil, 0, nil, nil);
  104. SetLength(Result, l - 1);
  105. if l > 1 then begin
  106. WideCharToMultiByte(codePage, WC_COMPOSITECHECK or WC_DISCARDNS or WC_SEPCHARS or WC_DEFAULTCHAR, @ws[1], - 1, @Result[1], l - 1, nil, nil);
  107. end;
  108. end;
  109. end;
  110. //from http://www.tmssoftware.com/atbdev5.htm
  111. function TaskDialog(const AHandle: THandle; const ATitle, ADescription, AContent: WideString; const Icon, Buttons: integer; includeDescInXP: boolean = false; stripLineFeed: boolean = true): Integer;
  112. type
  113. tTaskDialogProc = function(HWND: THandle; hInstance: THandle; cTitle, cDescription, cContent: pwidechar; Buttons: Integer; Icon: integer; ResButton: pinteger): integer; stdcall;
  114. var
  115. DLLHandle: THandle;
  116. res: integer;
  117. wS: WideString;
  118. S: String;
  119. {$IFDEF MESSAGEDLG}
  120. Btns: TMsgDlgButtons;
  121. DlgType: TMsgDlgType;
  122. {$ELSE}
  123. Btns: Integer;
  124. myIcon: Integer;
  125. {$ENDIF}
  126. TaskDialogFound: boolean;
  127. TaskDialogProc: tTaskDialogProc;
  128. begin
  129. TaskDialogFound := false;
  130. Result := 0;
  131. if IsWindowsVista then begin
  132. DLLHandle := LoadLibrary('comctl32.dll');
  133. if DLLHandle >= 32 then begin
  134. TaskDialogProc := tTaskDialogProc(GetProcAddress(DLLHandle,'TaskDialog'));
  135. if Assigned(TaskDialogProc) then begin
  136. if stripLineFeed then begin
  137. wS := StringReplace(AContent, #10, '', [rfReplaceAll]);
  138. wS := StringReplace(wS, #13, '', [rfReplaceAll]);
  139. end
  140. else begin
  141. wS := AContent;
  142. end;
  143. TaskDialogProc(AHandle, 0, PWideChar(ATitle), PWideChar(ADescription), PWideChar(wS), Buttons, Icon, @res);
  144. TaskDialogFound := true;
  145. Result := mrOK;
  146. case res of
  147. TD_RESULT_CANCEL : Result := mrCancel;
  148. TD_RESULT_RETRY : Result := mrRetry;
  149. TD_RESULT_YES : Result := mrYes;
  150. TD_RESULT_NO : Result := mrNo;
  151. TD_RESULT_CLOSE : Result := mrAbort;
  152. end;
  153. end;
  154. FreeLibrary(DLLHandle);
  155. end;
  156. end;
  157. if not TaskDialogFound then begin
  158. S := '';
  159. if includeDescInXP then S := ADescription + #10#13 + #10#13 + AContent else S := AContent;
  160. {$IFDEF MESSAGEDLG}
  161. Btns := [];
  162. if Buttons and TD_BUTTON_OK = TD_BUTTON_OK then Btns := Btns + [MBOK];
  163. if Buttons and TD_BUTTON_YES = TD_BUTTON_YES then Btns := Btns + [MBYES];
  164. if Buttons and TD_BUTTON_NO = TD_BUTTON_NO then Btns := Btns + [MBNO];
  165. if Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL then Btns := Btns + [MBCANCEL];
  166. if Buttons and TD_BUTTON_RETRY = TD_BUTTON_RETRY then Btns := Btns + [MBRETRY];
  167. if Buttons and TD_BUTTON_CLOSE = TD_BUTTON_CLOSE then Btns := Btns + [MBABORT];
  168. DlgType := mtCustom;
  169. case Icon of
  170. TD_ICON_WARNING : DlgType := mtWarning;
  171. TD_ICON_QUESTION : DlgType := mtConfirmation;
  172. TD_ICON_ERROR : DlgType := mtError;
  173. TD_ICON_INFORMATION: DlgType := mtInformation;
  174. end;
  175. Result := MessageDlg(S, DlgType, Btns, 0);
  176. {$ELSE}
  177. Btns := 0;
  178. if Buttons and TD_BUTTON_OK = TD_BUTTON_OK then Btns := MB_OK;
  179. if (Buttons and TD_BUTTON_YES = TD_BUTTON_YES) and (Buttons and TD_BUTTON_NO = TD_BUTTON_NO) then Btns := MB_YESNO;
  180. 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;
  181. if (Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL) and (Buttons and TD_BUTTON_OK = TD_BUTTON_OK) then Btns := MB_OKCANCEL;
  182. if (Buttons and TD_BUTTON_CANCEL = TD_BUTTON_CANCEL) and (Buttons and TD_BUTTON_RETRY = TD_BUTTON_RETRY) then Btns := MB_RETRYCANCEL;
  183. myIcon := 0;
  184. case Icon of
  185. TD_ICON_QUESTION : myIcon := MB_ICONQUESTION;
  186. TD_ICON_ERROR : myIcon := MB_ICONSTOP;
  187. TD_ICON_INFORMATION: myIcon := MB_ICONINFORMATION;
  188. end;
  189. Result := MessageBox(0, pchar(S), pchar(String(ATitle)), Btns + myIcon);
  190. {$ENDIF}
  191. end;
  192. end;
  193. end.