Skip to content

Commit f759f79

Browse files
author
J. Scott Elblein
committed
Versions 1.2 Updates
1 parent 11c9fb4 commit f759f79

File tree

5 files changed

+63
-8
lines changed

5 files changed

+63
-8
lines changed

GeekDrop Props/Classes/clsGeekDropProps.vb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,45 @@ Public Class GeekDropProps
119119

120120
End Function
121121

122+
Public Shared Function GenerateScreenCoords(ByVal WindowWidthRight As Integer, ByVal WindowWidthLeft As Integer, ByVal WindowHeightBottom As Integer, ByVal WindowHeightTop As Integer) As Integer()
123+
' This function generates screen X, Y coordinates that will keep a target Window within the user's visible viewing area, so that the entire window will always be shown,
124+
' and never cut off.
125+
'
126+
' The parameters are the dimensions of the target window to be shown on the user's screen. (GetWindowRect is a good API for getting these)
127+
'
128+
' Usage example:
129+
'
130+
' Dim intXY() As Integer = GeekDropProps.GenerateScreenCoords(1234, 1234, 1234, 1234)
131+
'
132+
' Returns:
133+
' Integer array. Element 0 = Width (X), Element 1 = Height (Y)
134+
'
135+
' Note: Since this function takes KNOWN dimensions of the target window, use care when dealing with non-fixed sized target windows.
136+
' i.e. Using this to calculate the coords of a fixed size Windows Properties sheet, no problem; using it on a resizable Notepad window, untested so far.
137+
138+
' Create an integer array of 2 elements
139+
Dim intCalculated(1) As Integer
140+
141+
' Generate a Random number
142+
Dim myRandom As New Random()
143+
144+
' These two vars take the dimensions of the target window to be displayed on the screen
145+
Dim intWindowWidth As Integer = WindowWidthRight - WindowWidthLeft
146+
Dim intWindowHeight As Integer = WindowHeightBottom - WindowHeightTop
147+
148+
' These 2 vars get the user's display resolution, then subtract the dimensions of the window to be displayed,
149+
' effectively making the "display area" smaller, so that the random number generator doesn't generate a number that won't allow the target
150+
' window to fit on the screen completely.
151+
Dim intScreenWidth As Integer = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - intWindowWidth
152+
Dim intScreenHeight As Integer = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - intWindowHeight
153+
154+
' Finally, generate the random numbers, using the above dimensions
155+
intCalculated(0) = myRandom.Next(intScreenWidth)
156+
intCalculated(1) = myRandom.Next(intScreenHeight)
157+
158+
' Return them in an integer array
159+
Return intCalculated
160+
161+
End Function
162+
122163
End Class

GeekDrop Props/Docs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ The "home page" of GeekDrop Props, is right here, don't be a stranger!: http://g
111111

112112
## Changelog ##
113113

114+
* Version 1.2
115+
* Further tweaking to the Properties Sheet location opening(s) introduced in the 1.1 update, so that the Sheet(s) will also always fully be visible on-screen, rather than (potentially) partially off-screen.
116+
114117
* Version 1.1
115118
* In Version 1.0 when opening more than 1 Properties Sheet, they would open directly on top of each other, which got a bit confusing, so now when more than 1 is opened they'll all open in different areas of the screen.
116119

GeekDrop Props/Forms/frmMain.vb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,25 @@ Public Class frmMain
110110
' Store this new hwnd in the List
111111
strRunning.Add(strHWND)
112112

113-
' Generate a Random number
114-
Dim myRandom As New Random()
113+
' Generate Random X, Y coords
114+
Dim intXY() As Integer = GeekDropProps.GenerateScreenCoords( _
115+
Convert.ToInt32(strWindow(4).Replace("R: ", "")), _
116+
Convert.ToInt32(strWindow(6).Replace("L: ", "")), _
117+
Convert.ToInt32(strWindow(5).Replace("B: ", "")), _
118+
Convert.ToInt32(strWindow(3).Replace("T: ", "")))
119+
120+
' Calc Window dimensions and store them
121+
Dim intWindowWidth As Integer = Convert.ToInt32(strWindow(4).Replace("R: ", "")) - Convert.ToInt32(strWindow(6).Replace("L: ", ""))
122+
Dim intWindowHeight As Integer = Convert.ToInt32(strWindow(5).Replace("B: ", "")) - Convert.ToInt32(strWindow(3).Replace("T: ", ""))
115123

116124
' Move the new Properties sheet to another location on the screen, so they don't all overlap each other,
117125
' making them harder to see without first having to manually move them
118126
GeekDropProps.MoveWindow( _
119127
CType(strHWND, IntPtr), _
120-
myRandom.Next(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width), _
121-
myRandom.Next(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height), _
122-
Convert.ToInt32(strWindow(4).Replace("R: ", "")) - Convert.ToInt32(strWindow(6).Replace("L: ", "")), _
123-
Convert.ToInt32(strWindow(5).Replace("B: ", "")) - Convert.ToInt32(strWindow(3).Replace("T: ", "")), _
128+
intXY(0), _
129+
intXY(1), _
130+
intWindowWidth, _
131+
intWindowHeight, _
124132
True)
125133

126134
' We need to hold our proverbial horses a sec here, to give the Sheets time to place themselves,

GeekDrop Props/My Project/AssemblyInfo.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
3131
' by using the '*' as shown below:
3232
' <Assembly: AssemblyVersion("1.0.*")>
3333

34-
<Assembly: AssemblyVersion("1.1.0.0")>
35-
<Assembly: AssemblyFileVersion("1.1.0.0")>
34+
<Assembly: AssemblyVersion("1.2.0.0")>
35+
<Assembly: AssemblyFileVersion("1.2.0.0")>

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ The "home page" of GeekDrop Props, is right here, don't be a stranger!: http://g
111111

112112
## Changelog ##
113113

114+
* Version 1.2
115+
* Further tweaking to the Properties Sheet location opening(s) introduced in the 1.1 update, so that the Sheet(s) will also always fully be visible on-screen, rather than (potentially) partially off-screen.
116+
114117
* Version 1.1
115118
* In Version 1.0 when opening more than 1 Properties Sheet, they would open directly on top of each other, which got a bit confusing, so now when more than 1 is opened they'll all open in different areas of the screen.
116119

0 commit comments

Comments
 (0)