Solved

Screen Resolution problem

Posted on 1998-01-18
10
293 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

816 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

13 Experts available now in Live!

Get 1:1 Help Now