Results 1 to 3 of 3

Thread: How do I have a function get called on vsync?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008

    How do I have a function get called on vsync?

    I would like to know if there's a vsync Windows api function that can register a function to get called on vsync, something maybe could be used like this in VB6:
    RegisterFunctionForVSync AddressOf MyFunction
    That way whenever the computer's graphics card fired vsync, my function called MyFunction would get called and its code executed (code responsible for drawing something new to the screen each time the monitor displayed a new frame), which would allow me to make sure that the display in my program only got updated EXACTLY at the moment that the screen was drawn (could be useful for games). Otherwise there's no way to prevent the display from being updated too soon or too late. I think DirectX used to allow you to do that, but it required the DirectX VB6 SDK, and this is no longer supplied by Microsoft. So I'm wondering if there's any similar function that is directly built into the Windows API.
    Last edited by Ben321; Sep 13th, 2017 at 07:37 PM.

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Southern Tier NY

    Re: How do I have a function get called on vsync?

    As far as I know there isn't. I believe you have to resort to using a DirectX object. Perhaps user "The trick" can weigh in.
    I know that a number of people are still actively using DirectX with VB6 so I still believe you can use it even if you can't get the SDK for VB6. User Mikle also has some great VB6 DirectX game samples on the forum. I don't think I've come across a simple wrapped version of vsync to get form update synchronizing, although I have looked a few times in the distant past.

  3. #3
    Fanatic Member
    Join Date
    Aug 2013

    Re: How do I have a function get called on vsync?

    DwmGetCompositionTimingInfo has everything you need to do this yourself, but note that there is little point if you are using standard drawing methods (e.g. rendering to a window). The DWM in Vista+ handles composition and vsync automatically.

    You only need to worry about tearing if you are rendering directly to the "screen", which usually means you are already using DirectX or OpenGL instead of GDI/System.Drawing/etc.

    (Note also that modern monitors can have variable refresh rates a la FreeSync or G-Sync, which would make this approach even more complicated.)
    Check out PhotoDemon, a pro-grade photo editor written completely in VB6. (Full source available at GitHub.)

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