可以具体点吗,如果比较麻烦的话我就自己做一个窗体了,但就是弄不到MSGBOX里的那个图标
解决方案 »
- VB TEXT控件組實現菜單中的複製剪切粘貼功能???
- 严重的速度问题!
- 初用TreeView,请教一下怎么用?
- VB里IrSock的控件在哪里?怎么用啊?最好哪位达人有代码提供,谢谢!100分送上
- 求一随系统运行时启动(该程序加入到注册表中)并同时屏蔽掉Ctrl+Alt+Del的小程序!
- 急救!为什么用ADO连接会经常出现E_FAILE的错误???
- 新手提问:如何在vb中设计一个扁平的按钮。----在线等待~!~!!
- 高手能给个端口监测的VBS代码吗?
- 在MDI窗体,如何把已经打开的窗口移到最前面,不是始终在最前面???
- vb 打印 picturebox 控件的方法
- 我想请问 MSHFlexGrid的显示行数列数是不是有限制?
- 如何在asp中调用word组件,以便实现下面类似的功能?
'--------------------API声明部分--------------------
Private Const WH_CBT = 5
Private Const HCBT_ACTIVATE = 5Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type'使用API的MessageBox替代VB系统的MsgBox
Private Declare Function MessageBox Lib "user32" _
Alias "MessageBoxA" _
(ByVal hWnd As Long, _
ByVal lpText As String, _
ByVal lpCaption As String, _
ByVal wType As Long) As Long
Private Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" _
(ByVal idHook As Long, _
ByVal lpfn As Long, _
ByVal hmod As Long, _
ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" _
(ByVal hHook As Long) As LongPrivate Declare Function MoveWindow Lib "user32" _
(ByVal hWnd As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) As Long
Private Declare Function GetWindowRect Lib "user32" _
(ByVal hWnd As Long, _
lpRect As RECT) As Long
Public Declare Function GetDlgItem Lib "user32" _
(ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
Private Declare Function SetDlgItemText Lib "user32" Alias "SetDlgItemTextA" _
(ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal lpString As String) As LongPrivate Declare Function GetDlgItemText Lib "user32" Alias "GetDlgItemTextA" _
(ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
Private hHook As Long
Private Const IDOK = 1
Private Const IDCANCEL = 2
Private Const IDABORT = 3
Private Const IDRETRY = 4
Private Const IDIGNORE = 5
Private Const IDYES = 6
Private Const IDNO = 7
Private Const IDPROMPT = &HFFFF&'----------------------窗体句柄----------------------'
Private hFormhWnd As Long
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'替代VB中的Msgbox函数
'''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function Msgbox(hWnd As Long, sPrompt As String, _
Optional dwStyle As Long, _
Optional sTitle As String) As Long
Dim hInstance As Long
Dim hThreadId As Long
hInstance = App.hInstance
hThreadId = App.ThreadID
If dwStyle = 0 Then dwStyle = vbOKOnly
If Len(sTitle) = 0 Then sTitle = App.EXEName
'将当前窗口的句柄付给变量
hFormhWnd = hWnd
'设置钩子
hHook = SetWindowsHookEx(WH_CBT, _
AddressOf CBTProc, _
hInstance, hThreadId)
'调用MessageBox API
Msgbox = MessageBox(hWnd, sPrompt, sTitle, dwStyle)End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''
'HOOK处理
'''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function CBTProc(ByVal nCode As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
'变量声明
Dim rc As RECT
Dim rcFrm As RECT
Dim newLeft As Long
Dim newTop As Long
Dim dlgWidth As Long
Dim dlgHeight As Long
Dim scrWidth As Long
Dim scrHeight As Long
Dim frmLeft As Long
Dim frmTop As Long
Dim frmWidth As Long
Dim frmHeight As Long
Dim hwndMsgBox As Long
' Dim lngHwnd As Long
'当MessageBox出现时,将Msgbox对话框居中与所在的窗口
If nCode = HCBT_ACTIVATE Then
'消息为HCBT_ACTIVATE时,参数wParam包含的是MessageBox的句柄
hwndMsgBox = wParam
'得到MessageBox对话框的Rect
Call GetWindowRect(hwndMsgBox, rc)
Call GetWindowRect(hFormhWnd, rcFrm)
'使MessageBox居中
frmLeft = rcFrm.Left
frmTop = rcFrm.Top
frmWidth = rcFrm.Right - rcFrm.Left
frmHeight = rcFrm.Bottom - rcFrm.Top dlgWidth = rc.Right - rc.Left
dlgHeight = rc.Bottom - rc.Top
scrWidth = Screen.Width \ Screen.TwipsPerPixelX
scrHeight = Screen.Height \ Screen.TwipsPerPixelY
newLeft = frmLeft + ((frmWidth - dlgWidth) \ 2)
newTop = frmTop + ((frmHeight - dlgHeight) \ 2)
'修改确定按钮的文字
Call SetDlgItemText(hwndMsgBox, IDOK, "这是确定按钮")
'Msgbox居中
Call MoveWindow(hwndMsgBox, newLeft, newTop, dlgWidth, dlgHeight, True)
'卸载钩子
UnhookWindowsHookEx hHook
End If
CBTProc = FalseEnd Function2·窗体中的代码:
Form1中的----- Option Explicit
Private Sub Command1_Click()
'变量声明
Dim strTitle As String
Dim strPrompt As String
Dim lngStyle As Long
'MessageBox的标题
strTitle = "我的应用"
'MessageBox的内容
strPrompt = "这是 hook MessageBox 的演示" & vbCrLf & vbCrLf & _
"MessageBox的对话框将会居中在Form中"
'MessageBox样式
lngStyle = vbAbortRetryIgnore Or vbInformation
Select Case Msgbox(hWnd, strPrompt, lngStyle, strTitle)
Case vbRetry: Text1.Text = "Retry button 按下"
Case vbAbort: Text1.Text = "Abort button 按下"
Case vbIgnore: Text1.Text = "Ignore button 按下"
End Select
End Sub Private Sub Command2_Click()
Form2.Show
End Sub
Form2中的----- Option Explicit Private Sub Command1_Click()
Call Msgbox(Me.hWnd, "确定按钮展示!", 0, "")
End Sub我抄的:)
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, lprc As RECT) As Long
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As String) As Long
Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Type POINTAPI
x As Long
y As Long
End Type
Public ProcOld As Long
Public Const TPM_LEFTALIGN = &H0&
Public Const WM_SYSCOMMAND = &H112
Public Const MF_SEPARATOR = &H800&
Public Const MF_STRING = &H0&
Public Const GWL_WNDPROC = (-4)
Public Const IDM_ABOUT As Long = 1010
Public Const WM_COMMAND = &H111
Public Const WM_ACTIVATE = &H6
Public Const WA_INACTIVE = 0
Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As LongPublic lhSysMenu As Long, lRet As LongPublic Function WindowProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case iMsg
Case WM_SYSCOMMAND
If wParam = IDM_ABOUT Then
MsgBox "VB Move Messagebox demo", vbInformation, "About"
Exit Function
End If
Case WM_COMMAND
If wParam = IDM_ABOUT Then
MsgBox "VB Move Messagebox demo", vbInformation, "About"
Exit Function
Else
CallWindowProc ProcOld, hwnd, WM_SYSCOMMAND, wParam, lParam
WindowProc = 0
Exit Function
End If
Case WM_ACTIVATE
If wParam = WA_INACTIVE Then
Dim mywnd As Long
Dim buf As String * 64
Dim oldrect As RECT
GetWindowRect hwnd, oldrect
mywnd = lParam
GetClassName mywnd, buf, 64
If Mid(buf, 1, 6) = "#32770" Then
Dim processid As Long
GetWindowThreadProcessId mywnd, processid
If processid = GetCurrentProcessId() Then
'SetWindowPos mywnd, 0, oldrect.Left, oldrect.Top, oldrect.Right - oldrect.Left, oldrect.Bottom - oldrect.Top, 0
Dim okbutton As Long
okbutton = FindWindowEx(mywnd, 0, vbNullString, "确定")
If okbutton Then
SetWindowText okbutton, "哈哈"
End If
End If
End If
End If
End Select
WindowProc = CallWindowProc(ProcOld, hwnd, iMsg, wParam, lParam)
End Function
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, lprc As RECT) As Long
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
有很多api声明都是为了别的操作而添加的,主要看
Case WM_ACTIVATE
If wParam = WA_INACTIVE Then
Dim mywnd As Long
Dim buf As String * 64
Dim oldrect As RECT
GetWindowRect hwnd, oldrect
mywnd = lParam
GetClassName mywnd, buf, 64
If Mid(buf, 1, 6) = "#32770" Then
Dim processid As Long
GetWindowThreadProcessId mywnd, processid
If processid = GetCurrentProcessId() Then
'SetWindowPos mywnd, 0, oldrect.Left, oldrect.Top, oldrect.Right - oldrect.Left, oldrect.Bottom - oldrect.Top, 0
Dim okbutton As Long
okbutton = FindWindowEx(mywnd, 0, vbNullString, "确定")
If okbutton Then
SetWindowText okbutton, "哈哈"
End If
End If
End If
End If窗体代码
private sub command1_click()
MsgBox "VB Messagebox demo", vbInformation, "HAHAHAHA"
end sub
如:
MsgBox "this is a test!",0,"I'm caption"
sleep(500)
if FindWindow(vbnullstring,"I'm caption") then
a=FindWindow(vbnullstring,"确定")
if SetWindowText(a,"haha") =0 then msgbox "ERR"
end if