一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

VB改變MsgBox對(duì)話框的字體、顏色、背景圖片。

 hdzgx 2019-10-19
VB改變MsgBox對(duì)話框的字體、顏色、背景圖片。
##CocoLiu 一年前的個(gè)人編寫(xiě),希望大家喜歡。##
效果圖如上:^-^   :)
Option Explicit

'*************************************************************
'*模塊:mMsgBoxEx
'*功能:把對(duì)話框的字體改變顏色,背景改變圖片。
'*調(diào)用:MsgBoxEx("改變背景對(duì)話框!" , vbOKOnly , "提示", , , vbCyan)
'*************************************************************

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
        '對(duì)話框顏色和標(biāo)簽顏色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(LoadResPicture(101, 0).Handle)
            'LoadResPicture(101, 0).Handle 是資源文件中ID為101的圖片。
            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

這個(gè)是個(gè)公共模塊。但是圖片是固定在資源文件里面,還沒(méi)有想到其他辦法,
如果有誰(shuí)想到其他解決方法,請(qǐng)告訴我,大家可以互相學(xué)習(xí)哦。^_^
其中:
'LoadResPicture(101, 0).Handle 是資源文件中ID為101的圖片。
也可以換成某個(gè)窗體的圖片框中的圖片。
例如:Form1.Picture1.Picture.Handle
這樣就不局限在資源文件里面了。后來(lái)發(fā)現(xiàn)
 

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類(lèi)似文章 更多

    国产成人午夜在线视频| 亚洲国产另类久久精品| 日韩av亚洲一区二区三区| 亚洲中文字幕在线观看四区| 日本欧美一区二区三区就 | 日本丁香婷婷欧美激情| 熟女少妇久久一区二区三区| 欧美日韩一区二区综合| 国产伦精品一区二区三区高清版| 国产精品自拍杆香蕉视频| 久久机热频这里只精品| 国产精品久久三级精品| 日韩精品中文字幕亚洲| 色无极东京热男人的天堂| 日韩毛片视频免费观看| 制服丝袜美腿美女一区二区| 香蕉网尹人综合在线观看| 五月综合婷婷在线伊人| 精品日韩av一区二区三区| 千仞雪下面好爽好紧好湿全文| 日系韩系还是欧美久久| 亚洲av秘片一区二区三区| 国产欧洲亚洲日产一区二区| 91后入中出内射在线| 国产麻豆一线二线三线| 亚洲中文字幕亲近伦片| 亚洲欧美日韩国产自拍| 大香蕉网国产在线观看av| 超薄丝袜足一区二区三区| 亚洲欧洲在线一区二区三区| 国语对白刺激高潮在线视频| 精品国产亚洲av成人一区| 国产一区日韩二区欧美| 99久久精品午夜一区二| 好吊日在线观看免费视频| 日韩一区二区三区嘿嘿| 久久热在线视频免费观看| 激情内射日本一区二区三区| 粉嫩国产美女国产av| 欧美丰满人妻少妇精品| 大伊香蕉一区二区三区|