|
-
Feb 8th, 2000, 03:08 AM
#1
Thread Starter
Junior Member
I'm writing an app which needs to load an image at runtime into a status bar control.
The problem is that the image (bitmap) is a certain size and needs to be stretched to fit the box, but the control just sizes the image vertically and not horizontally. Can some one please give me some feedback or sample code on what to do.
I've thought about using StretchBlt, would this help at all? I'm having trouble getting the handle of the correct panel in the status bar control. If you need any more information, just post a response. Please respond...
Thanks 
David Richardson
-
Feb 8th, 2000, 04:00 AM
#2
Here you go, I've written a Sub to do the Job, just pass it the Statusbar Object and the Number of the Panel, who's Image you want to Stretch:
Code:
'In a Module..
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc 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
Private Const SRCCOPY = &HCC0020
Public Sub StretchPanelImage(ByRef oStatusbar As StatusBar, ByVal PanelNumber As Long)
Dim W As Integer
Dim H As Integer
Dim DW As Integer
Dim DH As Integer
Dim lDC As Long
Dim lTempDC As Long
On Error GoTo StretchErr
With oStatusbar.Panels(PanelNumber)
'.Picture = LoadPicture("..\Common\Graphics\Bitmaps\Assorted\Beany.bmp")
'Get the Unstretched Dimensions of the Panel Image in Pixels..
W = oStatusbar.Parent.ScaleX(.Picture.Width, vbHimetric, vbPixels)
H = oStatusbar.Parent.ScaleY(.Picture.Height, vbHimetric, vbPixels)
'Get the Dimensions we want to Stretch the Image to..
DW = oStatusbar.Parent.ScaleX(.Width, vbTwips, vbPixels)
DH = oStatusbar.Parent.ScaleY(oStatusbar.Height, vbTwips, vbPixels)
'Get the StatusBars Device Context
lDC = GetWindowDC(oStatusbar.hwnd)
'Create a Matching Device Context to Temporarily Store the Unstretched Image
lTempDC = CreateCompatibleDC(lDC)
'Select the Image into the Temporary DC
Call SelectObject(lTempDC, .Picture.Handle)
'Scale the Invisible Picturebox to the size of the Destination Image
oStatusbar.Parent.Picture1.Move 0, 0, oStatusbar.Parent.ScaleX(DW, vbPixels, oStatusbar.Parent.ScaleMode), oStatusbar.Parent.ScaleY(DH, vbPixels, oStatusbar.Parent.ScaleMode)
'Copy the Stretched version of the Image to the Picturebox
StretchBlt oStatusbar.Parent.Picture1.hdc, 0, 0, DW, DH, lTempDC, 0, 0, W, H, SRCCOPY
'Make the Picturebox Image Persistent, (Static).
oStatusbar.Parent.Picture1 = oStatusbar.Parent.Picture1.Image
'Set the StatusBar Panels Picture Object to the new Stretched Picture..
.Picture = oStatusbar.Parent.Picture1
'Delete the Temp DC
Call DeleteDC(lTempDC)
'Release the Satusbar DC
Call ReleaseDC(oStatusbar.hwnd, lDC)
End With
StretchErr:
End Sub
Code:
'In the Form with the Statusbar, Add a Picturebox, (Picture1)...
Private Sub Form_Load()
Picture1.Visible = False
Picture1.AutoRedraw = True
StatusBar1.Panels(1).Picture = LoadPicture("..\Common\Graphics\Bitmaps\Assorted\Beany.bmp")
StretchPanelImage StatusBar1, 1
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Certified AllExperts Expert
-
Feb 9th, 2000, 04:28 AM
#3
Thread Starter
Junior Member
You are a GENIUS Aaron! Thank you 
David Richardson
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
|