Would it be possible ..... ???
Hi there,
One item which always interested me, was if it is possible to use a message box not as a pop up window but as part of a container i.e. picture box or so to open up ONLY in that container and any error message for that matter as well ??? So what I'm trying to get is a guided operation of that so beloved MsBox.
Maybe somebody could help in any way ???.
Thanks aktell
Re: Would it be possible ..... ???
I really dont think so AFAIK but its a whole lot easier if you create a small form that duplicates a msgbox. Then use the SetParent API to nest the form into your container.
Re: Would it be possible ..... ???
Thanks alot it is a beginning and I will try to find something on these lines.
There is not anything you would know of how it's or has been done ???.
Thanks aktell
Re: Would it be possible ..... ???
Nope, just like I posted is your best bet.
Re: Would it be possible ..... ???
I just found this !!! within this Forum - http://www.vbforums.com/showthread.php?t=409165 - and it is a very simelar question I had ??? and you (RobDog888) where so kind to reply too.
Now as we are so far I really need some help to redirect ALL - AND ONLY the App's Error MsBoxes etc. of to this Form2 !!!
Thanks aktell
NonModal MessageBox Inside A Container
This is what I've tried. I'm using a timer, so there is a slight flickering.
I'll post again if I find any better way.
VB Code:
' add 2 form in the project
' place a picturebox, a command button and a timer in Form1
' and place this code inside Form1
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Const MB_ICONASTERISK = &H40&
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function MessageBoxNonModal 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 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 Sub Form_Load()
Timer1.Enabled = False
End Sub
'==============================================================================
Private Sub Command1_Click()
Timer1.Interval = 5
Timer1.Enabled = True
'shows non-modal messagebox
' (Form2 is a hidden form)
Call MessageBoxNonModal(Form2.hwnd, "Hi! I'm inside PictureBox", _
"MessageBox inside PictureBox", MB_ICONASTERISK)
End Sub
'==============================================================================
Private Sub Timer1_Timer()
Dim hMsgBox As Long
Dim rectMsgBox As RECT
Timer1.Enabled = False
' Find the hWnd of the MessageBox
hMsgBox = FindWindow("#32770", "MessageBox inside PictureBox")
' Get screen co-ordinate of the MessageBox
GetWindowRect hMsgBox, rectMsgBox
'Change the messagebox's parent.
SetParent hMsgBox, Picture1.hwnd
'Move the Messagebox to PictureBox's top,left corner
MoveWindow hMsgBox, 0, 0, (rectMsgBox.Right - rectMsgBox.Left), (rectMsgBox.Bottom - rectMsgBox.Top), 1
End Sub
'==============================================================================
Private Sub Form_Unload(Cancel As Integer)
'This ensures that all forms get unloaded
UnloadAll
End Sub
Inside a Module:
VB Code:
' Inside a Module
Option Explicit
Public Sub UnloadAll()
'Unloads all Form from Forms collection
Dim frm As Form
For Each frm In Forms
Unload frm
Next
End Sub
Re: Would it be possible ..... ???
Hi there,
I'm very impressed Thank You Very Much. Please don't hessitate to get back to me if you find more.
Thanks aktell