-
Apr 15th, 2006, 09:49 PM
#1
Thread Starter
Junior Member
[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
-
Apr 17th, 2006, 07:04 AM
#2
-
Apr 17th, 2006, 06:13 PM
#3
Thread Starter
Junior Member
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.
-
Apr 18th, 2006, 07:03 AM
#4
-
Apr 18th, 2006, 05:55 PM
#5
Thread Starter
Junior Member
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.
-
Apr 19th, 2006, 10:07 AM
#6
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.
-
Apr 19th, 2006, 08:05 PM
#7
Thread Starter
Junior Member
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.
-
Apr 20th, 2006, 12:37 AM
#8
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?
-
Apr 21st, 2006, 01:31 AM
#9
Thread Starter
Junior Member
Re: Load a bitmap into a frame?
Moeur,
Yes, it is in a .bmp file.
-
Apr 22nd, 2006, 02:54 AM
#10
Re: Load a bitmap into a frame?
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.
Last edited by iPrank; Apr 22nd, 2006 at 03:50 AM.
-
Apr 22nd, 2006, 09:41 AM
#11
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:
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
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.
-
Apr 22nd, 2006, 12:15 PM
#12
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|