
上QQ阅读APP看书,第一时间看更新
There's more...
The new Task Dialog API can give your application a fresh look, but that comes with a cost because it works only on Vista or better, with enabled themes. So, how do you work around the problem if you need to run the application on Windows XP or on a machine without themes enabled? For button 6, there's simple code to check whether you can safely use the TTaskDialog component or whether you have to go back to the normal ShowMessage or MessageDlg. Here's the event handler for button 6:
procedure TMainForm.btnCheckWinVerClick(Sender: TObject); var LTaskDialog: TTaskDialog; begin if (Win32MajorVersion >= 6) and ThemeServices.ThemesEnabled then begin LTaskDialog := TTaskDialog.Create(Self); try LTaskDialog.Caption := 'MY Fantastic Application'; LTaskDialog.Title := 'The Cook Task Dialog!'; LTaskDialog.Text := 'This is a Task Dialog, so I''m on Vista ' +
'or better with themes enabled'; LTaskDialog.CommonButtons := [tcbOk]; LTaskDialog.Execute; finally LTaskDialog.Free; end
end
else
begin ShowMessage('This is an old and boring ShowMessage, ' +
'here only to support old Microsoft Windows OS ' +
'(XP and below)'); end; end;
Try to disable the themes for your application and click on button 6.
Obviously, it is strongly suggested that you wrap this code in a function so that you do not have to write the same code repeatedly.