sMessageDlgPos in sDialogs ignores x,y parameters

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #34310
    IPSteven
    Participant

    I am using AlphaControl reg v7.29 Stable, Delphi 2010 and Windows7 x64.

    I am having a problem in that sMessageDlgPos() in sDialogs ignores both the x and y parameters.

    The Delphi function MessageDlgPos() works as expected.

    Code:
    sMessageDlgPos('Test Msg!','AlphaControl message using sMessageDlgPos()',mtInformation,[mbOK],0, 100, 50);
    MessageDlgPos('Delphi message using MessageDlgPos()',mtInformation,[mbOK],0, 100, 50);
    #44681
    Support
    Keymaster

    Hello

    AlphaControls dialogs (sMessageDlgPos) uses standard Windows MessageBox function which can't be positioned. I can add additional code for positioning of messagebox, but this code will not work without skins (in standard mode)…

    #44683
    IPSteven
    Participant

    For my needs that would be OK, others might feel differently.

    If the function's name mimics that of a standard Delphi function, in this case sMessageDlgPos() vs MessageDlgPos(), it should have the same functionality or else it appears that something in AlphaControls is broken.

    With the program I am updating I have to offset the position of the message box or it gets hidden behind a modal form.

    Thanks

    …Steven

    #44689
    HeDiBo
    Participant
    'IPSteven' wrote:
    If the function's name mimics that of a standard Delphi function, in this case sMessageDlgPos() vs MessageDlgPos(), it should have the same functionality or else it appears that something in AlphaControls is broken.

    I agree. In fact, if skinning is off, the function should not go to a standard Windows function, but to the Delphi MessageDlgPos function :wacko:

    #44691
    IPSteven
    Participant
    Quote:
    I can add additional code for positioning of messagebox, but this code will not work without skins (in standard mode)…

    I think I misunderstood you.

    If you can't make sMessageDlgPos() a skinned version of MessageDlgPos() then there is no point in having sMessageDlgPos(). I could simply call MessageDlgPos() myself and avoid the confusion.

    The application that I am upgrading uses AlphaControls v4.79.

    With that version I created my own function SBMessageDlg() (code below) which is skinable version of MessageDlgPos().

    With SBMessageDlg() – I resolved 3 issues I had:

    1) Fixed problem with messages not being skinned in XP running with Classic theme

    2) Ability to vertically offset message for better visibility and to prevent it from appearing under status forms.

    3) Fixed problem I had where if an error occurred while the program was loading, i.e. when the Splash screen was showing, that the message would appear under the splash screen effectively locking up the program.

    Unfortunately now that I'm trying to upgrade this application to the current version of AlphaControls (v7.29 from v4.79) this function no longer works. This is not a great surprise since a lot has changed in AlphaControls since v4.79 (which is good).

    If I recall correctly TsMessageForm() doesn't exist in the current version of AlphaControls.

    Code:
    //written for use w/ AlphaControls v4.79.
    function SBMessageDlg(const Msg: string; DlgFrmCaption : string='';
    DlgType: TMsgDlgType=mtWarning; Buttons: TMsgDlgButtons=[mbOK];
    HelpCtx: Longint=0; Voffset : integer=0; DefButton: Integer=1 ): Integer;
    var
    X, Y: Integer;
    mf: TsMessageForm;
    i : integer;
    btn: TButton;

    begin
    //2.20.07 fixes grey background when using XP Windows Classic
    //9.11.09 fix for msgbox appearing under Splash form and hanging program
    X := -1;
    Y := -1;
    mf := TsMessageForm(sCreateMessageDialog(DlgFrmCaption, Msg, DlgType, Buttons));

    try
    mf.HelpContext := HelpCtx;
    mf.HelpFile := '';
    if X >= 0 then mf.Left := X;
    if Y >= 0 then mf.Top := Y;
    if (Y < 0) and (X < 0) then begin
    mf.Left := (Screen.Width div 2) – (mf.width div 2);
    mf.Top := (Screen.Height div 2) – (mf.height div 2);
    end;
    if Voffset <> 0 then
    mf.Top := mf.Top + Voffset;

    with mf do
    For i := 0 To ComponentCount-1 Do
    If Components Is TButton Then Begin
    btn := TButton(Components);
    btn.Default:= btn.ModalResult = DefButton;

    If btn.Default Then //if no match the ActiveControl is not changed!
    ActiveControl := Btn;
    End;

    //Check to see if Splash form is showing!
    //if so prevent messagebox from opening under Splash
    ////////////////////////v1.4.1.2 091109
    if frmSplash <> nil then
    if frmSplash.Visible then
    frmSplash.FormStyle := fsNormal;

    Application.ProcessMessages;
    FormOnTop(mf.Handle);
    Result := mf.ShowModal;

    if frmSplash <> nil then
    if frmSplash.Visible then
    frmSplash.FormStyle := fsStayOnTop;

    Application.ProcessMessages;
    ////////////////////////
    finally
    FreeAndNil(mf);
    end;
    exit;

    end;

    #44712
    Support
    Keymaster

    sMessageDlgPos is keeped for compatibility with old code. Difference between Windows MessageBox-based dialogs and Delphi dialogs is in automatic localization of buttons.

    Delphi dialogs haven't automatic localization but have some other features. So, programmer can select required type of dialog and use it.

    #44863
    IPSteven
    Participant

    I came up with my own fix and it appears to work fine (code below) at least using AlphaControl reg v7.31 Stable, Delphi 2010 and Windows7 x64.

    Regarding your comments…

    Not sure how this applies to localization issues, but would suspect that it is handled same way as regular Delphi message box routines.

    Quote:
    sMessageDlgPos is keeped for compatibility with old code.

    I would politely disagree since sMessageDlgPos() worked in AlphaControls v4.79 and is functionally broken in v7.31.

    It doesn't produce an error or crash so it is compatible in that fashion, but the behavior has changed.

    The message box caption is retained in the current version, but the positioning ability is lost.

    My workaround retains both features and uses the most common default settings.

    //Uses Dialogs

    Code:
    function SMessageDlgPosFix(const DlgFrmCaption : string; const Msg: string;
    DlgType: TMsgDlgType=mtInformation; Buttons: TMsgDlgButtons=[mbOK];
    HelpCtx: Longint=0; X: Integer=-1; Y: Integer=-1; DefButton: TMsgDlgBtn=mbOK ): Integer;
    var
    mf: TForm;
    begin
    mf := CreateMessageDialog(Msg, DlgType, Buttons, DefButton);
    try
    mf.Caption := DlgFrmCaption;
    mf.HelpContext := HelpCtx;
    mf.HelpFile := '';

    if X >= 0 then
    mf.Left := X
    else
    mf.Left := (Screen.Width div 2) – (mf.width div 2);

    if Y >= 0 then
    mf.Top := Y
    else
    mf.Top := (Screen.Height div 2) – (mf.height div 2);

    Result := mf.ShowModal;
    finally
    FreeAndNil(mf);
    end;
    exit;
    end;

    #44874
    Support
    Keymaster

    Standard Windows dialogs (based on MessageBox function, TForm is not used) have language of the current system automatically.

    If you uses Delphi dialogs, then you will have buttons captions like 'OK, 'Cancel' on all machines, but when used Windows system dialogs, then on russian PC you will have 'OK', 'Отмена'.

    Your solution is based on Delphi TForm. If automatic localization is not required then you can just use Delphi dialogs…

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.