LibFunc MessageBox Wizard

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

LibFunc MessageBox Wizard

Post by Rain » Thu Jun 05, 2008 11:45 am

Submitted by: Rain

I wrote this script to help me create LibFunc MessageBoxes on the fly. Simply enter your message for the window title and message body and select how you want to display your message. Click "Preview" to preview your MessageBox and "Copy" to copy the code to your clipboard.

Known Issues:
Large texts may not get displayed correctly.

Tested on Windows XP SP2
Written with version 10.1.15

Script Discussion Here

Code: Select all

Dialog>Dialog1
   Caption=LibFunc MessageBox Wizard by Rain
   Width=445
   Height=538
   Top=0
   Left=0
   Edit=msEdit1,8,16,417,Window Title
   Label=Title,8,0,true
   Memo=msMemo1,8,64,417,97,Message Body
   Label=Text,8,48,true
   RadioGroup=msRadioGroup1,Icons,16,176,193,169,Warning%CRLF%Informational%CRLF%Critical%CRLF%Question%CRLF%None,0
   RadioGroup=msRadioGroup2,Modality,16,352,193,113,Application%CRLF%System%CRLF%Task Modal,0
   RadioGroup=msRadioGroup3,Miscellaneous,232,376,193,89,Nothing%CRLF%Top-most attribute set%CRLF%Right-justified title/text,0
   RadioGroup=msRadioGroup4,Buttons,232,176,193,193,OK%CRLF%OK-Cancel%CRLF%Yes-No%CRLF%Yes-No-Cancel%CRLF%Abort-Retry-Ignore%CRLF%Retry-Cancel%CRLF%Cancel-Retry-Continue,0
   Button=Preview,16,472,97,25,1
   Button=Copy,128,472,97,25,3
EndDialog>Dialog1

show>Dialog1

    LET>COPY_CODE=FALSE

LABEL>Loop
   WAIT>0.05
   GetDialogAction>Dialog1,RESULT
   IF>RESULT=1,Preview
   IF>RESULT=2,Exit
   IF>RESULT=3,Copy
GOTO>Loop

LABEL>Copy
    LET>COPY_CODE=TRUE

LABEL>Preview

 ResetDialogAction>Dialog1

    LET>FLAG=0

    //--> START GET FLAG


//--> START Set Icons Flag
  IF>Dialog1.msRadioGroup1.ItemIndex=0
    LET>FLAG=FLAG+48
  ENDIF

  IF>Dialog1.msRadioGroup1.ItemIndex=1
    LET>FLAG=FLAG+64
  ENDIF

  IF>Dialog1.msRadioGroup1.ItemIndex=2
    LET>FLAG=FLAG+16
  ENDIF

  IF>Dialog1.msRadioGroup1.ItemIndex=3
    LET>FLAG=FLAG+32
  ENDIF
//<-- END Set Icons Flag


//--> START Set Modality Flag
  IF>Dialog1.msRadioGroup2.ItemIndex=1
    LET>FLAG=FLAG+4096
  ENDIF

  IF>Dialog1.msRadioGroup2.ItemIndex=2
    LET>FLAG=FLAG+8192
  ENDIF
//<-- END Set  Modality Flag


//--> START Set Miscellaneous Flag
  IF>Dialog1.msRadioGroup3.ItemIndex=1
    LET>FLAG=FLAG+262144
  ENDIF

  IF>Dialog1.msRadioGroup3.ItemIndex=2
    LET>FLAG=FLAG+5244288
  ENDIF
//<-- END Set  Miscellaneous Flag


//--> START Set Buttons Flag
  IF>Dialog1.msRadioGroup4.ItemIndex=1
    LET>FLAG=FLAG+1
  ENDIF

  IF>Dialog1.msRadioGroup4.ItemIndex=2
    LET>FLAG=FLAG+4
  ENDIF

  IF>Dialog1.msRadioGroup4.ItemIndex=3
    LET>FLAG=FLAG+3
  ENDIF

  IF>Dialog1.msRadioGroup4.ItemIndex=4
    LET>FLAG=FLAG+2
  ENDIF

  IF>Dialog1.msRadioGroup4.ItemIndex=5
    LET>FLAG=FLAG+5
  ENDIF

  IF>Dialog1.msRadioGroup4.ItemIndex=6
    LET>FLAG=FLAG+6
  ENDIF
//<-- END Set  Buttons Flag


   //<---- END GET FLAG


