File: n_msgbox.sru
Size: 8903
Date: Mon, 31 Dec 2018 21:14:38 +0100
$PBExportHeader$n_msgbox.sru
forward
global type n_msgbox from nonvisualobject
end type
end forward

global type n_msgbox from nonvisualobject autoinstantiate
end type

type prototypes
Function long MessageBox ( &
   long hWnd, &
   string lpText, &
   string lpCaption, &
   ulong uType &
   ) Library "user32.dll" Alias For "MessageBoxA"

Function long MessageBoxTimeout ( &
   long hWnd, &
   string lpText, &
   string lpCaption, &
   ulong uType, &
   integer wLanguageId, &
   long dwMilliseconds &
   ) Library "user32.dll" Alias For "MessageBoxTimeoutA"

Function long MessageBeep ( &
   ulong uType &
   ) Library "user32.dll"

end prototypes
type variables
// Returns:

Constant long IDABORT = 3
Constant long IDCANCEL = 2
Constant long IDCONTINUE = 11
Constant long IDIGNORE = 5
Constant long IDNO = 7
Constant long IDOK = 1
Constant long IDRETRY = 4
Constant long IDTRYAGAIN = 10
Constant long IDYES = 6

// Buttons:
Constant ulong MB_ABORTRETRYIGNORE = 2
Constant ulong MB_CANCELTRYCONTINUE = 2
Constant ulong MB_HELP = 16384
Constant ulong MB_OK = 0
Constant ulong MB_OKCANCEL = 1
Constant ulong MB_RETRYCANCEL = 5
Constant ulong MB_YESNO = 4
Constant ulong MB_YESNOCANCEL = 3

// Button Defaults:
Constant ulong MB_DEFBUTTON1 = 0
Constant ulong MB_DEFBUTTON2 = 256
Constant ulong MB_DEFBUTTON3 = 512
Constant ulong MB_DEFBUTTON4 = 768

// Icons:
Constant ulong MB_ICONEXCLAMATION = 48
Constant ulong MB_ICONWARNING = 48
Constant ulong MB_ICONINFORMATION = 64
Constant ulong MB_ICONASTERISK = 64
Constant ulong MB_ICONQUESTION = 32
Constant ulong MB_ICONSTOP = 16
Constant ulong MB_ICONERROR = 16
Constant ulong MB_ICONHAND = 16

// Other:
Constant ulong MB_APPLMODAL = 0
Constant ulong MB_SYSTEMMODAL = 4096
Constant ulong MB_TASKMODAL = 8192
Constant ulong MB_SETFOREGROUND = 65536

end variables

forward prototypes
public function integer of_messagebox (string as_title, string as_text, icon a_icon, button a_button, integer ai_default)
public function integer of_messageboxtimeout (string as_title, string as_text, icon a_icon, button a_button, integer ai_default, integer ai_seconds)
public function integer of_messagebox (string as_title, string as_text, icon a_icon, button a_button)
public function integer of_messagebox (string as_title, string as_text, icon a_icon)
public function integer of_messagebox (string as_title, string as_text)
public function integer of_messageboxtimeout (string as_title, string as_text, icon a_icon, button a_button, integer ai_seconds)
public function integer of_messageboxtimeout (string as_title, string as_text, icon a_icon, integer ai_seconds)
public function integer of_messageboxtimeout (string as_title, string as_text, integer ai_seconds)
public subroutine of_messagebeep (icon a_icon)
end prototypes

public function integer of_messagebox (string as_title, string as_text, icon a_icon, button a_button, integer ai_default);// -----------------------------------------------------------------------------
// SCRIPT:     n_msgbox.MessageBox
//
// PURPOSE:    This function displays a MessageBox using the API function.
//
// ARGUMENTS:  as_title    - The title of the message
//             as_text     - The text of the message
//             a_icon      - The icon to be displayed
//             a_button    - The buttons to be displayed
//             ai_default  - The default button
//
// RETURN:     Button number chosen
//
// DATE        PROG/ID     DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 07/13/2016  RolandS     Initial Coding
// -----------------------------------------------------------------------------

Return of_MessageBoxTimeout(as_title, as_text, a_icon, a_button, ai_default, 0)

end function

