Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Screen Resolution problem

Posted on 1998-01-18
10
Medium Priority
?
311 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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 800 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

782 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