PDA

Click to See Complete Forum and Search --> : HOW 2 custmize MSGBOX


Dec 26th, 2000, 03:03 AM
Hi PALS,
Can any one tell me is there any option or API functions to customize the VB message box? If S, what R those? Can Explain with one small example please?

THNX
Harish H.R.

Vlatko
Dec 26th, 2000, 04:23 AM
You will have to make your own form to act like a msgbox. Display it as modal

frmmsgbox.Show vbModal

Jop
Dec 26th, 2000, 07:32 AM
Take a look at this code I wrote, I also posted it in the General forum


'Jop's ModifyMsgBox
'Not toroughly tested, have fun though ;)
Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hWnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Public hThread As Long, hThreadID As Long
Public Sub ChangeMsgBox()
Dim lMsgBox&, Reg As RECT, boxReg&

'find the window
lMsgBox = FindWindow(vbNullString, "FINDME")

'Loop while it's found
Do While lMsgBox = 0
lMsgBox = FindWindow(vbNullString, "FINDME")
DoEvents
Loop
'get the top/left/bottom/right of the window
GetWindowRect lMsgBox, Reg

'this part is not really working well, the region is way to small, I don't wanna change it now
boxReg = CreateEllipticRgn(0, 0, (Reg.Right - Reg.Left) / Screen.TwipsPerPixelX, (Reg.Bottom - Reg.Top) / Screen.TwipsPerPixelY)

'set the window
SetWindowRgn lMsgBox, boxReg, True
'delete the region
DeleteObject boxReg
End Sub


Now put this in a form:

Dim Thread&
Private Sub Form_Load()
'Create a new thread so it can be executed parralel to the MsgBox
Thread = CreateThread(ByVal 0&, ByVal 0&, AddressOf ChangeMsgBox, ByVal 0&, ByVal 0&, hThreadID)
'show the MsgBox
MsgBox "test", , "FINDME"
'If you want to change the windowtitle be sure to change it in the module too! (at the findwindow line)
'close our thread
CloseHandle Thread
End Sub


I hope you understand that this was a small example that it's possible to change the MsgBox' appearance.

I wrote it fast so be sure to change any bugs or *****ed code ;)

It would be possible to almost everything you can do with a 'normal' foreign window, the only difference is that wuth a msgBox the sub has to be called from another thread, otherwise the msgBox will lock up the code and the code would be executed when the MsgBox was closed.

Well... have fun and merry X-Mas!