Results 1 to 8 of 8

Thread: DoEvents Replacement

  1. #1

    Thread Starter
    Computer Science BS Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    DoEvents Replacement

    In my program, I wanna replace DoEvents with something faster and close to how C++ does it. The only events I wanna check are painting events, mouse events, and keyboard events, window moving and resizing. I plan on using the GetMessage TranslateMessage and DispatchMessage APIs but can't find the stinking constant values to messages such as WM_PAINT as well as the others, if not all of em. I know there are other ways, and I'm well aware of em as I tinkered with this stuff in the past (literally all of em such as GetQueueStatus, GetInputState etc.) But I don't wanna use them. I had the code to do the GetMessage TranslateMessage and DispatchMessage APIs a few years ago, but the code is long gone, and Google isn't even helping much either. The setup I know is kinda like this:

    Code:
    Public Type Message_Type
        hwnd As Long
        Message As Long
        wParam As Long
        lParam As Long
        Time As Long
        ptX As Long
        ptY As Long
    End Type
    
    Public Declare Function GetMessage Lib "user32" Alias "GetMessageA" (lpMsg As Message_Type, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
    Public Declare Function TranslateMessage Lib "user32" (lpMsg As Message_Type) As Long
    Public Declare Function DispatchMessage Lib "user32" Alias "DispatchMessageA" (lpMsg As Message_Type) As Long
    
    Public Msg As Message_Type
    
    Public Sub DoEvents_Replacement()
        While GetMessage(Msg, frmMain.hWnd, 0, 0)
            TranslateMessage Msg
            DispatchMessage Msg
        Wend
    End Sub
    Just that I don't know what the constants are for the messages, and practically forgot completely on how to handle em. It's 3 in the morning so I'll get back to respond sometime when I'm actually awake. Thanks in advance.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: DoEvents Replacement

    You'll find the most authoritative source for things like window message constants to be the C header files included in the Windows SDK.

    As time goes on it becomes hard to find the older SDKs anymore. I think only the Win7 and Win8 versions are still readily available for free downloading without an MSDN subscription.

    Here is a link to the most recent version relative to Win7:

    https://www.microsoft.com/en-us/down...s.aspx?id=8279

    Here is the order page for ordering disks, and this goes back further:

    http://mssdk.orderport.net/22221848/showall.asp

  3. #3
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: DoEvents Replacement

    Have you tried using PeekMessage instead of GetMessage? You can specify in the wRemoveMsg parameter the message types that you want to be processed.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  4. #4

    Thread Starter
    Computer Science BS Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: DoEvents Replacement

    Yea but the point is, is that I don't know the constants because as dillentante pointed out, its getting harder and harder to find any documentation as time goes by and vb6 slowely gets killed off. Its funny that MS abandons support for vb6 entirely, yet its still a widely used language do to its ease of use. But thats another topic. Anyways I might just stick with DoEvents in the mean time just to avoid the hassle incase no solutions are present.

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: DoEvents Replacement

    Well my point was that support for old versions of Windows becomes less available over time.

    As far as playing around with window messages goes... that has never been what you could call "normal" VB6 programming. I'm not saying that nobody does it, but it really isn't something within the domain of higher level languages like VB6.


    There are alternatives to using DoEvents calls already built into VB6 and encouraged in the VB6 manuals. But I'm sure you are aware of them and have discarded them as unsuitable for reasons of your own.

    Here's a thought though:

    If there is a way to make a DoEvents substitute that truly avoids all of the warts of DoEvents don't you think we'd all be using it? We've had 32-bit VB now since 1995 after all.

  6. #6
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: DoEvents Replacement

    WINUSER.H is the header you want. You might well have it already if you have installed any of the windows kits.

    You can also find it online easily enough, here's a link.

    Also you can usually find values with a web search by including define in your search term i.e. "#define WM_PAINT".
    W o t . S i g

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: DoEvents Replacement

    Depends on which message you need.

    I usually let Windows index the Include directory, and create a desktop or Start Menu shortcut to take me there quickly. Once there I can paste the name of the message constant into the search box, then open the file or files that come up in Notepad and do a Find.

    This works well for all kinds of API constants.

  8. #8
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,600

    Re: DoEvents Replacement

    Here are quite a few of them already defined in VB syntax.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

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