MessageDlg Functionu ile ilgili

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
naci_ozdemir2001
Üye
Mesajlar: 13
Kayıt: 18 Haz 2003 04:34
Konum: ankara

MessageDlg Functionu ile ilgili

Mesaj gönderen naci_ozdemir2001 »

Messagedlg fonkisiyonundaki butonların captionlarını değiştirme ile ilgili bir örnek varmı İngilizce olarak Yes No Butonu nu kullanmak istemiyorum

Teşekkürler
sair
Kıdemli Üye
Mesajlar: 288
Kayıt: 16 Haz 2003 04:41
Konum: Kastamonu
İletişim:

Mesaj gönderen sair »

Messagedlg fonksiyonu butonların mesajnı windowstan alır. Türkçe windows yüklüyse buton mesajları türkçe gelir. Almanca yüklüyse almanca gelir. Türkçe windows ta ingilizce mesaj gelmez merak etme...
Geçip gideriz bizde ağızsız,dilsiz ve sorgusuz
İstanbul gibi düşeriz iki kıtaya birden...
En aşağılık düş, en büyük sevdadan belki
Erkek ölümler; bir uzun iç çekişle büyür göğsümüz
mavsar

Mesaj gönderen mavsar »

Şair arkadaşımın dediği geçerlidir. Fakat işletim sistemi ne olursa olsun ben kendi yazdığım değerleri kullanmak istiyorum diyorsanız. Aşağıdaki kodu buldum. Umarım işinize yarar.

Mehmet

Kod: Tümünü seç

You have to create a form, this is not a stock windows dialog. Take a look at 
the following unit, especially the MessageDlgWithNoMorebox function.

{== MyDialogs =========================================================}
{: Collects modified dialog functions
@author Dr. Peter Below
@desc   Version: 1.0  Created: 07.06.98<BR>
        Version 1.01 created 4 Juli 2001, added translation of 
          button captions.<BR>
        Last modified       4 Juli 2001<P>
   }
{======================================================================}
Unit MyDialogs;

Interface

Uses Dialogs;
 
Function DefMessageDlg(const aCaption: String;
                       const Msg: string;
                       DlgType: TMsgDlgType;
                       Buttons: TMsgDlgButtons;
                       DefButton: Integer;
                       HelpCtx: Longint): Integer;

Function MessageDlgWithNoMorebox(const aCaption: String;
                       const Msg: string;
                       DlgType: TMsgDlgType;
                       Buttons: TMsgDlgButtons;
                       DefButton: Integer;
                       HelpCtx: Longint;
                       Var askNoMore: Boolean ): Integer;
Implementation

Uses Windows, Classes, Controls, stdctrls, sysutils, forms;

Const { Copied from Dialogs }
  ModalResults: array[TMsgDlgBtn] of Integer = (
    mrYes, mrNo, mrOk, mrCancel, mrAbort, mrRetry, mrIgnore, mrAll, 
    mrNoToAll, mrYesToAll, 0);
  
Var { Filled during unit initialization }
  ButtonCaptions: Array[ TMsgDlgBtn ] Of String;

{ Convert a modal result to a TMsgDlgBtn code. }
Function ModalResultToBtn( res: TModalResult ): TMsgDlgBtn;
  Begin
    For Result:= Low( Result ) To High( Result ) Do Begin
      If ModalResults[ Result ] = res Then
        Exit;
    End; { For }
    Result := mbHelp;  // to remove warning only 
    Assert( False, 'ModalResultToBtn: unknown modalresult '+
                   IntToStr( res ));
  End; { ModalResultToBtn } 

{ When the button captions on the message form are translated 
  the button size and as a consequence the button positions need
  to be adjusted. }
