# Visual Basic > Visual Basic 6 and Earlier >  [RESOLVED] Resize; Maximize 2nd Monitor (regardless)

## SamOscarBrown

Okay, all you experts in this...PLEASE DON'T SHOOT ME.

I have a game I'm creating where I present on some second monitor/tv/projector.  I don't know the resolution of any of them (Well, I know MY second MONITOR, but not others to which I will be presenting the screen (I refer to these second screens normally as "frmAudience".))  In this game, I have several image controls (Stretch property all set to TRUE)---those are the cards (front and back) as well as the two 'circular' images in the top left and top right.  I also have label controls, four frames (which become visible if a card above them is an ACE (for player to say if he/she wants it to be a 1 or 11)).

So, that is a typical layout on several of my games.  What I want to be able to do is (in the main form load) display the audience form on a second display, have it maximized and all controls properly resized and positioned as the original-created audience form.  (again, I will not know the resolution of these other devices for my audience form.)

If anyone would be so kind as to post a simple solution (if there is one) where all controls are properly resized and repositioned when the form is initiated and displayed on a second monitor in maximized. 

I've done things similar in the past, but never with images (which always were not either 'stretched' properly or positioned relative to location).

Here is a snapshot of my audience form (at a point in the game)...you should be able to tell which are images (most in different arrays)...the other things you see are either labels or on option grouping in a frame (there are 3 other similar frames currently hidden).

Again...don't shoot me for my ignorance...

Sam

----------


## SamOscarBrown

Never Mind...found an example....Happy New Year!

Sam

----------


## baka

Happy New Year.

and just to be sure.
I use:



```
Private Declare Sub SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Declare Function MonitorFromWindow Lib "user32" (ByVal hwnd As Long, ByVal dwFlags As Long) As Long
Private Declare Function GetMonitorInfo Lib "user32" Alias "GetMonitorInfoA" (ByVal hMonitor As Long, MonInfo As tagMONITORINFO) As Long
```

for my needs when dealing with multiple screens.

----------


## VanGoghGaming

When playing BlackJack it is decided automatically what the Ace is (1 or 11) based on the actions of the player and the best possible outcome of his hand.

----------


## SamOscarBrown

@baka....actually, I am using (as a module) the following code developed by Harsh Gupta in Dec '05.  (but I will try your api's in a test program



```
'All it does is when the form is resized, it
'changes all the controls (command buttons, lines,
'text boxes etc) to make the controls still look
'like they're in the right place.
'
'example: If you have a command button that is the
'size of the form, normally when i change the forms
'size, the command button is either too big for the
'form, or too little.
'With this, the command button is automatically
'resized so its still in the same proportion with
'the form.
'
'Made by:
'           Harsh Gupta made on 14th Dec. 2005
'///////////////////////////////////////////////////
Option Explicit


Dim PrevResizeX As Long
Dim PrevResizeY As Long


Public Function ResizeAll(FormName As Form)
    Dim tmpControl As Control
    
    'If a control does not have width or height property then
    'ignore it and continue with next control on the form
    On Error Resume Next


    'If the previous form width was 0
    'Which means that this function wasn't run before
    'then change prevresize x and y and exit function
    If PrevResizeX = 0 Then
        PrevResizeX = FormName.ScaleWidth
        PrevResizeY = FormName.ScaleHeight
        Exit Function
    End If


    'looping till all the controls on the form are covered
    For Each tmpControl In FormName
        
        tmpControl.Left = tmpControl.Left / PrevResizeX * FormName.ScaleWidth
        tmpControl.Top = tmpControl.Top / PrevResizeY * FormName.ScaleHeight
        tmpControl.Width = tmpControl.Width / PrevResizeX * FormName.ScaleWidth
        tmpControl.Height = tmpControl.Height / PrevResizeY * FormName.ScaleHeight
        
    Next tmpControl


    'setting the Prevsize to the current form width and height
    PrevResizeX = FormName.ScaleWidth
    PrevResizeY = FormName.ScaleHeight
End Function
```

I call it in my 'audience' form like:



```
Private Sub Form_Resize()
    ResizeAll Me
End Sub
```


In my main form, I use this:



```
Private Sub Form_Load()    
    'other stuff is here....
    ' ----------------------
    frmAudience.Show
    CenterFormOnMonitorTwo frmAudience
    frmAudience.WindowState = vbMaximized
End Sub
```

----------


## SamOscarBrown

