控制MessageBox VB源码程序,程序员在编程的过程中可以参考学习使用,希望对IT程序员有用,此源码程序简单易懂、方便阅读,有很好的学习价值!
VERSION 5.00
Begin VB.Form frmManipulateMsgBox
AutoRedraw = -1 'True
Caption = "控制MessageBox"
ClientHeight = 2940
ClientLeft = 750
ClientTop = 750
ClientWidth = 4965
LinkTopic = "Form1"
ScaleHeight = 196
ScaleMode = 3 'Pixel
ScaleWidth = 331
Begin VB.CommandButton Command3
Caption = "对话框改变字体"
Height = 375
Left = 1365
TabIndex = 2
Top = 1860
Width = 2250
End
Begin VB.CommandButton Command2
Caption = "对话框居中于窗体"
Height = 375
Left = 1350
TabIndex = 1
Top = 1275
Width = 2250
End
Begin VB.CommandButton Command1
Caption = "对话框自动关闭"
Height = 375
Left = 1350
TabIndex = 0
Top = 705
Width = 2250
End
End
Attribute VB_Name = "frmManipulateMsgBox"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' demo project showing how to use the API to manipulate a messagebox
' by Bryan Stafford of New Vision Software?- newvision@imt.net
' this demo is released into the public domain "as is" without
' warranty or guaranty of any kind. In other words, use at
' your own risk.
Private Sub Command1_Click()
' this shows a messagebox that will be dismissed after 4 seconds
' set the callback timer and pass our application defined ID (NV_CLOSEMSGBOX)
' set the time for 4 seconds (4000& microseconds)
SetTimer hWnd, NV_CLOSEMSGBOX, 4000&, AddressOf TimerProc
' call the messagebox API function
Call MessageBox(hWnd, "4 秒钟后此对话框自动关闭", _
"Self Closing Message Box", MB_ICONQUESTION Or MB_TASKMODAL)
End Sub
Private Sub Command2_Click()
' this positions the messagebox in the desired location on the screen.
' the location is defined in the callback timer function
' lock the desktop so that the initial position is not shown
Call LockWindowUpdate(GetDesktopWindow())
' set the callback timer with our application defined ID (NV_MOVEMSGBOX)
' set the time for 10 microseconds to allow the messagebox time to become active
SetTimer hWnd, NV_MOVEMSGBOX, 10&, AddressOf TimerProc
' call the messagebox API function
Call MessageBox(hWnd, "对话框居中于窗体(而不是屏幕)?", _
"Position A Message Box", MB_ICONQUESTION Or MB_TASKMODAL)
End Sub
Private Sub Command3_Click()
' this changes th font for the message text of the messagebox.
' the routine in the callback timer function
' lock the desktop so that the initial font is not shown
Call LockWindowUpdate(GetDesktopWindow())
' set the callback timer with our application defined ID (NV_MSGBOXCHNGFONT)
' set the time for 10 microseconds to allow the messagebox time to become active
SetTimer hWnd, NV_MSGBOXCHNGFONT, 10&, AddressOf TimerProc
' call the messagebox API function
Call MessageBox(hWnd, MSGBOXTEXT, "Change The Message Box Font", MB_ICONQUESTION Or MB_TASKMODAL)
End Sub
Private Sub Form_Load()
' we will use the font from the form to change the text in one of our message boxes
' first, set the attributes of the font that we will want to display.
With Font
.Bold = True
.Italic = True
End With
' next, grab a handle to the form's font and store it in the global variable for use later.
' don't change the font on the form or the value in the global variable will be invalid.
Dim IFont As IFont
Set IFont = Font
g_hBoldFont = IFont.hFont
Set IFont = Nothing
End Sub