Procedure AdjustButtons( aForm: TForm );  
  Var
    buttons: TList;
    btnWidth: Integer;
    btnGap  : Integer;

  Procedure CollectButtons;
    Var
      i: Integer;
    Begin 
      For i:= 0 To aForm.Controlcount-1 Do 
        If aForm.Controls[ i ] Is TButton Then 
          buttons.Add( aForm.Controls[ i ] );
    End; { CollectButtons } 

  Procedure MeasureButtons;
    Var
      i: Integer;
      textrect: TRect;
      w: Integer;
    Begin 
      btnWidth := TButton(buttons[0]).Width;
      aForm.Canvas.Font := aForm.Font;
      For i:= 0 To buttons.count-1 Do Begin
        TextRect := Rect(0,0,0,0);
        Windows.DrawText( aform.canvas.handle,
          PChar(TButton( buttons[ i ] ).Caption),
          -1,
          TextRect,
          DT_CALCRECT or DT_LEFT or DT_SINGLELINE);
        with TextRect do w := Right - Left + 16;
        If w > btnWidth Then btnWidth := w;
      End; { For }
      If buttons.count > 1 Then
        btnGap := TButton( buttons[ 1 ] ).Left -
                  TButton( buttons[ 0 ] ).Left -
                  TButton( buttons[ 0 ] ).Width
      Else
        btnGap := 0;
    End; { MeasureButtons }

  Procedure SizeButtons;
    Var
      i: Integer;
    Begin 
      For i:= 0 To buttons.count-1 Do 
        TButton( buttons[ i ] ).Width := btnWidth;
    End; { SizeButtons }

  Procedure ArrangeButtons;  
    Var
      i: Integer;
      total, left: Integer;
    Begin 
      total := ( buttons.count - 1 ) * btnGap;
      For i:= 0 To buttons.count-1 Do 
        Inc( total, TButton( buttons[ i ] ).Width );
      left := ( aForm.ClientWidth - total ) div 2;
      If left < 0 Then Begin
        aForm.Width := aForm.Width + 2*Abs(left) + 16;
        left := 8;
      End; { If }
      For i:= 0 To buttons.count-1 Do Begin 
        TButton( buttons[ i ] ).Left := left;
        Inc( left, btnWidth+btnGap );
      End;
    End; { ArrangeButtons } 
    
  Begin 
    buttons := TList.Create;
    Try 
      CollectButtons;
      If buttons.Count = 0 Then
        Exit; 
      MeasureButtons;
      SizeButtons;
      ArrangeButtons;
    Finally
      buttons.Free;
    End; { finally }
  End; { AdjustButtons }

Procedure InitMsgForm( aForm: TForm; Const aCaption: String;
                       helpCtx: LongInt; DefButton: Integer );
  Var
    i: Integer;
    btn: TButton;
  Begin
    With aForm Do Begin
      If Length(aCaption) > 0 Then
        Caption := aCaption;
      HelpContext := HelpCtx;
      For i := 0 To ComponentCount-1 Do Begin
        If Components[i] Is TButton Then Begin
          btn := TButton(Components[i]);
          btn.Default:= btn.ModalResult = DefButton;
          If btn.Default Then
            ActiveControl := Btn;
          {$IFNDEF STANDARDCAPTIONS}
          btn.Caption :=
            ButtonCaptions[ ModalResultToBtn( btn.Modalresult ) ];
          {$ENDIF}
        End;
      End; { For }
      {$IFNDEF STANDARDCAPTIONS}
      AdjustButtons( aForm );
      {$ENDIF}
    End;
  End; { InitMsgForm }

{-- DefMessageDlg -----------------------------------------------------}
{: Creates a MessageDlg with translated button captions and a configurable
   default button and caption.
@Param aCaption   Caption to use for the dialog. If empty the
                  default is used.
@Param Msg        message to display
@Param DlgType    type of dialog, see MessageDlg online help
@Param Buttons    buttons to display, see MessageDlg online help
@Param DefButton  ModalResult of the button that should be the
                  default.
@Param HelpCtx    help context (optional)
@Returns the ModalResult of the dialog
}{ Created 07.06.1998 by P. Below, modified 04.07.2001
-----------------------------------------------------------------------}
Function DefMessageDlg( const aCaption: String; const Msg: string;
    DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; DefButton: Integer;
    HelpCtx: Longint ): Integer;
  Var
    aForm: TForm;
  Begin { DefMessageDlg }
    aForm:= CreateMessageDialog(Msg, DlgType, Buttons);
    try
      InitMsgForm(aForm, aCaption, helpCtx, DefButton );
      Result := aForm.ShowModal;
    finally
      aForm.Free;
    end;
  End; { DefMessageDlg }

Resourcestring
{$IFDEF GERMAN}
  AskNoMoreCaption = 'Diesen Dialog nicht mehr anzeigen';
{$ELSE}
  AskNoMoreCaption = 'Don''t show this dialog again';
{$ENDIF}

{-- MessageDlgWithNoMorebox -------------------------------------------}
{: Creates a MessageDlg with translated button captions and a configurable
   default button and caption.
@Param aCaption   Caption to use for the dialog. If empty the
                  default is used.
@Param Msg        message to display
@Param DlgType    type of dialog, see MessageDlg online help
@Param Buttons    buttons to display, see MessageDlg online help
@Param DefButton  ModalResult of the button that should be the
                  default.
@Param HelpCtx    help context (optional)
@Param askNoMore  if this is passed in as True the function will directly
                  return the DefButton result. Otherwise a checkbox is
                  shown beneath the buttons which the user can check to
                  not have this dialog show up in the future. Its checked
                  state is returned in the parameter.
@Returns the ModalResult of the dialog
}{ Created 4.7.2001 by P. Below
-----------------------------------------------------------------------}
Function MessageDlgWithNoMorebox( const aCaption: String;
    const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons;
    DefButton: Integer; HelpCtx: Longint;
    Var askNoMore: Boolean ): Integer;
  Var
    aForm: TForm;
    chk: TCheckbox;
  Begin { MessageDlgWithNoMorebox }
    If askNoMore Then
      Result := DefButton
    Else Begin
      aForm:= CreateMessageDialog(Msg, DlgType, Buttons);
      try
        InitMsgForm(aForm, aCaption, helpCtx, DefButton );
        chk:= TCheckbox.Create( aForm );
        chk.Parent := aForm;
        chk.SetBounds( 16, aForm.ClientHeight, aForm.Clientwidth-32,
                       chk.Height );
        chk.Checked := False;
        chk.Caption := AskNoMoreCaption;
        AForm.Height := aForm.Height + chk.Height + 8;
        Result := aForm.ShowModal;
        askNoMore := chk.Checked;
      finally
        aForm.Free;
      end;
    End;
  End; { MessageDlgWithNoMorebox }