//<-- START  Replace Comma in Title and Message Body
    LET>MEMO_C_O_M_M_A=,
    LET>EDIT_C_O_M_M_A=,
  StringReplace>Dialog1.msMemo1,%MEMO_C_O_M_M_A%,;,Dialog1.msMemo1
  StringReplace>Dialog1.msEdit1,%EDIT_C_O_M_M_A%,;,Dialog1.Dialog1.msEdit1
//<-- END  Replace Comma in Title and Message Body


//<-- START  Copy Code to Clipboard
    IF>COPY_CODE=TRUE
  PutClipBoard>LibFunc>user32,MessageBoxA,r,0,%Dialog1.msMemo1%,%Dialog1.msEdit1%,%FLAG%
    LET>COPY_CODE=FALSE
GOTO>Loop
  ENDIF
//<-- END  Copy Code to Clipboard


//<-- START  Preview MessageBox
  LibFunc>user32,MessageBoxA,r,0,Dialog1.msMemo1,Dialog1.msEdit1,%FLAG%
//<-- END Preview MessageBox

GOTO>Loop

LABEL>Exit
Last edited by Rain on Mon Jan 28, 2013 3:26 pm, edited 1 time in total.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Thu Oct 02, 2008 1:34 am

Nice work Rain.

Could you explain how the Modality and Misc functions affect the Message Box? How does performance behave with the different options?

I think I will be looking at how to modify the box to have options for the Close/Minimize/Resize buttons, etc. This is a good starting point.

Thanks for the Wizard utility.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Rain
Automation Wizard
Posts: 550
Joined: Tue Aug 09, 2005 5:02 pm
Contact:

Post by Rain » Sun Jan 27, 2013 4:10 pm

Updated to work with Macro Scheduler 12 or higher.

Added LabelToVar to store the message body.

Added default buttons option. Default buttons are in reverse when Right-justified title/text is selected under Miscellaneous.

Added an option to include the button results.

Commas are no longer replaced with semicolon ( ; )

There no longer seems to be a problem with large texts. It's possible the large text issue in my previous example was caused by Windows XP. I can't confirm this since I no longer have Windows XP.

Code: Select all

