Solved

Alternative to MsgBox?

Posted on 2006-11-30
7
1,958 Views
Last Modified: 2012-06-21
I like how MsgBox stops all further processing until it's clicked but I don't like how it pops that little msgbox in the middle of the screen, which I then have bring to the front if there is a window covering it. Is there a way to do something like a msgbox but keep it on my Form (which is always in view) so I can go ahead and click a button on the form instead of having to bring the little msgbox window on top of windows that may be covering it.

I use the msgbox to inform me that a certain situation has happened, which I manually fix and when I'm done I click the MsgBox to continue processing. It'd be nice to have this button right on the form.

Thanks
0
Comment
Question by:JohnDoeSr
7 Comments
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 18049316
I guess you could just create a new label & text box on a form.

Call the new label 'mErrLabel' and the new Button 'bButtonErr'

then you could do something like:

private sub raise_err(strTxt as string, strButton as string)
mErrLabel.caption = strTxt
bButtonErr.caption = strButton
mErrLabel.visible = true
bButtonErr.visible = true
end sub


and in your button click event, just hide the error label and button again.



Brian
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 18049394
add a frame to your form...
and put all your objects in that form (we'll call this the mainframe)

add another small frame, with a label in it and a button. (we'll call this popframe)
now instead of doing the msgbox... u do the following:

mainframe.enabled=false 'if you disable the frame all objects in that frame will become not clickable... or accessible
popframe.visible=true  'this will show the popframe (like a msgbox)

p.s. note that you popframe should not be in the mainframe orelse it will not be accessible as well...

hope this helps..

cheers

dan

0
 
LVL 9

Expert Comment

by:Naveen Swamy
ID: 18051180
yeah using/creating a msgbox with advaced option is good to do but bringing the msgbox on top of the applications could be achieved with the help of vbSystemModal
or
you could design an applicable form and show it as modal form, this will act like a messagebox
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Expert Comment

by:debtdude
ID: 18058856
Private Function NewMsgBox(sMsg As String, lButtons As VbMsgBoxStyle, sTitle As String) As VbMsgBoxResult
Dim RC As VbMsgBoxResult

   Call SetWindowPos(Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, _
                     SWP_NOSIZE Or SWP_NOMOVE)
                                               
   RC = MsgBox(sMsg, lButtons, sTitle)
   
   Call SetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
                     SWP_NOSIZE Or SWP_NOMOVE)
   
   NewMsgBox = RC
   
End Function
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 18058868
debtdude: Your code has a few logical errors.

I think what you ment to do was bring the form to the front _while_ the message box was displayed.

Your code will not bring the window to the front until the message box is closed (execution was halted while awaiting response of message box).

The only way your code would work is if the MessageBox was called from another thread.
0
 
LVL 3

Expert Comment

by:Stimphy
ID: 18058897
Look at this example

http://vb.mvps.org/samples/project.asp?id=MovedMsg

Scroll to the bottom of the page to see the dl link
0
 
LVL 19

Accepted Solution

by:
BrianGEFF719 earned 250 total points
ID: 18058924
Here is a simple, very simple, example of how to create a non-blocking messagebox by using another thread:


Option Explicit
Private Declare Function CreateThread Lib "kernel32" (ByVal lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Private Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
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 lThreadHandle As Long
Private lEventHandle As Long
Private mRes As VbMsgBoxResult
Private mTxt As String
Private mCap As String
Private mTyp As VbMsgBoxStyle

Public Function nonBlockingMsgBox(strTxt As String, strCaption As String, mType As VbMsgBoxStyle)
    Dim lpThreadID As Long
    mTxt = strTxt
    mCap = strCaption
    mTyp = mType
    lThreadHandle = CreateThread(ByVal 0&, ByVal 0&, AddressOf msgbox_fnc, ByVal 0&, 0, lpThreadID)
End Function

Private Function msgbox_fnc()
mRes = MessageBox(0, mTxt, mCap, mTyp)
If lThreadHandle Then TerminateThread lThreadHandle, 0
End Function





To do this, in your main form you woul do nonBlockingMsgBox "Test Text", "My Caption", 0
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now