GetWindowSize returns size of combobox

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
bossydog9
Junior Coder
Posts: 29
Joined: Wed Jan 08, 2020 12:46 pm

GetWindowSize returns size of combobox

Post by bossydog9 » Mon Feb 10, 2020 3:34 pm

I'm using the following code to select a window title from a combo box and run a subroutine to get the window size. I then update a label with the width & height of the selected window. For some reason, the width & height being returned by the GetWindowSize function is the width & height of the combo box (375 x 21). I've debugged the subroutine and the window title parameter is correct.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 441
  Top = 107
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'GetWindowSize Test'
  ClientHeight = 211
  ClientWidth = 476
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 34
    Top = 32
    Width = 95
    Height = 13
    Caption = 'Select Window Title'
  end
  object Label2: TLabel
    Left = 34
    Top = 100
    Width = 165
    Height = 13
    Caption = 'The size of the selected window is:'
  end
  object lblSize: TLabel
    Left = 236
    Top = 96
    Width = 6
    Height = 20
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlack
    Font.Height = -16
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object MSComboBox1: tMSComboBox
    Left = 34
    Top = 50
    Width = 375
    Height = 21
    Sorted = True
    TabOrder = 0
  end
  object MSButton1: tMSButton
    Left = 357
    Top = 167
    Width = 75
    Height = 25
    Caption = 'Exit'
    ModalResult = 2
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

GetWindowList>WindowList
SetDialogProperty>Dialog1,MSComboBox1,ListText,WindowList
AddDialogHandler>Dialog1,MSComboBox1,OnSelect,SetDialogCaption

show>Dialog1,DialogResult

SRT>SetDialogCaption
  GetDialogProperty>Dialog1,msComboBox1,Text,WindowTitle
  GetWindowSize>%WindowTitle%,nWidth,nHeight
  Let>strCaption=%nWidth% x %nHeight%
  SetDialogProperty>Dialog1,lblSize,Caption,strCaption
END>SetDialogCaption


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

Re: GetWindowSize returns size of combobox

Post by JRL » Mon Feb 10, 2020 9:04 pm

I can't explain why what you've posted does what it does. It's bizarre and seems to me to be a bug. We'll have to wait and see if Marcus weighs in.

I did some experimenting and found that if you change the text of the combobox prior to getting the window size, you get the size of the selected window rather than the size of the combobox. I added the line:

SetDialogProperty>Dialog1,MSComboBox1,Text,

as the second line in the subroutine.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 441
  Top = 107
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'GetWindowSize Test'
  ClientHeight = 211
  ClientWidth = 476
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 34
    Top = 32
    Width = 95
    Height = 13
    Caption = 'Select Window Title'
  end
  object Label2: TLabel
    Left = 34
    Top = 100
    Width = 165
    Height = 13
    Caption = 'The size of the selected window is:'
  end
  object lblSize: TLabel
    Left = 236
    Top = 96
    Width = 6
    Height = 20
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlack
    Font.Height = -16
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object MSComboBox1: tMSComboBox
    Left = 34
    Top = 50
    Width = 375
    Height = 21
    Sorted = True
    TabOrder = 0
  end
  object MSButton1: tMSButton
    Left = 357
    Top = 167
    Width = 75
    Height = 25
    Caption = 'Exit'
    ModalResult = 2
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1
GetWindowList>WindowList
SetDialogProperty>Dialog1,MSComboBox1,ListText,WindowList
AddDialogHandler>Dialog1,MSComboBox1,OnSelect,SetDialogCaption
show>Dialog1,
SRT>SetDialogCaption
  GetDialogProperty>Dialog1,msComboBox1,Text,WindowTitle
  SetDialogProperty>Dialog1,MSComboBox1,Text,
  GetWindowSize>%WindowTitle%,nWidth,nHeight
  Let>strCaption=%nWidth% x %nHeight%
  SetDialogProperty>Dialog1,lblSize,Caption,strCaption
END>SetDialogCaption

bossydog9
Junior Coder
Posts: 29
Joined: Wed Jan 08, 2020 12:46 pm

Re: GetWindowSize returns size of combobox

Post by bossydog9 » Mon Feb 10, 2020 11:08 pm

Ok, so that seems to infer that the GetWindowSize function may be including the combo box object in its search for the window. I just tested it again and that's exactly what it's doing. I also added an Edit box and set its Text value to the Window Title, and the GetWindowSize function returned the size of the Edit box (342 x 21).

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 441
  Top = 107
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'GetWindowSize Test'
  ClientHeight = 211
  ClientWidth = 476
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 34
    Top = 32
    Width = 95
    Height = 13
    Caption = 'Select Window Title'
  end
  object Label2: TLabel
    Left = 34
    Top = 100
    Width = 165
    Height = 13
    Caption = 'The size of the selected window is:'
  end
  object lblSize: TLabel
    Left = 236
    Top = 96
    Width = 6
    Height = 20
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clBlack
    Font.Height = -16
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
  end
  object MSComboBox1: tMSComboBox
    Left = 34
    Top = 50
    Width = 375
    Height = 21
    Sorted = True
    TabOrder = 0
  end
  object MSButton1: tMSButton
    Left = 357
    Top = 167
    Width = 75
    Height = 25
    Caption = 'Exit'
    ModalResult = 2
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object Edit1: TEdit
    Left = 35
    Top = 130
    Width = 342
    Height = 21
    TabOrder = 10
    Text = 'Edit1'
  end
end
EndDialog>Dialog1

GetWindowList>WindowList
SetDialogProperty>Dialog1,MSComboBox1,ListText,WindowList
AddDialogHandler>Dialog1,MSComboBox1,OnSelect,SetDialogCaption

show>Dialog1,DialogResult

SRT>SetDialogCaption
  GetDialogProperty>Dialog1,MSComboBox1,Text,WindowTitle
  SetDialogProperty>Dialog1,MSComboBox1,Text,
  SetDialogProperty>Dialog1,Edit1,Text,WindowTitle
  GetWindowSize>%WindowTitle%,nWidth,nHeight
  Let>strCaption=%nWidth% x %nHeight%
  SetDialogProperty>Dialog1,lblSize,Caption,strCaption
END>SetDialogCaption


User avatar
Marcus Tettmar
Site Admin
Posts: 7122
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: GetWindowSize returns size of combobox

Post by Marcus Tettmar » Tue Feb 11, 2020 8:20 am

Remember that a 'window' in Microsoft speak is any object that has a handle. Combo boxes are therefore also windows. So if the text in your combo box matches that you are searching for it may be the thing that is found first. This explains why when you changed the text the search found something else. One thing you can do is narrow your search to parent windows. See the WF_TYPE options in the help.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

bossydog9
Junior Coder
Posts: 29
Joined: Wed Jan 08, 2020 12:46 pm

Re: GetWindowSize returns size of combobox

Post by bossydog9 » Tue Feb 11, 2020 4:46 pm

Hello Marcus,

Given the significance of what you said in your response, it might be an idea to make a reference to the WF_TYPE variable in the help for GetWindowSize as you have for other functions such as WaitWindowOpen and WaitWindowClosed.

There does remain an inconsistency, however, in that the GetWindowList function only returns a list of open top-level window titles and therefore isn't affected by the value of WF_TYPE. GetWindowList and GetWindowSize appear to be sister functions so you would expect them both to deal with the same window level by default. GetWindowList seems to function as if WF_TYPE is set to zero (No Child Windows) whereas, by default, GetWindowSize seems to function as if WF_TYPE is set to 1 (ALL Windows).

Regards,

Post Reply