let>APP_TITLE=LibFunc MessageBox Wizard
Dialog>Dialog1
object Dialog1: TForm
  Left = 234
  Top = 84
  HelpContext = 5000
  BorderIcons = [biSystemMenu, biMinimize]
  BorderStyle = bsSingle
  Caption = 'LibFunc MessageBox Wizard by Rain'
  ClientHeight = 462
  ClientWidth = 421
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = True
  PixelsPerInch = 96
  TextHeight = 13
  object msLabel1: TLabel
    Left = 8
    Top = 8
    Width = 72
    Height = 13
    Caption = 'Window Title'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = [fsBold]
    ParentFont = False
    Transparent = True
  end
  object msLabel2: TLabel
    Left = 8
    Top = 48
    Width = 81
    Height = 13
    Caption = 'Message Body'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = [fsBold]
    ParentFont = False
    Transparent = True
  end
  object msEdit1: TEdit
    Left = 8
    Top = 24
    Width = 409
    Height = 21
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = [fsBold]
    ParentFont = False
    TabOrder = 2
    Text = 'Title of the message box'
  end
  object msMemo1: tMSMemo
    Left = 8
    Top = 64
    Width = 409
    Height = 153
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = [fsBold]
    Lines.Strings = (
      'Enter your message')
    ParentFont = False
    ScrollBars = ssVertical
    TabOrder = 3
    Text = 'Enter your message'
  end
  object msRadioGroup1: tMSRadioGroup
    Tag = 4
    Left = 176
    Top = 224
    Width = 97
    Height = 137
    Caption = 'Icons'
    ItemIndex = 0
    Items.Strings = (
      'None'
      'Warning'
      'Informational'
      'Critical'
      'Question')
    TabOrder = 5
    Text = 'None'#13#10'Warning'#13#10'Informational'#13#10'Critical'#13#10'Question'#13#10
  end
  object msRadioGroup2: tMSRadioGroup
    Tag = 2
    Left = 280
    Top = 224
    Width = 137
    Height = 65
    Caption = 'Modality'
    ItemIndex = 2
    Items.Strings = (
      'Application'
      'System'
      'Task Modal')
    TabOrder = 6
    Text = 'Application'#13#10'System'#13#10'Task Modal'#13#10
  end
  object msRadioGroup3: tMSRadioGroup
    Tag = 1
    Left = 280
    Top = 296
    Width = 137
    Height = 65
    Caption = 'Miscellaneous'
    ItemIndex = 1
    Items.Strings = (
      'Nothing'
      'Top-most attribute set'
      'Right-justified title/text')
    TabOrder = 7
    Text = 'Nothing'#13#10'Top-most attribute set'#13#10'Right-justified title/text'#13#10
  end
  object msRadioGroup4: tMSRadioGroup
    Left = 8
    Top = 224
    Width = 161
    Height = 137
    Caption = 'Buttons'
    ItemIndex = 0
    Items.Strings = (
      'OK'
      'OK-Cancel'
      'Yes-No'
      'Yes-No-Cancel'
      'Abort-Retry-Ignore'
      'Retry-Cancel'
      'Cancel-Try Again-Continue')
    TabOrder = 4
    Text = 
      'OK'#13#10'OK-Cancel'#13#10'Yes-No'#13#10'Yes-No-Cancel'#13#10'Abort-Retry-Ignore'#13#10'Retry-' +
      'Cancel'#13#10'Cancel-Try Again-Continue'#13#10
  end
  object msButton1: tMSButton
    Left = 184
    Top = 408
    Width = 89
    Height = 25
    Caption = 'Preview'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = [fsBold]
    ModalResult = 1
    ParentFont = False
    ParentShowHint = False
    ShowHint = False
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object msButton2: tMSButton
    Left = 288
    Top = 408
    Width = 97
    Height = 25
    Caption = 'Copy Code'
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = [fsBold]
    ModalResult = 3
    ParentFont = False
    ParentShowHint = False
    ShowHint = False
    TabOrder = 1
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object msCheckBox1: TCheckBox
    Left = 184
    Top = 380
    Width = 153
    Height = 17
    Caption = 'Include Button Results'
    Checked = True
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = [fsBold]
    ParentFont = False
    State = cbChecked
    TabOrder = 9
  end
  object msRadioGroup5: tMSRadioGroup
    Tag = -1
    Left = 8
    Top = 360
    Width = 161
    Height = 73
    Caption = 'Default Button'
    ItemIndex = 0
    Items.Strings = (
      'First Button')
    TabOrder = 8
    Text = 'First Button'#13#10
  end
  object StatusBar1: TStatusBar
    Left = 0
    Top = 443
    Width = 421
    Height = 19
    Panels = <>
    SimplePanel = True
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,msButton1,OnClick,Preview(PrevieOnly)
AddDialogHandler>Dialog1,msButton2,OnClick,Preview(CopyCode)
AddDialogHandler>Dialog1,,OnClose,Exit

AddDialogHandler>Dialog1,msEdit1,OnMouseDown,ClearTitleMessage
AddDialogHandler>Dialog1,msEdit1,OnKeyUp,ClearTitleMessage
AddDialogHandler>Dialog1,msMemo1,OnMouseDown,ClearBodyMessage
AddDialogHandler>Dialog1,msMemo1,OnKeyUp,ClearBodyMessage
AddDialogHandler>Dialog1,msRadioGroup3,OnClick,MiscellaneousClicked

SHOW>Dialog1
LET>ListBoxOptionA=FALSE
LET>ListBoxOptionB=FALSE
LET>ListBoxOptionC=FALSE
LET>ClearTitle=False
LET>ClearBody=False

LABEL>Loop
WAIT>0.05

GetDialogProperty>Dialog1,msRadioGroup4,ItemIndex,ButtonsRes
  IF>ListBoxOptionA=FALSE
    IF>ButtonsRes=0
    LET>ListBoxOptionA=TRUE
    LET>ListBoxOptionB=FALSE
    LET>ListBoxOptionC=FALSE
    SetDialogProperty>Dialog1,msRadioGroup5,ItemIndex,0
    SetDialogProperty>Dialog1,msRadioGroup5,Text,First Button
    endif
  ENDIF

  IF>ListBoxOptionB=FALSE
    IF>{(%ButtonsRes%=1)OR(%ButtonsRes%=2)OR(%ButtonsRes%=5)}
    LET>ListBoxOptionA=FALSE
    LET>ListBoxOptionB=TRUE
    LET>ListBoxOptionC=FALSE
    SetDialogProperty>Dialog1,msRadioGroup5,ItemIndex,0
    SetDialogProperty>Dialog1,msRadioGroup5,Text,First Button%CRLF%Second Button
    endif
  ENDIF

  IF>ListBoxOptionC=FALSE
    IF>{(%ButtonsRes%=3)OR(%ButtonsRes%=4)OR(%ButtonsRes%=6)}
    LET>ListBoxOptionA=FALSE
    LET>ListBoxOptionB=FALSE
    LET>ListBoxOptionC=TRUE
    SetDialogProperty>Dialog1,msRadioGroup5,ItemIndex,0
    SetDialogProperty>Dialog1,msRadioGroup5,Text,First Button%CRLF%Second Button%CRLF%Third Button
    endif
  ENDIF