ResourceString
{$IFDEF GERMAN} 
  cmbYes = '&Ja';
  cmbNo = '&Nein';
  cmbOK = 'OK';
  cmbCancel = 'Abbrechen';
  cmbHelp = '&Hilfe';
  cmbAbort = '&Abbrechen';
  cmbRetry = '&Wiederholen';
  cmbIgnore = '&Ignorieren';
  cmbAll = '&Alle';
  cmbNoToAll = 'N&ein für alle';
  cmbYesToAll = 'Ja für &alle';
{$ELSE} 
  cmbYes = '&Yes';
  cmbNo = '&No';
  cmbOK = 'OK';
  cmbCancel = 'Cancel';
  cmbHelp = '&Help';
  cmbAbort = '&Abort';
  cmbRetry = '&Retry';
  cmbIgnore = '&Ignore';
  cmbAll = '&All';
  cmbNoToAll = 'N&o to All';
  cmbYesToAll = 'Yes to &All';
{$ENDIF} 

Procedure InitButtonCaptions;  
  Begin     
    ButtonCaptions[ mbYes ] := cmbYes;
    ButtonCaptions[ mbNo ] := cmbNo;
    ButtonCaptions[ mbOK ] := cmbOK;
    ButtonCaptions[ mbCancel ] := cmbCancel;
    ButtonCaptions[ mbAbort ] := cmbAbort;
    ButtonCaptions[ mbRetry ] := cmbRetry;
    ButtonCaptions[ mbIgnore ] := cmbIgnore;
    ButtonCaptions[ mbAll ] := cmbAll;
    ButtonCaptions[ mbNoToAll ] := cmbNoToAll;
    ButtonCaptions[ mbYesToAll ] := cmbYesToAll;
    ButtonCaptions[ mbHelp ] := cmbHelp;
  End; { InitButtonCaptions } 


Initialization
  InitButtonCaptions;
End.
Kullanıcı avatarı
mussimsek
Admin
Mesajlar: 7601
Kayıt: 10 Haz 2003 12:26
Konum: İstanbul
İletişim:

Mesaj gönderen mussimsek »

Merhaba,

MessageBox sabitlerini windowstan alır, MessageDlg değil :!:

MessageDlg'un tüm sabitleri Consts.pas isimli dosyadadır. Eğer elinde Delphi'nin Source kod varsa bunları değiştirip derle ve oluşan dcu dosyasını Lib klasörüne koy.

Şu kısımları değiştirmen yeterli :

Kod: Tümünü seç

 SMsgDlgWarning = 'Warning';
  SMsgDlgError = 'Error';
  SMsgDlgInformation = 'Information';
  SMsgDlgConfirm = 'Confirm';
  SMsgDlgYes = '&Yes';
  SMsgDlgNo = '&No';
  SMsgDlgOK = 'OK';
  SMsgDlgCancel = 'Cancel';
  SMsgDlgHelp = '&Help';
  SMsgDlgHelpNone = 'No help available';
  SMsgDlgHelpHelp = 'Help';
  SMsgDlgAbort = '&Abort';
  SMsgDlgRetry = '&Retry';
  SMsgDlgIgnore = '&Ignore';
  SMsgDlgAll = '&All';
  SMsgDlgNoToAll = 'N&o to All';
  SMsgDlgYesToAll = 'Yes to &All';
Kolay gelsin.
sair
Kıdemli Üye
Mesajlar: 288
Kayıt: 16 Haz 2003 04:41
Konum: Kastamonu
İletişim:

Mesaj gönderen sair »

Mustafa bey. Peki neden Messagedlg nin butonları türkçe geliyor bizde o zaman. Bunun açıklaması ne ki... Madem Const.pas dosyasından alıyor. Bu dosyada ingilizce olarak derlenmiş ama bende türkçe geliyor bunun açıklaması ne peki ? Ben olayı çözemedim şimdi bak. Takıldı kafama...
Geçip gideriz bizde ağızsız,dilsiz ve sorgusuz
İstanbul gibi düşeriz iki kıtaya birden...
En aşağılık düş, en büyük sevdadan belki
Erkek ölümler; bir uzun iç çekişle büyür göğsümüz
sair
Kıdemli Üye
Mesajlar: 288
Kayıt: 16 Haz 2003 04:41
Konum: Kastamonu
İletişim:

Mesaj gönderen sair »

Özür ya. İngilizce geliyormuş. Ben hiç kullanmamışım ki bunu. Hep messagebox u kullanmışım. Karıştırdık. :)
Geçip gideriz bizde ağızsız,dilsiz ve sorgusuz
İstanbul gibi düşeriz iki kıtaya birden...
En aşağılık düş, en büyük sevdadan belki
Erkek ölümler; bir uzun iç çekişle büyür göğsümüz
Kullanıcı avatarı
sadettinpolat
Moderator
Mesajlar: 2131
Kayıt: 07 Ara 2003 02:51
Konum: Ankara
İletişim:

Mesaj gönderen sadettinpolat »

messagedlg fonksiyonuna default buton özelliğini eklemenin kolay bir yolu var mı?

messagebox kullanmak istemiyorum da :)
Kullanıcı avatarı
mussimsek
Admin
Mesajlar: 7601
Kayıt: 10 Haz 2003 12:26
Konum: İstanbul
İletişim:

Mesaj gönderen mussimsek »

var :)

Kod: Tümünü seç

Function DefMessageDlg(const aCaption: String;
                       const Msg: string;
                       DlgType: TMsgDlgType;
                       Buttons: TMsgDlgButtons;
                       DefButton: Integer;
                       HelpCtx: Longint): Integer;
Var
  i: Integer;
  btn: TButton;
Begin
  With CreateMessageDialog(Msg, DlgType, Buttons) Do
  try
    Caption := aCaption;
    HelpContext := HelpCtx;
    For i := 0 To ComponentCount-1 Do Begin
      If Components[i] Is TButton Then Begin
        btn := TButton(Components[i]);
        btn.Default:= btn.ModalResult = DefButton;
        If btn.Default Then
          ActiveControl := Btn;
      End;
    End; { For }
    Result := ShowModal;
  finally
    Free;
  end;
End;
//Kullanımı

Kod: Tümünü seç

procedure TForm1.Button2Click(Sender: TObject);
begin
  If DefMessageDlg( 'Please confirm',
                    'Do you want to format your harddisk now?',
                    mtConfirmation,
                    mbYesNoCancel,
                    [b]mrno[/b],
                    0 ) = mrYes
  Then
    ShowMessage('Formatting disk...');
end;
NOT : Koyu yazdığım yerde default butonu belirliyorsunuz. Burda No (Hayır) butonu default olarak gelir.

Kolay gelsin.
Kullanıcı avatarı
nitro
Üye
Mesajlar: 1112
Kayıt: 23 Ağu 2004 01:18
Konum: Çanakkale
İletişim:

Mesaj gönderen nitro »

mussimsek yazdı:
MessageDlg'un tüm sabitleri Consts.pas isimli dosyadadır. Eğer elinde Delphi'nin Source kod varsa bunları değiştirip derle ve oluşan dcu dosyasını Lib klasörüne koy.

Kolay gelsin.
abi ben bu dosyayı buldum değiştirdim ama nasıl derleyeceğimi bulamadım. install componentten giriyorum, surce\vcl already ... yani bu dosya zaten var diyor.

başlık 3 yıl önce açılmış, :ara olayının güzelliği işte ;)
Kullanıcı avatarı
rsimsek
Admin
Mesajlar: 4482
Kayıt: 10 Haz 2003 01:48
Konum: İstanbul

Mesaj gönderen rsimsek »

C:\Program Files\Borland\Delphi7\Source\Vcl>dcc32 consts.pas ile derle
ve oluşan consts.dcu yu C:\Program Files\Borland\Delphi7\Lib altına kopyala :wink:
Bilgiyi paylaşarak artıralım! Hayatı kolaylaştıralım!!
Kullanıcı avatarı
mussimsek
Admin
Mesajlar: 7601
Kayıt: 10 Haz 2003 12:26
Konum: İstanbul
İletişim:

Mesaj gönderen mussimsek »

Ben yeni bir proje açıyorum, dosyayı Add To project ile ekleyip derliyorum, oluşan dcu'yu öncekinin üstüne kopyalıyorum.

Kolay gelsin.
Kullanıcı avatarı
nitro
Üye
Mesajlar: 1112
Kayıt: 23 Ağu 2004 01:18
Konum: Çanakkale
İletişim:

Mesaj gönderen nitro »

teşekkürler yaptım oldu. Çok da güzel oldu ;)
Cevapla