Exclude VCL styles from styles. Dialog / ShowMessage Boundaries.

Is there a way to exclude the VCL style to stylize the border of system dialog boxes.

The sepecifically dialog box displayed by a call to MessageDlg or ShowMessage.

I read several articles about "The Road to Delphi" (which is a great place on the site), but could not find the answer.

Here is what I want to achieve:

Now (Carbon style with stylized borders):

now

Purpose (Carbon style with standard window borders):

enter image description here

I still want to have stylized controls, but not stylized borders.

Removing seBorder from parent StyleElements forms does not do the trick.

enter image description here

Thanks!

+7
delphi delphi-xe7 vcl vcl-styles
source share
2 answers

MessageDlg() and ShowMessage() are Delphi VCL functions. They dynamically create Delphi TForm and display it, so you have no way to configure it. However, you can use CreateMessageDialog() instead to create the same TForm , and then change its style elements as necessary, and then show it. For example:

 function DoMessageDlgPosHelp(MessageDialog: TForm; X, Y: Integer): Integer; begin with MessageDialog do try if X >= 0 then Left := X; if Y >= 0 then Top := Y; if (Y < 0) and (X < 0) then Position := poScreenCenter; Result := ShowModal; finally Free; end; end; procedure ShowStyledMessage(const Msg: string; const StyleElements: TStyleElements); var Form: TForm; begin Form := CreateMessageDialog(Msg, mtCustom, [mbOK]); Form.StyleElements := StyleElements; DoMessageDlgPosHelp(Form, -1, -1); end; 

Name it as follows:

 ShowStyledMessage('Some text', [seFont, seClient]); 

And the dialog box looks like this:

screenshot

+4
source share

To create a stylish form without borders, you must remove the seBorder property from the StyleElements form.

  StyleElements := [seFont, seClient]; 

From form designer

But you must set this property for each form. If I understand correctly, you want to show a message dialog with a Windows border. In this case, the StyleElements parameter for the form that calls ShowMessage will not affect the dialog box, because it is a completely new form.

What you need to do is set the StyleElements property for the dialog form that Delphi creates from your reach. To do this, you need to create your own StyleHook form and replace TFormStyleHook for all forms.

Just add the following block to your project, and all forms will have a Windows border, without the need to explicitly specify it for each form.

 unit WinBorder; interface uses Winapi.Windows, Winapi.Messages, Vcl.Themes, Vcl.Controls, Vcl.Forms; type TWinBorderFormStyleHook = class(TFormStyleHook) protected procedure WndProc(var Message: TMessage); override; public constructor Create(AControl: TWinControl); override; end; implementation constructor TWinBorderFormStyleHook.Create(AControl: TWinControl); begin inherited; OverridePaintNC := false; end; procedure TWinBorderFormStyleHook.WndProc(var Message: TMessage); begin inherited; if Message.Msg = CM_VISIBLECHANGED then begin if (Control is TCustomForm) and (seBorder in TCustomForm(Control).StyleElements) then TCustomForm(Control).StyleElements := [seFont, seClient]; end; end; initialization TCustomStyleEngine.UnRegisterStyleHook(TCustomForm, TFormStyleHook); TCustomStyleEngine.UnRegisterStyleHook(TForm, TFormStyleHook); TCustomStyleEngine.RegisterStyleHook(TCustomForm, TWinBorderFormStyleHook); TCustomStyleEngine.RegisterStyleHook(TForm, TWinBorderFormStyleHook); finalization TCustomStyleEngine.UnRegisterStyleHook(TCustomForm, TWinBorderFormStyleHook); TCustomStyleEngine.UnRegisterStyleHook(TForm, TWinBorderFormStyleHook); TCustomStyleEngine.RegisterStyleHook(TCustomForm, TFormStyleHook); TCustomStyleEngine.RegisterStyleHook(TForm, TFormStyleHook); end. 
+2
source share

All Articles