Dialog position, 2 monitors

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
wil
Junior Coder
Posts: 25
Joined: Mon Dec 06, 2010 6:00 pm

Dialog position, 2 monitors

Post by wil » Tue Dec 27, 2011 10:39 pm

Hello,

I have 2 monitors.
Monitor 1 (1920x1200, lying) see http://img513.imageshack.us/img513/6762/monitor1k.jpg
Monitor 2 (1050x1680, stand, mirrored) see http://img851.imageshack.us/img851/8067/monitor2q.jpg

below is some testcode:

Code: Select all

//initial: get dialogs to center pos
GetScreenRes>leftresult,topresult
let>leftresult=leftresult/2
let>topresult=topresult/2
let>xdialogleft=600/2
let>ydialogheight=400/2
let>leftresult=leftresult-xdialogleft
let>topresult=topresult-ydialogheight
Let>leftresult={Round(%leftresult%)}
Let>topresult={Round(%topresult%)}
Dialog>Dialog1
object Dialog1: TForm
  Left = 1
  Top = 1
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Main Dialog'
  ClientHeight = 400
  ClientWidth = 600
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -12
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 108
  TextHeight = 13
  object MSButton1: tMSButton
    Left = 518
    Top = 366
    Width = 75
    Height = 25
    Caption = 'Exit'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 438
    Top = 366
    Width = 75
    Height = 25
    Caption = 'Open next'
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

Dialog>Dialog2
object Dialog2: TForm
  Left = 1
  Top = 1
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Sub dialog'
  ClientHeight = 260
  ClientWidth = 460
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -12
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 108
  TextHeight = 13
  object MSButton1a: tMSButton
    Left = 376
    Top = 230
    Width = 75
    Height = 25
    Caption = 'Exit'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog2

SetDialogProperty>Dialog1,,Left,%leftresult%
SetDialogProperty>Dialog1,,Top,%topresult%
AddDialogHandler>Dialog1,MSButton1,OnClick,Doclose
AddDialogHandler>Dialog1,MSButton2,OnClick,DoOpen2
Show>Dialog1,r

SRT>Doclose
  exit
END>Doclose

SRT>Doclose2
  CloseDialog>Dialog2
END>Doclose2

SRT>DoOpen2
  GetDialogProperty>Dialog1,,Top,%topresult%
  GetDialogProperty>Dialog1,,Left,%leftresult%
  SetDialogProperty>Dialog2,,Top,%topresult%
  SetDialogProperty>Dialog2,,Left,%leftresult%
  AddDialogHandler>Dialog2,MSButton1a,OnClick,Doclose2
  Show>Dialog2,r
END>DoOpen2
When i run this code the dialog (Caption = 'Main Dialog') will open in the center of monitor1. When i drag this dialog within monitor1 and next i press button "Open next" the dialog (Caption = 'Sub dialog') will open in the top/left over 'Main Dialog', so that works fine.
But when i drag 'Main Dialog' "into" Monitor2 and then press "Open next", the 'Sub dialog' will open in Monitor1.
What am i doing wrong? Has anyone a solution for this?

Thanks in advance and best regards,

wil

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Jan 18, 2012 6:39 am

I don't have two monitors to test this but what happens if you get and use the window position rather than the dialog properties? I was getting an av error when I had the AddDialogHandler>Dialog2,MSButton1a,OnClick,Doclose2 line in the DoOpen2 subroutine so I moved it out. Also removed the result variable from the Show>Dialog2 line because the dialog didn't close for me as a modal dialog.

Code: Select all

//initial: get dialogs to center pos
GetScreenRes>leftresult,topresult
let>leftresult=leftresult/2
let>topresult=topresult/2
let>xdialogleft=600/2
let>ydialogheight=400/2
let>leftresult=leftresult-xdialogleft
let>topresult=topresult-ydialogheight
Let>leftresult={Round(%leftresult%)}
Let>topresult={Round(%topresult%)}
Dialog>Dialog1
object Dialog1: TForm
  Left = 1
  Top = 1
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Main Dialog'
  ClientHeight = 400
  ClientWidth = 600
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -12
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 108
  TextHeight = 13
  object MSButton1: tMSButton
    Left = 518
    Top = 366
    Width = 75
    Height = 25
    Caption = 'Exit'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 438
    Top = 366
    Width = 75
    Height = 25
    Caption = 'Open next'
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