public function integer of_messageboxtimeout (string as_title, string as_text, icon a_icon, button a_button, integer ai_default, integer ai_seconds);// -----------------------------------------------------------------------------
// SCRIPT:     n_msgbox.of_MessageBoxTimeout
//
// PURPOSE:    This function displays a MessageBox. If ai_seconds = zero then
//             it calls the standard API function. Otherwise it calls an
//             undocumented API function MessageBoxTimeout added in Windows XP.
//
// ARGUMENTS:  as_title    - The title of the message
//             as_text     - The text of the message
//             a_icon      - The icon to be displayed
//             a_button    - The buttons to be displayed
//             ai_default  - The default button
//             ai_seconds  - The number of seconds to timeout the message
//
//             The maximum number for an integer is 32768 which equates to
//             9 hours, 6 minutes, and 8 seconds.
//
// RETURN:     Returns the number of the selected button (1, 2, or 3) if
//             it succeeds and -1 if an error occurs.
//
// DATE        PROG/ID     DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 07/13/2016  RolandS     Initial Coding
// -----------------------------------------------------------------------------

Long ll_rc
ULong lul_Type
Integer li_return, li_timeout

lul_Type = MB_SETFOREGROUND + MB_TASKMODAL
li_timeout = ai_seconds * 1000

// set the Button
choose case a_button
   case OKCancel!
      lul_Type += MB_OKCANCEL
   case YesNo!
      lul_Type += MB_YESNO
   case YesNoCancel!
      lul_Type += MB_YESNOCANCEL
   case RetryCancel!
      lul_Type += MB_RETRYCANCEL
   case AbortRetryIgnore!
      lul_Type += MB_ABORTRETRYIGNORE
   case else
      lul_Type += MB_OK
end choose

// set the Default button
choose case ai_default
   case 2
      lul_Type += MB_DEFBUTTON2
   case 3
      lul_Type += MB_DEFBUTTON3
   case else
      lul_Type += MB_DEFBUTTON1
end choose

// set the Icon
choose case a_icon
   case Information!
      lul_Type += MB_ICONINFORMATION
   case StopSign!
      lul_Type += MB_ICONSTOP
   case Exclamation!
      lul_Type += MB_ICONEXCLAMATION
   case Question!
      lul_Type += MB_ICONQUESTION
end choose

If ai_seconds > 0 Then
   // display the message with timeout
   ll_rc = MessageBoxTimeout(0, as_text, as_title, lul_Type, 0, li_timeout)
Else
   // display the message without
   ll_rc = MessageBox(0, as_text, as_title, lul_Type)
End If

// determine the return value
choose case ll_rc
   case 0
      li_return = -1
   case IDCANCEL
      If a_button = YesNoCancel! Then
         li_return = 3
      Else
         li_return = 2
      End If
   case IDIGNORE
      li_return = 3
   case IDNO, IDRETRY
      li_return = 2
   case else
      li_return = 1
end choose

Return li_return

end function

public function integer of_messagebox (string as_title, string as_text, icon a_icon, button a_button);Return of_MessageBox(as_title, as_text, a_icon, a_button, 1)

end function

public function integer of_messagebox (string as_title, string as_text, icon a_icon);Return of_MessageBox(as_title, as_text, a_icon, OK!, 1)

end function

public function integer of_messagebox (string as_title, string as_text);Return of_MessageBox(as_title, as_text, Information!, OK!, 1)

end function

public function integer of_messageboxtimeout (string as_title, string as_text, icon a_icon, button a_button, integer ai_seconds);Return of_MessageBoxTimeout(as_title, as_text, a_icon, a_button, 1, ai_seconds)

end function

public function integer of_messageboxtimeout (string as_title, string as_text, icon a_icon, integer ai_seconds);Return of_MessageBoxTimeout(as_title, as_text, a_icon, OK!, ai_seconds)

end function

public function integer of_messageboxtimeout (string as_title, string as_text, integer ai_seconds);Return of_MessageBoxTimeout(as_title, as_text, Information!, OK!, ai_seconds)

end function

public subroutine of_messagebeep (icon a_icon);// -----------------------------------------------------------------------------
// SCRIPT:     n_msgbox.of_MessageBeep
//
// PURPOSE:    This function plays the sound associated with the icon.
//
// ARGUMENTS:  a_icon   - The icon sound to be played
//
// RETURN:     Returns the number of the selected button (1, 2, or 3) if
//             it succeeds and -1 if an error occurs.
//
// DATE        PROG/ID     DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 07/13/2016  RolandS     Initial Coding
// -----------------------------------------------------------------------------

ULong lul_Type

// set the Icon
choose case a_icon
   case Information!
      lul_Type = MB_ICONINFORMATION
   case StopSign!
      lul_Type = MB_ICONSTOP
   case Exclamation!
      lul_Type = MB_ICONEXCLAMATION
   case Question!
      lul_Type = MB_ICONQUESTION
   case None!
      Return
end choose

// play the beep sound
MessageBeep(lul_Type)

end subroutine

on n_msgbox.create
call super::create
TriggerEvent( this, "constructor" )
end on

on n_msgbox.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on