@VGG...you may be correct, but (seemingly (watching YouTube of Catch21- https://www.youtube.com/watch?v=N73GnjXfl48 )) a player has an option of using an Ace as 1 or 11...so I designed my version similarly.  
Also, my version uses a maximum number of cards per player as 5....but that does not guarantee an 'automatic win' as many 'home versions' of BlackJack allow...If I ever get the situation with 2 players still under 21 with all five cards each shown, I will declare the one with the most points to be the winner...if both have the same number of points, I will declare the round a tie. (I may add a sixth card per person in my next variation.

Sam

----------


## baka

since I don't place any form anywhere, Im just interested "where is the form"
I use

hMonitor = MonitorFromWindow(Main.hwnd, 1&)

this will give me the "id" of the screen wheren my Main.hwnd is
now I get the screen property using

GetMonitorInfo hMonitor, MI

where MI is the type tagMONITORINFO
with tons of info

now I just use SetWindowPos to place the form correctly (I use different sizes, so normal, maximized, fullscreen) where the user is at.

for your need, it will instead be, "place my form in the other screen"
to know that we need to scan all available monitors.
u can use *EnumDisplayMonitors*

now u can create an array with all the monitors available
u could use MonitorFromWindow so u know "where am I"

so,
do the Enum, so you have the array at hand.
check where u are
this "id" will not be used, instead u use the other one.
if theres "2" (as u have 3 monitors or more) u can decide to take the "right one" or "left one" from the current one.
this is easy. just check the "left" of each one (that u get with GetMonitorInfo)

when u know that u should place your form in "id:2"
use GetMonitorInfo of id:2 and calculate your form-rect to center it in that area.
I mean, window sees all monitor as a "BIG ONE". so using SetWindowPos  or MoveWindow works well

another thing.
it could be that u know beforehand what is what.
so game should always be in the 2nd monitor with id:2
or it should be with the monitor with the highest dimension or lowest dimension etc.
its easy to compare the monitors I do this:



```
.Left = MI.rcMonitor.Left
.Top = MI.rcMonitor.Top
.Width = MI.rcMonitor.right - .Left
.Height = MI.rcMonitor.bottom - .Top
.wleft = MI.rcWork.Left
.wtop = MI.rcWork.Top
.wwidth = MI.rcWork.right - .wleft
.wheight = MI.rcWork.bottom - .wtop
```

as u see Im also interested in the Taskbar so I can center my form properly knowing where it is and how big it is.

----------


## Elroy

Personally, if it were me, and I just had a dozen controls or so, I'd tend to just mathematically figure it all out in the Form_Resize event.  No need to get super-fancy just because you can.

And, if you always want that form on monitor #2, I can help with that.  But I'm not sure that's what you asked for.   :Smilie:

----------


## SamOscarBrown

Well, Elroy...as I plan to use that module on several of the games I have created in the past (for future presentation), there may be several different controls on those audience forms.  As far as "always on monitor #2", I always just use two (one primary on the computer I have the program running (and other controls (like, options, command buttons, lists, grids, etc)---THOSE, I do not need resized...so, my audience forms will always be presented on #2 (if present).

baka...my stuff is never complicated (I don't know enough to make my programs that way!!), so simply 'borrowing' Gupta's code (which I DO understand however--I just want to give him credit for that 'module'---yes, I see I COULD have written something similar to create the same effect--it was not rocket-science, but I was having difficulties with PB's and Images).
Sam

----------


## baka

U do what u are most comfortable with.
programming is like that. u do what u like or can do.
and when u need something that u don't know how to, thats when u ask for help or try new code. nothing should be forced.
I gave u one way of doing things, but it can be done in other ways.
and if its your home computer and always run from your computer, u don't need any API at all. just place it with the right .left/.top coordination and its done.
API are used when u want to distribute to many people with many different computers, screen, resolutions etc.
thats what Im doing. it need to work for all people not just for me.
but if its a tool/game that I do for myself, I can be lazy and do it the most easy way possible.

----------


## Elroy

> Well, Elroy...as I plan to use that module on several of the games I have created in the past (for future presentation), there may be several different controls on those audience forms.  As far as "always on monitor #2", I always just use two (one primary on the computer I have the program running (and other controls (like, options, command buttons, lists, grids, etc)---THOSE, I do not need resized...so, my audience forms will always be presented on #2 (if present).


Fair enough.   :Smilie: 

I actually took a moment and studied Gupta's code.  It looks fine with one exception.  Not all controls are required to have Left, Top, Width, & Height properties.  The Line control is one in our standard Toolbox that has none of these, so just watch out for that situation.  I guess that's why he's got that "On Error Resume Next" up there.

Also, if you do any control nesting (controls in Frames or Pictureboxes), I'm not sure that code is going to work out.

ADDED:  Also, looked at it more, and it's possible you'll get "rounding creep" the way it's done.  LaVolpe ran into this problem a while back.  He wanted to get the "original" (upon loading) values of controls, but wasn't able to work that out.  If you always started with the original values and applied a scale to those, you wouldn't have to worry about any creep.

----------


## SamOscarBrown

Yeah, thx Elroy.  I know about lines (am sure there are other common controls as well) that dont have those properties-I also guessed why that OERN was put in there
Yes, thanks BakaI only do this coding as a hobby for myselfused to create websites years ago as a side job, but Ive retired twice now, so that extra income is not neededjust fun creating small projects for my church, friends and family.

----------

