dcsimg
December 2, 2016
Hot Topics:

The Registry - Now I've got it what can I do?

  • November 19, 2002
  • By John Percival
  • Send Email »
  • More Articles »
Public Sub SaveFormPos( _
      frmSave As Form)
Dim strRegPath As String
strRegPath = "Software\" & App.CompanyName _
& "\" & App.Title & "\" & frmSave.Name

If frmSave.WindowState = vbMaximized Then
SaveSettingLong HKEY_CURRENT_USER, strRegPath, "Maximised", 1
DeleteValue HKEY_CURRENT_USER, strRegPath, "Left"
DeleteValue HKEY_CURRENT_USER, strRegPath, "Top"
DeleteValue HKEY_CURRENT_USER, strRegPath, "Width"
DeleteValue HKEY_CURRENT_USER, strRegPath, "Height"
Else
With frmSave
SaveSettingLong HKEY_CURRENT_USER, strRegPath, "Maximised", 0
SaveSettingLong HKEY_CURRENT_USER, strRegPath, "Left", .Left
SaveSettingLong HKEY_CURRENT_USER, strRegPath, "Top", .Top
SaveSettingLong HKEY_CURRENT_USER, strRegPath, "Width", .Width
SaveSettingLong HKEY_CURRENT_USER, strRegPath, "Height", .Height
End With
End If

End Sub

Public Sub LoadFormPos(frmLoad As Form)
Dim strRegPath As String
Dim IsMax As Long
strRegPath = "Software\" & App.CompanyName _
& "\" & App.Title & "\" & frmLoad.Name
IsMax = GetSettingLong(HKEY_CURRENT_USER, strRegPath, "Maximised", 2)

Select Case IsMax
Case 0
With frmLoad
.Move GetSettingLong(HKEY_CURRENT_USER, strRegPath, "Left", .Left), _
GetSettingLong(HKEY_CURRENT_USER, strRegPath, "Top", .Top), _
GetSettingLong(HKEY_CURRENT_USER, strRegPath, "Width", .Width), _
GetSettingLong(HKEY_CURRENT_USER, strRegPath, "Height", .Height)
End With

Case 1
frmLoad.WindowState = vbMaximized

Case 2
MsgBox "There is no form data saved for this form"

End Select

End Sub

This useful pair of functions allow you to save the position of the form in the registry, and load it at a later time. This is good when you have a small form that the user can move around, and will expect it in the same place next time they start. How it works is pretty self-explanatory. It uses the functions that I wrote last week in a module. The path that the information is saved to is HKEY_CURRENT_USER\CompanyName\AppName\FormName, so don't forget to set up the company name in Project Options.  It pops up a message box if there is no data saved, and you may want to catch this error, and set up a default position.





Page 4 of 5



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel