Results 1 to 5 of 5

Thread: [VB6 and API] - Convert a hdc to long variable

Threaded View

  1. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: [VB6 and API] - Convert a hdc to long variable

    If the picturebox does not have AutoRedraw=True and is hidden/not visible, you should get just black I would think.
    If the picturebox does have AutoRedraw=True and the size is smaller than what you are trying to Blt, you will get only the size of the picturebox, the rest should be black I would think

    Now, if PicAnimation(picAnimation.Count-1).AutoRedraw=False, then this is a problem...
    Code:
            PrintWindow Extender.Container.hwnd, PicAnimation(PicAnimation.Count - 1).hDC, 0
            PicAnimation(PicAnimation.Count - 1).Refresh ' << erased without AutoRedraw=True
    If the above isn't the problem, I'm sure this is part of it too
    Code:
            PicAnimation(PicAnimation.Count - 1).Picture = PicAnimation(PicAnimation.Count - 1).Image
            s = PicAnimation(PicAnimation.Count - 1).hDC
            PicAnimation(PicAnimation.Count - 1).Picture = Nothing ' << erased DC
            ' ^^ if the AutoRedraw = True, the hDC changed, therefore s points to a destroyed hDC
    It is never safe to cache a VB hDC since VB can change it whenever it wants. Try this example
    -- add a picturebox to a form & paste this code. Run project & click the picturebox.
    See the results. You may be surprised
    Code:
    Private Sub Picture1_Click()
        Picture1.AutoRedraw = True
        Picture1.PaintPicture Me.Icon, 0, 0
        Debug.Print "hDC before setting picture to image: "; Picture1.hDC
        Set Picture1.Picture = Picture1.Image
        Debug.Print "hDC after setting picture to image: "; Picture1.hDC
        Set Picture1.Picture = Nothing
        Debug.Print "hDC after setting picture1.picture=nothing: "; Picture1.hDC
    End Sub
    Last edited by LaVolpe; Sep 9th, 2010 at 05:13 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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