Dialog>Dialog2
object Dialog2: TForm
  Left = 1
  Top = 1
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Sub dialog'
  ClientHeight = 260
  ClientWidth = 460
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -12
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 108
  TextHeight = 13
  object MSButton1a: tMSButton
    Left = 376
    Top = 230
    Width = 75
    Height = 25
    Caption = 'Exit'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog2

SetDialogProperty>Dialog1,,Left,%leftresult%
SetDialogProperty>Dialog1,,Top,%topresult%
AddDialogHandler>Dialog1,MSButton1,OnClick,Doclose
AddDialogHandler>Dialog1,MSButton2,OnClick,DoOpen2
AddDialogHandler>Dialog2,MSButton1a,OnClick,Doclose2
Show>Dialog1,r

SRT>Doclose
  exit
END>Doclose

SRT>Doclose2
  CloseDialog>Dialog2
END>Doclose2

SRT>DoOpen2
  Let>WIN_USEHANDLE=1
    GetWindowPos>Dialog1.handle,WinX,WinY
    MoveWindow>Dialog2.handle,WinX,WinY
  Let>WIN_USEHANDLE=0
/*
  GetDialogProperty>Dialog1,,Top,%topresult%
  GetDialogProperty>Dialog1,,Left,%leftresult%
  SetDialogProperty>Dialog2,,Top,%topresult%
  SetDialogProperty>Dialog2,,Left,%leftresult%
*/
  Show>Dialog2
END>DoOpen2

wil
Junior Coder
Posts: 25
Joined: Mon Dec 06, 2010 6:00 pm

Post by wil » Wed Jan 18, 2012 9:50 pm

Hi JRL, First thank you for your reply.
JRL wrote:I don't have two monitors to test this but what happens if you get and use the window position rather than the dialog properties?
I tested it. At first sight, still the same result. But then i noticed when i double click "Open next" it worked. So i tried to add LClick after pressing "Open Next" and that works. I had to use another SRT before SRT DoOpen2 to had it worked.

This "LClick" is probably not the best solution but it works well enough for me.

thnx!

Below the code with lclick:

Code: Select all

//initial: get dialogs to center pos
GetScreenRes>leftresult,topresult
let>leftresult=leftresult/2
let>topresult=topresult/2
let>xdialogleft=600/2
let>ydialogheight=400/2
let>leftresult=leftresult-xdialogleft
let>topresult=topresult-ydialogheight
Let>leftresult={Round(%leftresult%)}
Let>topresult={Round(%topresult%)}
Dialog>Dialog1
object Dialog1: TForm
  Left = 1
  Top = 1
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Main Dialog'
  ClientHeight = 400
  ClientWidth = 600
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -12
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 108
  TextHeight = 13
  object MSButton1: tMSButton
    Left = 518
    Top = 366
    Width = 75
    Height = 25
    Caption = 'Exit'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object MSButton2: tMSButton
    Left = 438
    Top = 366
    Width = 75
    Height = 25
    Caption = 'Open next'
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

Dialog>Dialog2
object Dialog2: TForm
  Left = 1
  Top = 1
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Sub dialog'
  ClientHeight = 260
  ClientWidth = 460
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -12
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 108
  TextHeight = 13
  object MSButton1a: tMSButton
    Left = 376
    Top = 230
    Width = 75
    Height = 25
    Caption = 'Exit'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog2

SetDialogProperty>Dialog1,,Left,%leftresult%
SetDialogProperty>Dialog1,,Top,%topresult%
AddDialogHandler>Dialog1,MSButton1,OnClick,Doclose
AddDialogHandler>Dialog1,MSButton2,OnClick,DoOpen2a
AddDialogHandler>Dialog2,MSButton1a,OnClick,Doclose2
Show>Dialog1,r


SRT>Doclose
  exit
END>Doclose

SRT>Doclose2
  CloseDialog>Dialog2
END>Doclose2

SRT>DoOpen2a
  LClick
  GoSub>DoOpen2
END>DoOpen2a

SRT>DoOpen2
  Let>WIN_USEHANDLE=1
    GetWindowPos>Dialog1.handle,WinX,WinY
    MoveWindow>Dialog2.handle,WinX,WinY
  Let>WIN_USEHANDLE=0
/*
  GetDialogProperty>Dialog1,,Top,%topresult%
  GetDialogProperty>Dialog1,,Left,%leftresult%
  SetDialogProperty>Dialog2,,Top,%topresult%
  SetDialogProperty>Dialog2,,Left,%leftresult%
*/
  Show>Dialog2
END>DoOpen2
Best regards,

wil

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts