Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Muted message box

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dave Biggs
    replied
    Version two - Silent Message Box (sMsgBox).
    Modified the code to be a more direct replacement for PB's MsgBox.
    Also added code for a user supplied icon - resource file required.
    Code:
    #INCLUDE "WIN32API.INC"
    #RESOURCE "SilentMsg.pbr"
    %IDR_UserIcon = 101
     
    #If 0                      ' Resource file for user supplied icon
     // SilentMsg.RC
     #define IDR_UserIcon = 101
     IDR_UserIcon   ICON   "UserIcon.ico"   // your icon here.
    #ENDIF
     
    '-------------------------------------------------------------------------/
    ' Silent Message Box - replacement for PB MsgBox Statement / Function.
    ' Call like:  sMSGBOX txt$ [, [style%], title$]
    '        or:  lResult& = sMSGBOX(txt$ [, [style&], title$])
    '-------------------------------------------------------------------------/
     
    Function sMsgBox (ByVal sMsg As String, Opt ByVal dwFlags As Dword, Opt ByVal sTitle As String) As Long
     Local hOwner, Res As Long, icoFile As String
     Local MbParams As MSGBOXPARAMS
     
      If Len(sTitle) = 0 Then sTitle = "sMsgBox"        ' $AppName ?
     
      MbParams.hInstance = 0                            ' Use standard OS icons
     
      Select Case dwFlags AND &H000000f0                ' Choose appropriate icon to match flags
        Case &H00000010                                 ' %MB_ICONHAND, %MB_ICONERROR, %MB_ICONSTOP
          MbParams.lpszIcon = %IDI_HAND
        Case &H00000020                                 ' %MB_ICONQUESTION
          MbParams.lpszIcon = %IDI_QUESTION
        Case &H00000030                                 ' %MB_ICONEXCLAMATION, %MB_ICONWARNING
          MbParams.lpszIcon = %IDI_EXCLAMATION
        Case &H00000040                                 ' %MB_ICONASTERISK, %MB_ICONINFORMATION
          MbParams.lpszIcon = %IDI_ASTERISK
        Case &H00000000                                 ' No Icon flag
          dwFlags = dwFlags Or %MB_ICONMASK
        Case Else                                       ' %MB_USERICON
          MbParams.hInstance = GetModuleHandle(BYVAL %NULL) ' Don't want OS standard icon here
          MbParams.lpszIcon = %IDR_UserIcon                 ' User's Icon from resource file
      End Select
     
      If (dwFlags AND &H000000f0) <> %MB_ICONMASK Then
        dwFlags = (dwFlags AND &Hffffff0f) OR &H00000080    ' Force %MB_USERICON flag
      End If
     
      hOwner = GetForegroundWindow()                    ' 0 for desktop or function could 
                                                        ' take 'hOwner' as a parameter
      MbParams.cbSize             = SizeOf(MbParams)
      MbParams.hwndOwner          = hOwner
      'MbParams.hInstance          = 0
      MbParams.lpszCaption        = StrPtr(sTitle)
      MbParams.lpszText           = StrPtr(sMsg)
      MbParams.dwStyle            = dwFlags             ' if .dwStyle includes %MB_USERICON, .lpszIcon is valid
    '  MbParams.lpszIcon           =                    ' and Windows doesn't automatically assign a sound !
      MbParams.dwContextHelpId    = 0
      MbParams.lpfnMsgBoxCallback = 0
      MbParams.dwLanguageId       = 0                   ' 3081 ? 0 = 'Language Neutral'
     
      Res = MESSAGEBOXINDIRECT(MbParams)
     Function = Res
    End Function
    '------------------/sMsgBox
     
    Function PbMain()
     Local MbParams As MSGBOXPARAMS
     Local Res As Long
      sMsgBox "Whatever", %MB_ICONMASK
      sMsgBox "IDI_HAND, IDI_ERROR", %MB_ICONHAND, "MB_ICONHAND, ERROR, STOP"
      Res = sMsgBox ("IDI_QUESTION", %MB_ICONQUESTION OR %MB_YESNO OR %MB_DEFBUTTON2, "MB_ICONQUESTION, YESNO")
      sMsgBox "IDI_EXCLAMATION, IDI_WARNING", %MB_ICONEXCLAMATION, "MB_ICONEXCLAMATION, WARNING"
      sMsgBox "IDI_ASTERISK, IDI_INFORMATION", %MB_ICONASTERISK, "MB_ICONASTERISK, INFORMATION"
      sMsgBox "IDI_APPLICATION", %MB_USERICON, "%MB_USERICON"
      ' Standard API MessageBox (or PB MsgBox) - applies sound as per Control panel setup / Sound Scheme
      MsgBox "~!#$%^&*'"+$CRLF+"MessageBox..!", %MB_ICONEXCLAMATION Or %MB_SYSTEMMODAL, "Now hear this!"
     
    End Function
    '------------------/PBMain

    Leave a comment:


  • Dave Biggs
    started a topic PBWin/PBCC Muted message box

    Muted message box

    Normal MessageBoxes (and PB's MsgBoxes) generate sounds according to the sound scheme that the user currently has set up.
    (The type of sound changes with the icon displayed in the message box).
    By using MessageBoxIndirect() we can circumvent Window's sound schemes and present a 'Muted' MessageBox...:shhh:
    Code:
     
    #INCLUDE "WIN32API.INC"
    '------------------/
     
    ' Call like: MMBox "Message", "Title", Flags   or Res = MMBOX("Choose","eg Yes or No", %MB_YESNO)
    Function MMBox (ByVal sMsg As String, Opt ByVal sTitle As String, Opt ByVal dwFlags As Dword) As Long
     Local hOwner, Res As Long
     Local MbParams As MSGBOXPARAMS
     
      If Len(sTitle) = 0 Then sTitle = "MMBox"          ' $AppName ?
     
      Select Case dwFlags AND &H000000f0                ' Choose appropriate icon
        Case &H00000010                                 ' %MB_ICONHAND, %MB_ICONERROR, %MB_ICONSTOP
          MbParams.lpszIcon = %IDI_HAND
        Case &H00000020                                 ' %MB_ICONQUESTION
          MbParams.lpszIcon = %IDI_QUESTION
        Case &H00000030                                 ' %MB_ICONEXCLAMATION, %MB_ICONWARNING
          MbParams.lpszIcon = %IDI_EXCLAMATION
        Case &H00000040                                 ' %MB_ICONASTERISK, %MB_ICONINFORMATION
          MbParams.lpszIcon = %IDI_ASTERISK
        Case Else                                       ' %MB_USERICON
          MbParams.lpszIcon = %IDI_APPLICATION          ' Or Icon from resource file..?
      End Select
     
      dwFlags = (dwFlags AND &Hffffff0f) OR &H00000080  ' Force %MB_USERICON Style
     
      hOwner = GetForegroundWindow()                    ' 0 for desktop or function could 
                                                        ' take 'hOwner' as a parameter
      MbParams.cbSize             = SizeOf(MbParams)
      MbParams.hwndOwner          = hOwner
      MbParams.hInstance          = 0
      MbParams.lpszCaption        = StrPtr(sTitle)
      MbParams.lpszText           = StrPtr(sMsg)
      MbParams.dwStyle            = dwFlags             ' if .dwStyle includes %MB_USERICON, .lpszIcon is valid
    '  MbParams.lpszIcon           =                    ' and Windows doesn't automatically asign a sound !
      MbParams.dwContextHelpId    = 0
      MbParams.lpfnMsgBoxCallback = 0
      MbParams.dwLanguageId       = 0                   ' 3081 ?
     
      Res = MESSAGEBOXINDIRECT(MbParams)
     Function = Res
    End Function
    '------------------/MMBox
     
    Function PbMain()
     Local MbParams As MSGBOXPARAMS
     Local Res As Long
      MMBox "Whatever"
      MMBox "IDI_HAND, IDI_ERROR", "MB_ICONHAND, ERROR, STOP", %MB_ICONHAND
      Res = MMBox ("IDI_QUESTION", "MB_ICONQUESTION, YESNO", %MB_ICONQUESTION OR %MB_YESNO OR %MB_DEFBUTTON2)
      MMBox "IDI_EXCLAMATION, IDI_WARNING", "MB_ICONEXCLAMATION, WARNING", %MB_ICONEXCLAMATION
      MMBox "IDI_ASTERISK, IDI_INFORMATION", "MB_ICONASTERISK, INFORMATION", %MB_ICONASTERISK
      MMBox "IDI_APPLICATION", "%MB_USERICON", %MB_USERICON
      ' Standard API MessageBox (or PB MsgBox) - applies sound as per Control panel setup / Sound Scheme
      MessageBox GetForegroundWindow(), "~!#$%^&*'"+$CRLF+"MessageBox..!", "Now hear this!", %MB_ICONEXCLAMATION
     
    End Function
    '------------------/PBMain
Working...
X