Results 1 to 12 of 12

Thread: [RESOLVED] Load a bitmap into a frame?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    28

    Resolved [RESOLVED] Load a bitmap into a frame?

    Hello all.

    Simple question: What syntax (VB 6.0) would I use to place a bitmap image into a frame. Not looking to do it in an image or picture box...frame only.

    Thanks

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Load a bitmap into a frame?

    What exactly are you trying do to? Put a background image in a frame? You could put it in a picturebox and then put other things on top. Any specific reason you want explicitly in a frame?


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    28

    Re: Load a bitmap into a frame?

    Yes, there is a specific reason why I want it to go directly into a frame. It is currently in a picture box.

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Load a bitmap into a frame?

    Yes, but what is wrong with having it in a picturebox? Putting it in a frame is hard (if possible). I've never tried it but guessing, it would require subclassing... Why can't you put the picture in a picturebox and the other controls you would have in the frame, put them in the picture box?


    Has someone helped you? Then you can Rate their helpful post.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    28

    Re: Load a bitmap into a frame?

    Manavo,

    I appreciate your reply, and as I said before, the bitmap is already in a picture box. I cannot discuss the app, as it is governmental in nature and I am not free to...I just need help trying to load a bitmap directly into a frame.

  6. #6
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Load a bitmap into a frame?

    The frame control is a lightweight control, it has no hWnd or Device Context. Therefore it cannot be be drawn on.

    You simulate drawing on it in may ways using other controls.

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    28

    Re: Load a bitmap into a frame?

    Moeur,

    Thanks for the reply. The frame control does have an hWnd, which I currently use to show mpeg movies (using API). But I do not know API well enough to know if a bitmap can drawn to the hWnd.

  8. #8
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Load a bitmap into a frame?

    Ah, so it does. It does also have a device context so it can be done.
    Where is the image you want to show? in a file or what?

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    28

    Re: Load a bitmap into a frame?

    Moeur,

    Yes, it is in a .bmp file.

  10. #10
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,728

    Re: Load a bitmap into a frame?

    Hey Moeur,
    I've managed to draw on the Frame's DC with StretchBlt.
    VB Code:
    1. Option Explicit
    2.  
    3. 'GDI32
    4. Private Declare Function StretchBlt Lib "gdi32.dll" ( _
    5.      ByVal hDesthdc As Long, _
    6.      ByVal x As Long, _
    7.      ByVal y As Long, _
    8.      ByVal nWidth As Long, _
    9.      ByVal nHeight As Long, _
    10.      ByVal hSrcDC As Long, _
    11.      ByVal xSrc As Long, _
    12.      ByVal ySrc As Long, _
    13.      ByVal nSrcWidth As Long, _
    14.      ByVal nSrcHeight As Long, _
    15.      ByVal dwRop As Long) As Long
    16.  
    17. 'USER32
    18. Private Declare Function GetDC Lib "user32.dll" ( _
    19.      ByVal hwnd As Long) As Long
    20.  
    21. Private Sub Command2_Click()
    22. Me.Refresh
    23. End Sub
    24.  
    25. '--------------------------------------
    26. Private Sub Form_Load()
    27.     Me.ScaleMode = vbPixels
    28.  
    29.     With Picture1
    30.         .Visible = False
    31.         .AutoRedraw = True
    32.         .Width = Frame1.Width
    33.         .Height = Frame1.Height
    34.     End With
    35.  
    36. End Sub
    37.  
    38. '--------------------------------------
    39. Private Sub Command1_Click()
    40.     Dim lFraDC As Long
    41.     lFraDC = GetDC(Frame1.hwnd)
    42.     StretchBlt lFraDC, _
    43.                3, _
    44.                Me.TextHeight("H"), _
    45.                Frame1.Width - 3, _
    46.                Frame1.Height - 15, _
    47.                Picture1.hdc, _
    48.                0, _
    49.                0, _
    50.                Picture1.Width, _
    51.                Picture1.Height, _
    52.                vbSrcCopy
    53.    
    54. End Sub

    But the problem is, Frame controls doesn't have any Autoredraw property. So, every time the Frame goes out of screen or gets covered, it's DC changes and the image gets destroyed.

    I guess it can be solved by subclassing and trapping WM_PAINT/WM_ERASEBACKGROUND. (not tested)

    But, any idea how to solve it without subclassing ?

    Also, any idea how to get the 'drawing area' of the frame ?
    I've tried GetClientRect, but it always gives (0,0) as (Top,Left) - No matter if there is a caption or not.
    Last edited by iPrank; Apr 22nd, 2006 at 03:50 AM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  11. #11
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Load a bitmap into a frame?

    You have to subclass the frame if you want it to repaint properly.

    Make sure you leave some margins around the picture in the frame so that the borders and caption are not covered. Or you could store the frames borders and caption in a memory DC, then after drawing the picture you could transparentblt them over the top of the picture. This could look nice.

    Without that extra step, your window procedure could do something like this
    VB Code:
    1. Private Sub FrameSC_WMArrival(hwnd As Long, uMsg As Long, wParam As Long, lParam As Long, lRetVal As Long)
    2.     Select Case uMsg
    3.         Case WM_PAINT
    4.             BitBlt frhDc, 2, 15, Picture1.Width, Picture1.Height, Picture1.hdc, 0, 0, vbSrcCopy
    5.     End Select
    6. End Sub
    If you try this you'll see that it does OK, but that you can sometimes get it to forget to paint in some regions around the edge.

    The proper way to repaint would be to use the Beginpaint and endpaint functions but this gets a bit more complicated.

    Now if the requirement is that we cannot use a picturebox at all, then things get even worse. We can load the picture into a standard picture object, but getting the bitmap into the frame might require using a memory DC or two.

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Posts
    28

    Re: Load a bitmap into a frame?

    Hello iPrank and Moeur,

    Thanks very much for your suggestions. I will try them out and see if they will get me st least close to where I need to be. Thanks again.

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