Results 1 to 11 of 11

Thread: Metafiles

  1. #1

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Lightbulb Metafiles

    I have a PictureBox that contains an Image control.
    That Image control contains a WMF (Windows MetaFile).
    The PictureBox also contains some Label Controls which I want to move around PictureBox.
    When using the Move method, the moving Label control does flicker a lot. When setting the Image control's picture to nothing (or when setting it invisible), the flicker no longer occurs!
    The flicker frequency also depends on the complexity of the WMF.

    Help? I do not want the flicker!

  2. #2
    Addicted Member
    Join Date
    Aug 2000
    Location
    Croatia
    Posts
    200
    The only thing I can come up with is to draw the text contained in label(s) using the TextOut API.

  3. #3
    Zaei
    Guest
    There is an article on VBWorld that uses an API to remove flicker. The reason that you are getting the flickers is that everytime the label moves, the WMF redraws itself (WMF files are simply a series of steps that uses API calls to draw, like LineTo, Rectangle, etc. It is not a collection of pixels). After the WMF redraws, your label redraws. This causes flicker. Use the LockWindowUpdate() API call before you call Move:
    Code:
    LockWindowUpdate(pic1.hwnd)
    Label1.Move(...)
    LockWindowUpdate(0)
    That should work.

    Z.

  4. #4

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Lightbulb

    The LockWindowUpdat() API won't do it, because moving lables across its 'locked' parent won't update the screen!
    Only when LockWindowUpdate(0&) is given, the screen will be updated.

    But, now I found the solution: I made the Image Control invisible, loaded a WMF into it and used the PlayMetaFile() API directly to the Image Control's parent (=PictureBox).

    Now it works smoothly without the flicker!

    I had to do this workaround because in VB3, the PlayMetaFile() API doesn't recognize Aldus Placeable Metafiles...

  5. #5
    Zaei
    Guest
    If you do it correctly, LockWindowUpdate() will do the trick. It will draw everything, then when you unlock, its almost like BitBlt from a back buffer.

    Z.

  6. #6
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540

    Not quite sure...

    But would the lockwindowupdate also get rid of the speed drop when it's redrawing? Although you can't see it doesn't mean it doesn't get drawn, right? (theoretically)

    And another problem: if any other window moves over the locked window, and LockWindowUpdate(0) is called, the whole desktop repaints
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  7. #7

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553

    Exclamation

    Ho, guys, I know that my solution (using PlayMetaFile) is good.
    But as a reaction to the LockWindowUpdate API, I wrote some code to demonstrate this behaviour - see the attachment.

    Try moving the label without the checkbox clicked and then with the checkbox clicked. See the difference and say that I was right, not?

  8. #8
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    No VB here, but looking at your code, you only call LockWindowUpdate() once, I think what we meant was, call LockWindowUpdate before moving, then call again with 0& afterwards, and do this everytime you move
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  9. #9

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    This will implement continously a Refresh, which will encourage the flicker, not?

  10. #10
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    It refreshes only after everything has been drawn, thus reducing flicker theoretically. But it's better to have a backbuffer instead of using LockWindowUpdate, like I said, LockWindowUpdate could cause the whole desktop to be repainted, which causes even more flicker than without it
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  11. #11

    Thread Starter
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    I do not use LockWindowUpdate() anymore because the whole desktop refreshes.
    Alternatively, I use the WM_SETREDRAW message to the hWnd. This locks only the given window and after the lock everything is drawn very smoothly.
    I use this message for simulating a multi-color ListBox using a PictureBox instead.

    For smooth redrawing:

    SendMessage (hWnd, WM_SETREDRAW, 0&, 0&) 'LOCK
    '... do the redrawing in the hWnd
    SendMessage (hWnd, WM_SETREDRAW, 1&, 0&) 'UNLOCK
    'don't forget to use the Refresh method of the object
    Last edited by Mad Compie; Nov 15th, 2001 at 03:30 PM.

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