-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmWindow.bas
50 lines (37 loc) · 1.69 KB
/
mWindow.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Attribute VB_Name = "mWindow"
'// Provides portable modular code for window operations.
'// Copyright (c)2002 Richard Holyoak.
'// Contact rholyoak@bigfoot.com
'// Requires at least modRegistryV1
Option Explicit
'// Registry keys
Public Const REG_WINDOW As String = "Windows"
Public Sub GetWindowPosition(frmForm As Form)
Dim h As Single, w As Single, t As Single, l As Single
On Error Resume Next
With frmForm
'// Get the initial position, width and height of the window
w = RegGet(REG_WINDOW, .Caption & " Width", .Width)
h = RegGet(REG_WINDOW, .Caption & " Height", .Height)
l = RegGet(REG_WINDOW, .Caption & " Left", (fMain.Width - w) / 2)
t = RegGet(REG_WINDOW, .Caption & " Top", (fMain.Height - h) / 2)
'// Make sure the origin of the window is within the screen boundaries
If Screen.Width < l Then l = (fMain.Width - w) / 2
If Screen.Height < t Then t = (fMain.Height - h) / 2
If l < 0 Then l = 0
If t < 0 Then t = 0
'// Setup the window
.Move l, t, w, h
.WindowState = RegGet(REG_WINDOW, .Caption & " WindowState", .WindowState)
End With
End Sub
Public Sub PutWindowPosition(frmForm As Form, Optional Metrics As Boolean)
On Error Resume Next
With frmForm
RegPut REG_WINDOW, .Caption & " Left", .Left, REG_DWORD
RegPut REG_WINDOW, .Caption & " Top", .Top, REG_DWORD
If Metrics Then RegPut REG_WINDOW, .Caption & " Width", .Width, REG_DWORD
If Metrics Then RegPut REG_WINDOW, .Caption & " Height", .Height, REG_DWORD
RegPut REG_WINDOW, .Caption & " WindowState", .WindowState, REG_DWORD
End With
End Sub