改变部件忙或请求挂起消息

“部件忙”对话框和“部件请求挂起”对话框作为简单的缺省消息由 Visual Basic 提供。在许多情况下这些对话框可能不满足需要。如:

在这些情况下,“切换到”按钮是不适合的,可能引起程序用户的混乱。这时可以为两个或其中的一个超时指定代用消息。消息会显示在一个没有“切换到”按钮的简单消息框中。

对请求挂起状态,消息框仅有一个“确定”按钮。对部件忙状态,提供“确定”按钮和“取消”按钮。如果用户按“取消”,在提出请求的过程中会出现错误 error-2147418111 (&h8001001)。

下列 App 对象的属性决定了“部件忙”或“部件请求挂起”对话框是否被消息框所取代,以及是否允许指定消息框的文本与标题。

OLEServerBusyMsgText 属性

该属性规定消息文本在部件忙状态发生时被显示。设置这个属性使得常用“部件忙”对话框的地方使用了替换的消息框。

OLEServerBusyMsgTitle 属性

如果在部件忙状态下提供了一个替换消息框,请确定要用的标题。(仅设置这个属性不会引起替换的消息框被使用。)

OLERequestPendingMsgText 属性

当请求挂起状态发生时,确定要显示的消息文本。 设置这个属性使得替换的消息框用在常用“部件请求挂起”对话框的地方。

OLERequestPendingMsgTitle 属性

如果为请求挂起状态提供替换的消息,请确定要使用的标题。(仅设置这个属性不会使替换的消息框被使用。)

下面的例子给部件忙和请求挂起两种状态设置标题和消息文本,完全替换“部件忙”或“部件请求挂起”对话框。

Public Const APP_TITLE = "Demo Application"

Private Sub cmdLongTransaction_Click()
   On Error Goto LongTransaction_Error
   ' 可能希望在 Sub Main 中设置标题一次。
   App.OLEServerBusyMsgTitle = APP_TITLE

   App.OLERequestPendingMsgTitle = APP_TITLE
   '针对这次请求的消息文本。
   App.OLEServerBusyMsgText = "The component for _
      the " & "Long Transaction has not responded. _
      If " & "you have been waiting more than five " _
      & "minutes, you may wish to cancel this " _
      & "request and try it later." & vbCrLf _
      & "Call Network Services to verify that the " _
      & "component is running, or to report problems."
   App.OLERequestPendingMsgText = "Your request " _
      & "is still executing. " & vbCrLf _
      & "Call Network Services to verify that the " _
      & " component is running, or to report _
      problems."
   '提出请求并使用结果的代码
   ' ...
LongTransaction_Cleanup:
   '完成所有必要清理的代码...
   ' ...
   Exit Sub

LongTransaction_Error:
   If Err.Number = &h80010001 Then
      MsgBox "Transaction cancelled"
   Else
      '处理其他错误的代码。
   End If
   Resume LongTransaction_Cleanup
End Sub

重点 消息的长度可能受操作系统的限制。当目标操作系统是 Windows NT 或 Windows 95 时,可使用长于一千字符的消息。