Solved

Alternative to MsgBox?

Posted on 2006-11-30
7
2,002 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

734 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