Results 1 to 17 of 17

Thread: API function to replace DoEvents?

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    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

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Wouldn't Sleep do it?

    VB Code:
    1. Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)


    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Duncan (i.e. MerrionComputing) has an API implementation of DoEvents as far as I know ...
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    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

  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    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]

  6. #6
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type Msg
    4.     hwnd As Long
    5.     message As Long
    6.     wParam As Long
    7.     lParam As Long
    8.     time As Long
    9.     ptX As Long
    10.     ptY As Long
    11. End Type
    12. 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
    13. Private Declare Function TranslateMessage Lib "user32" (lpMsg As Msg) As Long
    14. Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As Msg) As Long
    15. 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
    16.  
    17. Public Sub API_DoEvents()
    18.    Dim TMsg As Msg
    19.    Do While PeekMessage(TMsg, 0&, 0&, 0&, True)
    20.         TranslateMessage TMsg
    21.         DispatchMessage TMsg
    22.   Loop
    23. End Sub

    Although this probably lets buttons be clicked etc. just as DoEvents does...

  7. #7
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    703
    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?
    an ending

  8. #8
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    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.


  9. #9

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Originally posted by Merrion
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type Msg
    4.     hwnd As Long
    5.     message As Long
    6.     wParam As Long
    7.     lParam As Long
    8.     time As Long
    9.     ptX As Long
    10.     ptY As Long
    11. End Type
    12. 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
    13. Private Declare Function TranslateMessage Lib "user32" (lpMsg As Msg) As Long
    14. Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As Msg) As Long
    15. 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
    16.  
    17. Public Sub API_DoEvents()
    18.    Dim TMsg As Msg
    19.    Do While PeekMessage(TMsg, 0&, 0&, 0&, True)
    20.         TranslateMessage TMsg
    21.         DispatchMessage TMsg
    22.   Loop
    23. End Sub

    Although this probably lets buttons be clicked etc. just as DoEvents does...
    Errr...If I use:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
    4.  
    5. Public Property Get MSG_PING() As Long
    6. Static lngMsgID     As Long
    7.     If lngMsgID = 0 Then
    8.         lngMsgID = RegisterWindowMessage("MSG_PING")
    9.     End If
    10.     MSG_PING = lngMsgID
    11. 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

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104
    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!

  11. #11
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    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

  12. #12

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    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

  13. #13
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    Use the filter params of Peekmessage thus:-

    VB Code:
    1. Option Explicit
    2.  
    3. Private Type Msg
    4.     hwnd As Long
    5.     message As Long
    6.     wParam As Long
    7.     lParam As Long
    8.     time As Long
    9.     ptX As Long
    10.     ptY As Long
    11. End Type
    12. 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
    13. Private Declare Function TranslateMessage Lib "user32" (lpMsg As Msg) As Long
    14. Private Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As Msg) As Long
    15. 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
    16.  
    17. Option Explicit
    18.  
    19. Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
    20.  
    21. Public Property Get MSG_PING() As Long
    22. Static lngMsgID     As Long
    23.     If lngMsgID = 0 Then
    24.         lngMsgID = RegisterWindowMessage("MSG_PING")
    25.     End If
    26.     MSG_PING = lngMsgID
    27. End Property
    28.  
    29.  
    30. Public Sub API_DoPingEvents()
    31.    Dim TMsg As Msg
    32.    Do While PeekMessage(TMsg, 0&, MSG_PING, MSG_PING, True)
    33.         TranslateMessage TMsg
    34.         DispatchMessage TMsg
    35.   Loop
    36. End Sub

  14. #14
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166
    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.

  15. #15
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    How about:

    Me.Enabled = False

    ..... do your stuff...

    Me.Enabled = True

    ?

  16. #16

  17. #17
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    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
  •  



Click Here to Expand Forum to Full Width