Message Queues

  • Thread starter Thread starter Neil Stevens
  • Start date Start date
N

Neil Stevens

Hi,

I would like to implements a message queue much like i used to in vb6 as
below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in VB.NET, i
need to implement this kind of message loop as part of an execution yield, i
dont want to use DoEvents() because of the propblems i have had with using
it in the past and this method has proved the best in VB6 for yilding
execution.

Could somebody provide some example code of how to do this in VB.NET or
point me to a good resource on the internet.

Thanks in advance
Neil
 
Look in your help under messagequeues, and message class. For instance, its
already intercepted for you in most cases with the overridable function
WndProc from the Control class. Check out that and it may be a good start.

HTH,
CJ
 
Neil Stevens said:
I would like to implements a message queue much like i used to in vb6
as below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in
VB.NET, i need to implement this kind of message loop as part of an
execution yield, i dont want to use DoEvents() because of the
propblems i have had with using it in the past and this method has
proved the best in VB6 for yilding execution.

Out of interest: When do you need this?
 
I would like to implements a message queue much like i used to in vb6 as
below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in VB.NET, i
need to implement this kind of message loop as part of an execution yield, i
dont want to use DoEvents() because of the propblems i have had with using
it in the past and this method has proved the best in VB6 for yilding
execution.

Could somebody provide some example code of how to do this in VB.NET or
point me to a good resource on the internet.

Give us more details on what you're really trying to do.

The fact there are threads and that these threads can be priorized in .NET
changes the whole picture. If you want to yield to another application just
lower your main threads priority, or higten the other app's thread, etc...

You don't give us enough info to really know what you want to do so I might
be totally off...

Alex.
 
What i have in the application is a form that opens a web document, i have a
method that sets the document property of the web browser control. The html
document has an amount of processing that has to be completed before it can
be shown to the user, so the form is hidden the web browser controls
document property is set to the html page and the html page starts
processing itself.

What i have then is a Yield method which processing the message queue so
that the application doesnt lock up while the html document is processing,
when the document is loaded then the method which sets up the document
property can continue to set up the form sizes and finally show the form.

As i said i have had some problems with the DoEvents method and personally
dont like this for of yielding execution, i have found that during a
DoEvents execution pops off to some other part of the application and i want
to prevent this until the form has fully loaded and been shown. The
following code is an example of the code i have

{Method that navigates to a page in a web browser control}
Set wb = New WebBrowser
wb.Navigate htmlPageToLoad

Dim hDoc as HTMLDocument
Set hDoc = wb.Document
If hDoc Is Nothing Then
Exit Function
End If

Do
Yield()
Loop Until (LCase$(hDoc.ReadyState) = "complete" Or LCase$(hDoc.ReadyState)
= "interactive") And wb.Busy = False

{Returns hDoc if it is not nothing}

' This is the yield method, it process any post message on the stack - not
keyboard or mouse messages
Public Sub Yield()
Dim m As MSG

While PeekMessage(m, 0, 0, 0, PM_REMOVE Or PM_QS_POSTMESSAGE Or
PM_QS_PAINT)
TranslateMessage m
DispatchMessage m
Wend
End Sub

I hope this makes things a little more clearer, i have other parts of the
code where this type of method is used.

I also use the PostMessage to post a close message from a handling UI class
to a form

Public Sub PostCloseMessage(ByVal hWnd As Long)
Posts a WM_CLOSE message to the target hWnd
PostMessage hWnd, WM_CLOSE, 0, 0
End Sub

And would like to know if there is an equivalant .NET Framework method.

Thanks for your time in advance
Neil
 
* "Neil Stevens said:
I would like to implements a message queue much like i used to in vb6 as
below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in VB.NET, i
need to implement this kind of message loop as part of an execution yield, i
dont want to use DoEvents() because of the propblems i have had with using
it in the past and this method has proved the best in VB6 for yilding
execution.

I think you can use the same code in VB.NET, but why do you need that?
Maybe there is a better, managed solution.
 
What i have in the application is a form that opens a web document, i have
a
method that sets the document property of the web browser control. The html
document has an amount of processing that has to be completed before it can
be shown to the user, so the form is hidden the web browser controls
document property is set to the html page and the html page starts
processing itself.

What i have then is a Yield method which processing the message queue so
that the application doesnt lock up while the html document is processing,
when the document is loaded then the method which sets up the document
property can continue to set up the form sizes and finally show the form.

As i said i have had some problems with the DoEvents method and personally
dont like this for of yielding execution, i have found that during a
DoEvents execution pops off to some other part of the application and i want
to prevent this until the form has fully loaded and been shown.

I haven't had to work with a similar problem but I suppose you could kick a
thread in which you would assign the url to the web control and then do the
sizing stuff.... All while your mean thread continues to process events...
If you need to prevent mouse/keyboard input while that happens, just disable
the main form at start of thread and re-enable at end of thread...

Would that work?

Alex.
 
Neil,
Is there a way that i can implements something similar to this in VB.NET,
i
Yes: System.Windows.Forms.Application.DoEvents

Or use Threads.
dont want to use DoEvents() because of the propblems i have had with using
it in the past and this method has proved the best in VB6 for yilding
execution.
VB.NET is NOT VB6, problems you may or may not have had in VB6 do not
necessarily exist in VB.NET. New runtime, new framework, and sad to say new
problems.
Could somebody provide some example code of how to do this in VB.NET or
point me to a good resource on the internet.
My first advice would be not to attempt it: as you are probably causing more
problems then helping in either VB6 or VB.NET, however you can use the same
technique in VB.NET that you used in VB6!

Declare your functions (PeekMessage,TranslateMessage,DispatchMessage) at the
top of your source file & call the them. Remember that Integer is 32bit in
VB.NET while only 16 bit in VB6.

I would seriously look at using a thread rather then some "hack" that may
cause other "hidden" problems...

Hope this helps
Jay
 
Back
Top