VB代码,弹出窗口是图片背景,在哪里添加图片,要用代码?

原弹窗是这样的publicsubcommand1_click;msgbox"你好'endsub我想在你好的窗体背景是图片的,请教VB高手,要怎么写?... 原弹窗是这样的
public sub command1_click;
msgbox "你好'
end sub
我想在你好的窗体背景是图片的,请教VB高手,要怎么写?
展开
 我来答
远风的梦想家
2010-08-09 · TA获得超过2550个赞
知道大有可为答主
回答量:1389
采纳率:0%
帮助的人:0
展开全部
1、这个窗体的背景图片不可以直接修改,VB不支持这么做
2、如果你非要改的话,需要API钩子来完成,具体方法如下:
先创建一个窗体,窗体上添加一个picturebox并把这个picturebox的picture属性设置成你要的图片背景,然后粘贴如下代码
Private Sub Form_Load()
Me.Show
MsgBoxEx "你好"
End Sub

第二部,增加一个模块,添加如下代码

Private Type CWPSTRUCT
lParam As Long
wParam As Long
message As Long
hWnd As Long
End Type

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length 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 CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private 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
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long

Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Private Declare Function CreatePatternBrush Lib "gdi32" (ByVal hBitmap As Long) As Long
'透明处理
Public Const TRANSPARENT = 1

Private Const WH_CALLWNDPROC = 4
Private Const GWL_WNDPROC = (-4)
Private Const WM_CTLCOLORBTN = &H135
Private Const WM_DESTROY = &H2
Private Const WM_SETTEXT = &HC
Private Const WM_CREATE = &H1

' System Color Constants
Private Const COLOR_BTNFACE = 15
Private Const COLOR_BTNTEXT = 18

' Windows Messages
Private Const WM_CTLCOLORSTATIC = &H138
Private Const WM_CTLCOLORDLG = &H136

Private lHook As Long
Private lPrevWnd As Long

Private lForecolor As Long

Public Function SubMsgBox(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim sText As String
Select Case Msg
'对话框颜色和标签颜色Message
Case WM_CTLCOLORDLG, WM_CTLCOLORSTATIC
Debug.Print wParam & ":Wparam"
'Set Font Back 透明 和改变颜色。
If Msg = WM_CTLCOLORSTATIC Then
Call SetBkMode(wParam, TRANSPARENT)
End If
Call SetTextColor(wParam, lForecolor)
'Set BackGround Picture。
SubMsgBox = CreatePatternBrush(Form1.Picture1.Picture.Handle)
Exit Function
Case WM_DESTROY
'Remove the MsgBox Subclassing
Call SetWindowLong(hWnd, GWL_WNDPROC, lPrevWnd)
End Select
SubMsgBox = CallWindowProc(lPrevWnd, hWnd, Msg, wParam, ByVal lParam)
End Function

Private Function HookWindow(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim tCWP As CWPSTRUCT
Dim sClass As String
'This is where you need to Hook the Messagebox
CopyMemory tCWP, ByVal lParam, Len(tCWP)
If tCWP.message = WM_CREATE Then
sClass = Space(255)
sClass = Left(sClass, GetClassName(tCWP.hWnd, ByVal sClass, 255))
If sClass = "#32770" Then
'Subclass the Messagebox as it's created
lPrevWnd = SetWindowLong(tCWP.hWnd, GWL_WNDPROC, AddressOf SubMsgBox)
End If
End If
HookWindow = CallNextHookEx(lHook, nCode, wParam, ByVal lParam)
End Function

Public Function MsgBoxEx(ByVal Prompt As String, Optional ByVal Buttons As VbMsgBoxStyle, Optional ByVal Title As String, Optional ByVal HelpFile As String, Optional ByVal Context As Long, Optional ByVal ForeColor As ColorConstants = -1) As Long
Dim lReturn As Long
lHook = SetWindowsHookEx(WH_CALLWNDPROC, AddressOf HookWindow, App.hInstance, App.ThreadID)
'Set the Defaults
If Len(Title) = 0 Then Title = App.Title
lForecolor = GetSysColor(COLOR_BTNTEXT)
If ForeColor >= 0 Then lForecolor = ForeColor
'Show the Modified MsgBox
lReturn = MsgBox(Prompt, Buttons, Title, HelpFile, Context)
Call UnhookWindowsHookEx(lHook)
MsgBoxEx = lReturn
End Function

------------------------------------------------
方法非常复杂 建议你自己建立一个小窗口仿造它做一个
wu_xiaolin2009
2010-08-09 · TA获得超过632个赞
知道小有建树答主
回答量:378
采纳率:0%
帮助的人:298万
展开全部
1.添加一个对话框
2.用Form2.Picture属性来设置背景图片
3.在窗体上添加一个Label,设置BackStyle属性为Transparent
4.
public sub command1_click;
Form2.Label1.Caption = "你好"
Form2.Show

end sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zbs_8
2010-08-09 · TA获得超过2302个赞
知道小有建树答主
回答量:2058
采纳率:36%
帮助的人:513万
展开全部
msgbox这个函数不能改背景的吧。
如果是我处理你的这个问题,我就新建一个窗体。然后把窗体设置成弹出窗的样子,在窗体里面加入图片。
窗体设置成
borderstyle=5
然后在加一个确定按钮。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2010-08-09
展开全部
自己写添加一个窗体 用的时候就不用msgbox了

直接show 窗体名

其实就是掩眼法 自己自定义一个对话框窗体罢了
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式