Specific text in dialog causes failure

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Specific text in dialog causes failure

Post by Jerry Thomas » Thu Dec 09, 2010 6:24 pm

This one has taken me a long time to narrow down, It's probably really easy, but I am not seeing it.

I am running MS multi session and using a dialog to write in another MS window (building scripts). My problem is in trying to set the focus to the other window.

I have an edit box for the user to type in the name of the other window (or if I use SetDialogProp to set it) but the script fails.

It fails even if I don't use that value but have SetFocus hard coded! Just having the window name in the dialog makes it fail. (I know this sounds crazy)

To repro:
1. Open this dialog
2. In a 2nd session create a new script titled 'TEST SCRIPT' (all uppercase)
3. In dialog, enter random text and then press 'Write to script'
- it works
4. Click Text1 or type 'Macro - TEST SCRIPT' and press 'Write to script'
- Script fails!
- 'Wrong window' Window = 'Script Builder'' or 'Press Esc to quit'

Code: Select all

Dialog>ScriptBuilder
object ScriptBuilder: TForm
  Left = 528
  Top = 255
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'ScriptBuilder'
  ClientHeight = 205
  ClientWidth = 414
  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 btnWrite: tMSButton
    Left = 128
    Top = 124
    Width = 89
    Height = 25
    Caption = 'Write to Script'
    DoubleBuffered = True
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    ParentDoubleBuffered = False
    ParentFont = False
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object ebWindow: TEdit
    Left = 128
    Top = 41
    Width = 121
    Height = 21
    TabOrder = 1
    TextHint = 'Script Window...'
  end
  object btnText1: tMSButton
    Left = 92
    Top = 84
    Width = 75
    Height = 25
    Caption = 'Text1'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 10
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object btnText2: tMSButton
    Left = 181
    Top = 84
    Width = 75
    Height = 25
    Caption = 'Text2'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 11
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>ScriptBuilder

SetDialogProperty>ScriptBuilder,ebWindow,Text,TEST
AddDialogHandler>ScriptBuilder,btnWrite,OnClick,WriteScript
AddDialogHandler>ScriptBuilder,btnText1,OnClick,Text1
AddDialogHandler>ScriptBuilder,btnText2,OnClick,Text2

Show>ScriptBuilder,r

SRT>WriteScript
  Let>strWindow=Macro - TEST SCRIPT
  SetFocus>strWindow
  GetActiveWindow>WinTitle,,,,

  If>WinTitle=strWindow
    Let>SK_DELAY=10
    SendText>CmdStr
  Else
    Mdl>Wrong window: %WinTitle%
  Endif

  SetDialogProperty>ScriptBuilder,,Visible,True
END>WriteScript

SRT>Text1
  SetDialogProperty>ScriptBuilder,ebWindow,Text,Macro - TEST SCRIPT
END>Text1

SRT>Text2
  SetDialogProperty>ScriptBuilder,ebWindow,Text,Macro - SOME OTHER TEXT
END>Text2
Thanks,
Jerry

[email protected]

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

Post by JRL » Thu Dec 09, 2010 7:05 pm

Get the handle of the 'TEST SCRIPT' editor window early in the script and use the handle rather than the window's text title. I suspect that the focus is going to the edit box once the edit box has the window name in it.

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

Post by Marcus Tettmar » Thu Dec 09, 2010 7:19 pm

Or add this above your SetFocus line:

Let>WF_TYPE=0

This will tell it to ignore child windows.

As Dick says SetFocus is finding the text box. Since it is a child window, adding WF_TYPE=0 will prevent it from being seen.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Thu Dec 09, 2010 7:34 pm

But the incorrect focus is only when the text = the window name.

Anything except the actual window name contiues to work. Even if I just add or omit one letter (ie; 'Macro - TEST SCRIPTx') it will work.

I will try your suggestions.
Thanks,
Jerry

[email protected]

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Thu Dec 09, 2010 7:35 pm

I just reread JRL. That does make sense. Ignore prev. comment.

WF_TYPE=0 does it.
MANY THANKS!
Last edited by Jerry Thomas on Thu Dec 09, 2010 7:48 pm, edited 1 time in total.
Thanks,
Jerry

[email protected]

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

Post by Marcus Tettmar » Thu Dec 09, 2010 7:37 pm

Yes. Exactly. By default SetFocus matches ALL windows. And in Microsoft-speak any object is also a window. So by default when you type "Macro - TEST SCRIPT" into the edit box your SetFocus line will find *IT* because IT's caption now matches and is closer in the z-order (the dialog is active). So the simple solution is to tell SetFocus NOT to match against child windows. Since the edit box is a child window[object]. So set WF_TYPE to 0 and you should be fine because then the edit box will be ignored.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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