GOTO>Loop


SRT>Preview

LET>FLAG=0

//<--START GET FLAGS

//<--START Set Icons Flag
GetDialogProperty>Dialog1,msRadioGroup1,ItemIndex,IconsRes
IF>IconsRes=1
LET>FLAG=FLAG+48
ENDIF

IF>IconsRes=2
LET>FLAG=FLAG+64
ENDIF

IF>IconsRes=3
LET>FLAG=FLAG+16
ENDIF

IF>IconsRes=4
LET>FLAG=FLAG+32
ENDIF
//<--ENDI Set Icons Flag

//<--START Set Modality Flag
GetDialogProperty>Dialog1,msRadioGroup2,ItemIndex,ModalityRes
IF>ModalityRes=1
LET>FLAG=FLAG+4096
ENDIF

IF>ModalityRes=2
LET>FLAG=FLAG+8192
ENDIF
//<--END Set Modality Flag

//<--START Set Miscellaneous Flag
GetDialogProperty>Dialog1,msRadioGroup3,ItemIndex,MiscellaneousRes
IF>MiscellaneousRes=1
LET>FLAG=FLAG+262144
ENDIF

IF>MiscellaneousRes=2
LET>FLAG=FLAG+5244288
ENDIF
//<--END Set Miscellaneous Flag

//<--START Set Buttons Flag
GetDialogProperty>Dialog1,msRadioGroup4,ItemIndex,ButtonsRes
IF>ButtonsRes=1
LET>FLAG=FLAG+1
ENDIF

IF>ButtonsRes=2
LET>FLAG=FLAG+4
ENDIF

IF>ButtonsRes=3
LET>FLAG=FLAG+3
ENDIF

IF>ButtonsRes=4
LET>FLAG=FLAG+2
ENDIF

IF>ButtonsRes=5
LET>FLAG=FLAG+5
ENDIF

IF>ButtonsRes=6
LET>FLAG=FLAG+6
ENDIF
//<--END Set Buttons Flag

//<--START Set Default Button Flag
GetDialogProperty>Dialog1,msRadioGroup3,ItemIndex,MiscellaneousRes
IF>MiscellaneousRes=2
  //Set Default button in reverse (Right-justified)
  GetDialogProperty>Dialog1,msRadioGroup5,ItemIndex,DefaultButtonRes
  
  IF>DefaultButtonRes=1
   LET>FLAG=FLAG-1024
  ENDIF

  IF>DefaultButtonRes=2
   LET>FLAG=FLAG-768
  ENDIF

ELSE

  GetDialogProperty>Dialog1,msRadioGroup5,ItemIndex,DefaultButtonRes
  IF>DefaultButtonRes=1
   LET>FLAG=FLAG+256
  ENDIF

  IF>DefaultButtonRes=2
   LET>FLAG=FLAG+512
  ENDIF

ENDIF
//<--END Set Default Button Flag


//<---- END GET FLAGS



GetDialogProperty>Dialog1,msEdit1,Text,TheTitle
GetDialogProperty>Dialog1,msMemo1,Text,Memo1Text

IF>%Preview_Var_1%=CopyCode
 //<--START Create Code to Copy
Let>MsgFunc=
Concat>MsgFunc,/*%CRLF%
Concat>MsgFunc,MSG_BODY.DATA:%CRLF%
Concat>MsgFunc,%Memo1Text%%CRLF%
Concat>MsgFunc,*/%CRLF%
Concat>MsgFunc,LabelToVar>MSG_BODY.DATA,MsgBody%CRLF%
Concat>MsgFunc,LibFunc>user32,MessageBoxA,res,0,%MsgBody%,%TheTitle%,%FLAG%%CRLF%
GetDialogProperty>Dialog1,msCheckBox1,Checked,IncludeResultOptions
IF>IncludeResultOptions=True
GetDialogProperty>Dialog1,msRadioGroup4,ItemIndex,ButtonsRes
IF>ButtonsRes=0
/*
BUTTON_RESULT_OPTIONS_0.DATA:
IF>res=1
//Ok
endif
*/
LabelToVar>BUTTON_RESULT_OPTIONS_0.DATA,ButtonResultOptions
ENDIF

