|
-
Apr 5th, 2004, 07:36 AM
#1
API function to replace DoEvents?
I have subclassed my form.
And it picks up custom msgs.
One of them is a PING message...when it gets this it PINGs a msg back...which is fair enough.
It does this every 30seconds.
Now I have a loop in my app that runs for about 10-20mins.
While this is looping my form doesn't pick up the ping and thus the other component terminates itself.
I need someway of allowing Msgs through, but I don't want a user to be able to click on a button or menu, which is what doevents would allow me to do...
Any ideas?
Woka
-
Apr 5th, 2004, 07:40 AM
#2
Wouldn't Sleep do it?
VB Code:
Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Phreak
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Apr 5th, 2004, 07:43 AM
#3
Retired VBF Adm1nistrator
Duncan (i.e. MerrionComputing) has an API implementation of DoEvents as far as I know ...
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 5th, 2004, 07:59 AM
#4
Sleep has completely the opposite affect 
Will see if I can chat to merrion...
I just want my main form to keep processing msgs, ie Paint and Move and resize etc, while my loop is running...but I don't want to be able to click a button on the form, which is what doevents will let me 
Woka
-
Apr 5th, 2004, 08:04 AM
#5
Retired VBF Adm1nistrator
Perhaps a simler solution would be to use DoEvents, but before the loop starts, you could disable all other controls on the form?
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Apr 7th, 2004, 04:31 AM
#6
VB Code:
Option Explicit
Private Type Msg
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
ptX As Long
ptY As Long
End Type
Private Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As Msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Private Declare Function TranslateMessage Lib "user32" (lpMsg As Msg) As Long
Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As Msg) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Public Sub API_DoEvents()
Dim TMsg As Msg
Do While PeekMessage(TMsg, 0&, 0&, 0&, True)
TranslateMessage TMsg
DispatchMessage TMsg
Loop
End Sub
Although this probably lets buttons be clicked etc. just as DoEvents does...
-
Apr 7th, 2004, 05:23 AM
#7
Fanatic Member
Yep, it will.
Surely you can just silently drop any messages you don't want in your WindowProc by simply not passing them to DefWindowProc?
Or disable your controls?
-
Apr 7th, 2004, 06:35 AM
#8
Not NoteMe
Not sure if this'll help, but it's some C++ code to remove all mouse messages - you should be able to translate/adapt it to your needs.
Code:
ZeroMemory(&tmpmsg,sizeof(tmpmsg));
while(tmpmsg.message != WM_QUIT)
if(!PeekMessage(&tmpmsg,NULL,WM_MOUSEFIRST,WM_MOUSELAST,PM_REMOVE))
break;
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Apr 7th, 2004, 08:14 AM
#9
Originally posted by Merrion
VB Code:
Option Explicit
Private Type Msg
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
ptX As Long
ptY As Long
End Type
Private Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As Msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Private Declare Function TranslateMessage Lib "user32" (lpMsg As Msg) As Long
Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As Msg) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Public Sub API_DoEvents()
Dim TMsg As Msg
Do While PeekMessage(TMsg, 0&, 0&, 0&, True)
TranslateMessage TMsg
DispatchMessage TMsg
Loop
End Sub
Although this probably lets buttons be clicked etc. just as DoEvents does...
Errr...If I use:
VB Code:
Option Explicit
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Public Property Get MSG_PING() As Long
Static lngMsgID As Long
If lngMsgID = 0 Then
lngMsgID = RegisterWindowMessage("MSG_PING")
End If
MSG_PING = lngMsgID
End Property
Then is there a way to look through the msg que for that message and process it, WITHOUT affecting any other msg?
Woka
-
Apr 7th, 2004, 09:19 AM
#10
Doesn't this seem like a situation for multi-threading? One thread to handle messages, another for the function process.
Didn't somebody write something about that in this forum?
Hmmmmm....who could that have been....Oh yeah! It was YOU!
-
Apr 7th, 2004, 09:34 AM
#11
Frenzied Member
If you want the loop to run
AND
respond to system messages
AND
not respond to user initiated messages
WHILE
the loop is running
....why not disable all user input to the form, mouse and keyboard, while the loop is running and then re-enable it once the activity is completely? Or have I misunderstood your requirements?
Regards
Kaushik Janardhanan
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Apr 7th, 2004, 09:57 AM
#12
Yes I am using my multithreading...new and improved too 
What I want is for the threaded object to PING the client and vis versa...if my app crashes, or the thread object crashes then I don't want resources still being used in windows.
Thus if either thread ain't heard from each other then I terminate processes and stuff...
The problem is that while this huge loop is running the PING messages and not being intercepted, so the threaded object destroys itself 
Woka
-
Apr 7th, 2004, 09:58 AM
#13
Use the filter params of Peekmessage thus:-
VB Code:
Option Explicit
Private Type Msg
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
ptX As Long
ptY As Long
End Type
Private Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As Msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Private Declare Function TranslateMessage Lib "user32" (lpMsg As Msg) As Long
Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As Msg) As Long
Private Declare Function PeekMessage Lib "user32" Alias "PeekMessageA" (lpMsg As Msg, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal wRemoveMsg As Long) As Long
Option Explicit
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Public Property Get MSG_PING() As Long
Static lngMsgID As Long
If lngMsgID = 0 Then
lngMsgID = RegisterWindowMessage("MSG_PING")
End If
MSG_PING = lngMsgID
End Property
Public Sub API_DoPingEvents()
Dim TMsg As Msg
Do While PeekMessage(TMsg, 0&, MSG_PING, MSG_PING, True)
TranslateMessage TMsg
DispatchMessage TMsg
Loop
End Sub
-
Apr 8th, 2004, 01:21 PM
#14
PowerPoster
Wokawidget
You might want to consider a separate process for your pinging and then use xprocess messaging to the client to notify whatever action you want to take.
This works well for me when no xprocess drawing needs to occur.
However, I have yet to resolve (control) the drawing order of the graphics when drawing across a process. For example: when using a loop to receive a real-time data update which draws in a client pbox and at the same time time allowing the client to use
a toolbox of drawing tools in the same pbox.
-
Apr 8th, 2004, 09:37 PM
#15
How about:
Me.Enabled = False
..... do your stuff...
Me.Enabled = True
?
-
Apr 9th, 2004, 05:28 AM
#16
-
Apr 9th, 2004, 09:54 AM
#17
Originally posted by Wokawidget
Bad bad bad bad *slap*
Your saying that to yourself in the sense that: how come I did not think of this ? or your saying that to me as in: no, that does not work ?
Sorry, I don't know the entire *woof* language
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|