![]() |
MessageBox mit Icons
Hallo!
Also MessageDlg nimmt die Captions ja aus Delphi und MessageBox aus Windows. Jedoch kann man mit MessageBox keine Icons (i, !, ?, ...) erzeugen. Mit welcher Funktion kann ich das machen? Grüße Faux |
Re: MessageBox mit Icons
![]() wie du dort siehst hast du bei den optionen auch welche mit MB_ICON beginnend...das sind die Icons ;) HTH Frank |
Re: MessageBox mit Icons
Danke für die Information! Das hat mir geholfen. ;)
Eine Frage hätte ich noch: In der MSDN steht geschrieben: MB_ICONQUESTION A question-mark icon appears in the message box. The question-mark message icon is no longer recommended because it does not clearly represent a specific type of message and because the phrasing of a message as a question could apply to any message type. In addition, users can confuse the message symbol question mark with Help information. Therefore, do not use this question mark message symbol in your message boxes. The system continues to support its inclusion only for backward compatibility. Wieso soll man das nicht benutzen? Das verstehe ich nicht ganz. Wie mache ich sonst ein Frage-Symbol? Ich will einen Schließen-Dialog machen, wo das Frage-Icon eigentlich gut passen würde. Grüße Faux |
Re: MessageBox mit Icons
Ich kenne keine Software, die bei diesem Dialog ein Icon anzeigt, und fände es auch nicht passend. Also einfach weglassen ;) .
|
Re: MessageBox mit Icons
kA ob man das darf aber das ist mal der Code aus der Unit wo der MessageDialog erzeugt wird, schau dir mal durch vllt findest es ja :zwinker:
Delphi-Quellcode:
function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons): TForm; const mcHorzMargin = 8; mcVertMargin = 8; mcHorzSpacing = 10; mcVertSpacing = 10; mcButtonWidth = 50; mcButtonHeight = 14; mcButtonSpacing = 4; var DialogUnits: TPoint; HorzMargin, VertMargin, HorzSpacing, VertSpacing, ButtonWidth, ButtonHeight, ButtonSpacing, ButtonCount, ButtonGroupWidth, IconTextWidth, IconTextHeight, X, ALeft: Integer; B, DefaultButton, CancelButton: TMsgDlgBtn; IconID: PChar; TextRect: TRect; begin Result := TMessageForm.CreateNew(Application); with Result do begin BiDiMode := Application.BiDiMode; BorderStyle := bsDialog; Canvas.Font := Font; KeyPreview := True; Position := poDesigned; OnKeyDown := TMessageForm(Result).CustomKeyDown; DialogUnits := GetAveCharSize(Canvas); HorzMargin := MulDiv(mcHorzMargin, DialogUnits.X, 4); VertMargin := MulDiv(mcVertMargin, DialogUnits.Y, 8); HorzSpacing := MulDiv(mcHorzSpacing, DialogUnits.X, 4); VertSpacing := MulDiv(mcVertSpacing, DialogUnits.Y, 8); ButtonWidth := MulDiv(mcButtonWidth, DialogUnits.X, 4); for B := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do begin if B in Buttons then begin if ButtonWidths[B] = 0 then begin TextRect := Rect(0,0,0,0); Windows.DrawText( canvas.handle, PChar(LoadResString(ButtonCaptions[B])), -1, TextRect, DT_CALCRECT or DT_LEFT or DT_SINGLELINE or DrawTextBiDiModeFlagsReadingOnly); with TextRect do ButtonWidths[B] := Right - Left + 8; end; if ButtonWidths[B] > ButtonWidth then ButtonWidth := ButtonWidths[B]; end; end; ButtonHeight := MulDiv(mcButtonHeight, DialogUnits.Y, 8); ButtonSpacing := MulDiv(mcButtonSpacing, DialogUnits.X, 4); SetRect(TextRect, 0, 0, Screen.Width div 2, 0); DrawText(Canvas.Handle, PChar(Msg), Length(Msg)+1, TextRect, DT_EXPANDTABS or DT_CALCRECT or DT_WORDBREAK or DrawTextBiDiModeFlagsReadingOnly); IconID := IconIDs[DlgType];//Guggst du hier IconTextWidth := TextRect.Right; IconTextHeight := TextRect.Bottom; if IconID <> nil then begin Inc(IconTextWidth, 32 + HorzSpacing); if IconTextHeight < 32 then IconTextHeight := 32; end; ButtonCount := 0; for B := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do if B in Buttons then Inc(ButtonCount); ButtonGroupWidth := 0; if ButtonCount <> 0 then ButtonGroupWidth := ButtonWidth * ButtonCount + ButtonSpacing * (ButtonCount - 1); ClientWidth := Max(IconTextWidth, ButtonGroupWidth) + HorzMargin * 2; ClientHeight := IconTextHeight + ButtonHeight + VertSpacing + VertMargin * 2; Left := (Screen.Width div 2) - (Width div 2); Top := (Screen.Height div 2) - (Height div 2); if DlgType <> mtCustom then Caption := LoadResString(Captions[DlgType]) else Caption := Application.Title; if IconID <> nil then with TImage.Create(Result) do begin Name := 'Image'; Parent := Result; Picture.Icon.Handle := LoadIcon(0, IconID);//und hier guggst du au SetBounds(HorzMargin, VertMargin, 32, 32); end; TMessageForm(Result).Message := TLabel.Create(Result); with TMessageForm(Result).Message do begin Name := 'Message'; Parent := Result; WordWrap := True; Caption := Msg; BoundsRect := TextRect; BiDiMode := Result.BiDiMode; ALeft := IconTextWidth - TextRect.Right + HorzMargin; if UseRightToLeftAlignment then ALeft := Result.ClientWidth - ALeft - Width; SetBounds(ALeft, VertMargin, TextRect.Right, TextRect.Bottom); end; if mbOk in Buttons then DefaultButton := mbOk else if mbYes in Buttons then DefaultButton := mbYes else DefaultButton := mbRetry; if mbCancel in Buttons then CancelButton := mbCancel else if mbNo in Buttons then CancelButton := mbNo else CancelButton := mbOk; X := (ClientWidth - ButtonGroupWidth) div 2; for B := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do if B in Buttons then with TButton.Create(Result) do begin Name := ButtonNames[B]; Parent := Result; Caption := LoadResString(ButtonCaptions[B]); ModalResult := ModalResults[B]; if B = DefaultButton then Default := True; if B = CancelButton then Cancel := True; SetBounds(X, IconTextHeight + VertMargin + VertSpacing, ButtonWidth, ButtonHeight); Inc(X, ButtonWidth + ButtonSpacing); if B = mbHelp then OnClick := TMessageForm(Result).HelpButtonClick; end; end; end; |
Re: MessageBox mit Icons
Liste der Anhänge anzeigen (Anzahl: 1)
Zitat:
@Angel: Wie? Was soll ich denn mit dem Code machen? :gruebel: Grüße Faux |
Re: MessageBox mit Icons
Also ich hab mir aus diesem Code die Icons geschichte für meinen eigenen MessageDialog gezogen, dummerweise ist das ganze im Geschäft un da bin ich erst Montag wieder.
Aus jedenfall siehst du da wie das der "richtige" MessageDlg macht und könntest es ja evtl übernehmen :zwinker: musst dir das eben bei dir im delphi noch bissi genauer anschauen |
Re: MessageBox mit Icons
So, hier mal der Code wie ich die Icons in eine TImage-Kompo lade, für alle Fälle:
Delphi-Quellcode:
var
Img_Symbol : TImage; FDlgType : Integer; procedure TMyDialog.LoadIcon; var IconID : PAnsiChar; begin case FDlgType of 0 : IconID := IDI_QUESTION; 1 : IconID := IDI_WARNING; 2 : IconID := IDI_INFORMATION; else IconID := IDI_ERROR; end; Img_Symbol.Picture.Icon.Handle:=LoadIcon(0,IconID); end; |
Re: MessageBox mit Icons
Und was hat er davon?
|
Re: MessageBox mit Icons
Öhm.. er kann sich einen eigenen Dialog basteln den er je nach bedürfnis anpassen kann, ist teilweise praktischer als so en Standard-Dialog.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:41 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz