Solved

Screen Resolution problem

Posted on 1998-01-18
10
292 Views
Last Modified: 2006-11-17
I want to test my program in other resolutions, but the
BackGround doesn't fit...
I used a PictureBox control to contain the BackGround
(and i can't change it into an image control because of
some functions of the program).
I'd like to know if there is something like the stretch
property of the image controls for the picturebox control.
Or, maybe, how to fit it accordingly to the resolution of
the user...Thank you!
0
Comment
Question by:Brando
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 5

Expert Comment

by:dirtdart
ID: 1452010
You can get the resoultion of the screen by the Screen.Width and Screen.Height properties.  Then adjust your picturebox Width and Height accordingly.  Once you have your picturebox to the right size, use LoadBitmap to get a handle to the bitmap and copy the picture to the picturebox with StrechBlt.

Declare Function StretchBlt Lib "gdi32" Alias "StretchBlt" (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

Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long

In LoadImage, hInst should be null, lpsz should be the path and filename of the Bitmap, un1 should be IMAGE_BITMAP, n1 and n2 are the width and height of the bitmap, and un2 should be LR_LOADFROMFILE.

In StrechBlt, hDC will be the handle to the device you are copying to, in this case, Picture1.hDC.  x and y are the upper left coordinates of the destination.  nWidth and nHeight are the width and height of the destination.  hSrcDC is the Device context of the bitmap, returned by the LoadImage call.  xSrc and ySrc are the upper left coordinates of the bitmap.  nSrcWidth and nSrcHeight are the width and height of the bitmap.  dwRop should be SRCCOPY.
0
 
LVL 4

Expert Comment

by:rantanen
ID: 1452011
Sorry dirtdart, but this won't work as you propose because

"The LoadImage() API can be used to load a bitmap from a BMP file. However, it does not return palette information."

So, you end up with a picture with background color.
0
 
LVL 5

Expert Comment

by:dirtdart
ID: 1452012
In that case, the easiest way would probably be to load the bitmap into a "hidden" picturebox, then transfer it from one to the other using StrechBlt.
0
 
LVL 4

Expert Comment

by:rantanen
ID: 1452013
Yes, that is the easiest way.
0
 
LVL 5

Expert Comment

by:dirtdart
ID: 1452014
Any particular reason why my answer was rejected?  Just curious, and it might help others to find out what you want.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:mrmick
ID: 1452015
dirtdart, provide a sample Form_Resize event procedure that demonstrates your previously proposed answer - and propose it as the answer to this question.
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1452016
... as for the LoadImage API comments, you could use the native VB method:

Set Picture1.Picture = LoadPicture("FilePathName")

0
 
LVL 8

Expert Comment

by:mrmick
ID: 1452017
... but then again, you could also use the native VB "PaintPicture" method to copy/stretch the bitmap.

0
 
LVL 8

Accepted Solution

by:
mrmick earned 200 total points
ID: 1452018
On second thought, here's the solution without any API calls using only native VB calls.  Create a new project, place two picturebox controls on Form1 and set the Form1.BorderStyle = 0.  Paste the code below into the Form1.Module and run.


Private Sub Form_Resize()

   Const strBitmap = "C:\Windows\Clouds.bmp"
   Static Here As Boolean
   
   If Here Then Exit Sub

   Here = True
   Me.Move 0, 0, Screen.Width, Screen.Height
   Picture1.AutoRedraw = True
   Picture1.BorderStyle = 0
   Picture2.AutoSize = True
   Set Picture2.Picture = LoadPicture(strBitmap)
   Picture2.AutoSize = False
   Picture1.Move 0, 0, Screen.Width, Screen.Height
   If (Picture2.Width < Picture1.Width) Or (Picture2.Height < Picture1.Height) Then
      Picture1.PaintPicture Picture2.Picture, 0, 0, Picture1.Width, Picture1.Height, 0, 0, Picture2.Width, Picture2.Height, vbSrcCopy
   Else
      Picture2.Move 0, 0, Screen.Width, Screen.Height
      Picture1.PaintPicture Picture2.Picture, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, vbSrcCopy
   End If
   Picture2.Visible = False
   Here = False

End Sub

0
 

Author Comment

by:Brando
ID: 1452019
I got it working using mrmicks suggestion using native VB methods .I would like mrmick to have the points. Thank you, MrMick.
( i don't know what an api should be...)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now