IF>ButtonsRes=1
/*
BUTTON_RESULT_OPTIONS_1.DATA:
IF>res=1
//Ok
endif
IF>res=2
//Cancel
endif
*/
LabelToVar>BUTTON_RESULT_OPTIONS_1.DATA,ButtonResultOptions
ENDIF

IF>ButtonsRes=2
/*
BUTTON_RESULT_OPTIONS_2.DATA:
IF>res=6
//Yes
endif
IF>res=7
//No
endif
*/
LabelToVar>BUTTON_RESULT_OPTIONS_2.DATA,ButtonResultOptions
ENDIF

IF>ButtonsRes=3
/*
BUTTON_RESULT_OPTIONS_3.DATA:
IF>res=2
//Cancel
endif
IF>res=6
//Yes
endif
IF>res=7
//No
endif
*/
LabelToVar>BUTTON_RESULT_OPTIONS_3.DATA,ButtonResultOptions
ENDIF

IF>ButtonsRes=4
/*
BUTTON_RESULT_OPTIONS_4.DATA:
IF>res=3
//Abort
endif
IF>res=4
//Retry
endif
IF>res=5
//Ignore
endif
*/
LabelToVar>BUTTON_RESULT_OPTIONS_4.DATA,ButtonResultOptions
ENDIF

IF>ButtonsRes=5
/*
BUTTON_RESULT_OPTIONS_5.DATA:
IF>res=2
//Cancel
endif
IF>res=4
//Retry
endif
*/
LabelToVar>BUTTON_RESULT_OPTIONS_5.DATA,ButtonResultOptions
ENDIF

IF>ButtonsRes=6
/*
BUTTON_RESULT_OPTIONS_6.DATA:
IF>res=2
//Cancel
endif
IF>res=10
//Try Again
endif
IF>res=11
//Continue
endif
*/
LabelToVar>BUTTON_RESULT_OPTIONS_6.DATA,ButtonResultOptions
ENDIF



Concat>MsgFunc,%ButtonResultOptions%%CRLF%
ENDIF
PutClipBoard>MsgFunc
GetTime>TheTime
SetDialogProperty>Dialog1,StatusBar1,SimpleText,Code copied %TheTime%
//<--END Create Code to Copy

ELSE

//<--START Preview Message Box
LibFunc>user32,MessageBoxA,r,0,%Memo1Text%,%TheTitle%,%FLAG%
//<--END Preview Message Box
ENDIF
END>Preview

SRT>MiscellaneousClicked
  GetDialogProperty>Dialog1,msRadioGroup3,ItemIndex,MiscellaneousRes
  IF>MiscellaneousRes=2
   //Reverse if Right-justified title/text is selected
   SetDialogProperty>Dialog1,msRadioGroup4,Text,OK%CRLF%Cancel-OK%CRLF%No-Yes%CRLF%Cancel-No-Yes%CRLF%Ignore-Retry-Abort%CRLF%Cancel-Retry%CRLF%Continue-Try Again-Cancel
  ELSE
   SetDialogProperty>Dialog1,msRadioGroup4,Text,OK%CRLF%OK-Cancel%CRLF%Yes-No%CRLF%Yes-No-Cancel%CRLF%Abort-Retry-Ignore%CRLF%Retry-Cancel%CRLF%Cancel-Try Again-Continue
  ENDIF
END>MiscellaneousClicked

SRT>ClearTitleMessage
IF>ClearTitle=False
  SetDialogProperty>Dialog1,msEdit1,Text,
  Let>ClearTitle=True
ENDIF
END>ClearTitleMessage

SRT>ClearBodyMessage
IF>ClearBody=False
  SetDialogProperty>Dialog1,msMemo1,Text,
  Let>ClearBody=True
ENDIF
END>ClearBodyMessage

SRT>Exit
  Exit>1
END>Exit

Bob Hansen wrote: Could you explain how the Modality and Misc functions affect the Message Box? How does performance behave with the different options?
I hope this helps http://msdn.microsoft.com/en-us/library ... 85%29.aspx

User avatar
Grovkillen
Automation Wizard
Posts: 1009
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

....

Post by Grovkillen » Mon Jan 28, 2013 1:58 pm

This is awesome work! Thanks for sharing!
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Tue Jan 29, 2013 12:59 am

Nice Script Rain, Will Add That Into My Samples Folder. Thanks For That.
FIREFIGHTER

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