Solved

Screen Resolution problem

Posted on 1998-01-18
10
290 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Yes, that is the easiest way.
0
 
LVL 5

Expert Comment

by:dirtdart
Comment Utility
Any particular reason why my answer was rejected?  Just curious, and it might help others to find out what you want.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 8

Expert Comment

by:mrmick
Comment Utility
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
Comment Utility
... 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
Comment Utility
... 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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 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

6 Experts available now in Live!

Get 1:1 Help Now