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
Printable View
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
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?
Yes, there is a specific reason why I want it to go directly into a frame. It is currently in a picture box.
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?
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.
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.
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.
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?
Moeur,
Yes, it is in a .bmp file.
Hey Moeur,
I've managed to draw on the Frame's DC with StretchBlt.
VB Code:
Option Explicit 'GDI32 Private Declare Function StretchBlt Lib "gdi32.dll" ( _ ByVal hDesthdc As Long, _ ByVal x As Long, _ ByVal y As Long, _ ByVal nWidth As Long, _ ByVal nHeight As Long, _ ByVal hSrcDC As Long, _ ByVal xSrc As Long, _ ByVal ySrc As Long, _ ByVal nSrcWidth As Long, _ ByVal nSrcHeight As Long, _ ByVal dwRop As Long) As Long 'USER32 Private Declare Function GetDC Lib "user32.dll" ( _ ByVal hwnd As Long) As Long Private Sub Command2_Click() Me.Refresh End Sub '-------------------------------------- Private Sub Form_Load() Me.ScaleMode = vbPixels With Picture1 .Visible = False .AutoRedraw = True .Width = Frame1.Width .Height = Frame1.Height End With End Sub '-------------------------------------- Private Sub Command1_Click() Dim lFraDC As Long lFraDC = GetDC(Frame1.hwnd) StretchBlt lFraDC, _ 3, _ Me.TextHeight("H"), _ Frame1.Width - 3, _ Frame1.Height - 15, _ Picture1.hdc, _ 0, _ 0, _ Picture1.Width, _ Picture1.Height, _ vbSrcCopy 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.
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 thisIf 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.VB Code:
Private Sub FrameSC_WMArrival(hwnd As Long, uMsg As Long, wParam As Long, lParam As Long, lRetVal As Long) Select Case uMsg Case WM_PAINT BitBlt frhDc, 2, 15, Picture1.Width, Picture1.Height, Picture1.hdc, 0, 0, vbSrcCopy End Select End Sub
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.
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.