VB MsgBox

Status
Not open for further replies.

chill

Smack-Fu Master, in training
66
Hi
Ive got a problem with visual basic (ok another problem :D)
Im using an MDI form with a winsock control on it and numerous other forms which do pretty things to teh data which comes in from teh webserver connected to by the winsock control. The problem is that when a message box is displayed, or a common dialog control is shown, the application is suspended (this was revealed by having a caption incremented when the DataArrival event of the winsock control was called), this procedure and others e.g. timer controls are suspended. After doing a bit of research on this I find there are two constants to do with this kind of thing in MsgBox's:

vbApplicationModal 0 Application modal; the user must respond to the message box before continuing work in the current application.

vbSystemModal 4096 System modal; all applications are suspended until the user responds to the message box. (ie will stop the rest of windows apps from running.....)


As the ApplicationModal's value=0, there is no way of getting around this problem as far as I can see. Does this mean I am reduced to using a form which looks like a message box and passing variables to and from it to make it act like a message box, or is there a way to do it from the API? Or a different way entirely? I hope there is another way to do this other than the forms way because otherwise im going to have to do an open file dialog and print dialog etc etc etc...
grr
thanks a lot
jæs :confused:
 

russ-iha

Ars Praefectus
4,407
Subscriptor
VB applications are single-threaded, so there isn't any way around it without using some other (read:multi-threaded) approach. I posted some simple and easy code for threading in VB a while back... it would be fairly simple to just have a .BAS module that had only one function: display a messagebox. Then you could spawn your dialogs on a different thread.

http://episteme.arstechnica.com/6/ubb.x?a=tpc&s=50009562&f=6330927813&m=1790967143&r=8610988143

Its the first message I posted to that thread. If you follow the warnings (don't fool with global vars, use sync. objects, etc) then you shouldn't have any problems. Let me know if this helps or you have any questions.
 

wb

Ars Legatus Legionis
25,208
Subscriptor
There are two ways to handle this that I know of:


1) Use the win32 API messagebox function as follows

code:<HR>
Code:
Private Declare Function MessageBox Lib "USER32" Alias "MessageBoxA" _
(ByVal hwnd As Long, ByVal msg As String, ByVal caption As String,_ 
ByVal style As Long) As Long<P>' Different MessageBox styles
Public Const MB_OK = &H0&
Public Const MB_OKCANCEL = &H1&
Public Const MB_ABORTRETRYIGNORE = &H2&
Public Const MB_YESNOCANCEL = &H3&
Public Const MB_YESNO = &H4&
Public Const MB_RETRYCANCEL = &H5&
Public Const MB_ICONHAND = &H10&
Public Const MB_ICONQUESTION = &H20&
Public Const MB_ICONEXCLAMATION = &H30&
Public Const MB_ICONASTERISK = &H40&
Public Const MB_ICONINFORMATION = MB_ICONASTERISK
Public Const MB_ICONSTOP = MB_ICONHAND<P>' combine with "or" to change default button (the one
' that is selected by hitting "enter")
Public Const MB_DEFBUTTON1 = &H0&
Public Const MB_DEFBUTTON2 = &H100&
Public Const MB_DEFBUTTON3 = &H200&<P>' combine with "or" and an above style to define modality
Public Const MB_APPLMODAL = &H0&
Public Const MB_SYSTEMMODAL = &H1000&
Public Const MB_TASKMODAL = &H2000&<P>' combine with "or" to define messagebox behavior
Public Const MB_NOFOCUS = &H8000&
Public Const MB_SETFOREGROUND = &H10000
Public Const MB_DEFAULT_DESKTOP_ONLY = &H20000<P>
' Some possible results returned by calling MessageBox
Public Const IDOK = 1
Public Const IDCANCEL = 2
Public Const IDABORT = 3
Public Const IDRETRY = 4
Public Const IDIGNORE = 5
Public Const IDYES = 6
Public Const IDNO = 7<P>
.
.
. (in your code somewhere)
.
result = MessageBox(MyForm.hWnd, "This is a test", "Test messagebox",_
                    MB_YESNOCANCEL | MB_SYSTEMMODAL )<P>

You can get more information about all the various window styles and behaviors here

2) Create your own form which will behave as a messagebox. You can control the modality and style of the form quite easily, and can even customize your mesaagebox to have all kinds of great stuff.
 
Status
Not open for further replies.