Automatic inialization of control properties  Previous topicNext topicFirst topicLast topic



Automatic initialization of control properties

When localizing an application to other languages, it is important that the user interface text properties of all controls be initialized with LoadResString resource strings to ensure that all user interface strings can be translated. There are existing schemes for remembering to replace the default text properties of controls with LoadResString() references, but these are now old fashioned.

The ResMe string extraction utility simplifies your effort by allowing you to set the default text properties of your controls to the appropriate message in your native language and then automatically generating LoadResString() references for these properties. This is best demonstrated in the following example:

Suppose a form looked like this with no code to initialize the default text properties for the menus, frames, and command buttons. All the text on the form and its controls was set with the Properties Dialog Box rather than with code.

Before String Extraction

Option Explicit

Private Sub Form_Load()
'No code for this form.
End Sub



After String Extraction
The string form will appear the same as before but notice the difference in the code behind the form. There are fifteen new strings in the resource file that are used to initialize all the user interface text on the form and its controls. In addition to the creation of a .RES file, a .BAS file containing references to all resource strings is shown below.

Option Explicit

Private Sub Form_Load()
'ResMe auto-generated line of code to call the initialization routine that was automatically generated.
Call frmStandard_Auto_Init
'No code for this form.
End Sub


Private Sub frmStandard_Auto_Init()
'This routine initializes all the string properties on this form.
'This section of code was automatically generated by the string extraction utility ResMe.
frmStandard.Caption = LoadResString(S16_System_Control_Dialo)
fraControl.Caption = LoadResString(S13_Master_Control)
chkLog.Caption = LoadResString(S12_Log_Results)
cmdStatus(1).Caption = LoadResString(S15_Stop)
txtInfo.Text = LoadResString(S11_Default_Information)
cmdCancel.Caption = LoadResString(S10_Cancel)
cmdStatus(0).Caption = LoadResString(S14_Start)
mnuFile.Caption = LoadResString(S5_File)
mnuFileOpen.Caption = LoadResString(S8_Open)
mnuFileExit.Caption = LoadResString(S4_Exit)
mnuEdit.Caption = LoadResString(S3_Edit)
mnuView.Caption = LoadResString(S9_View)
mnuHelp.Caption = LoadResString(S6_Help)
mnuHelpAbout.Caption = LoadResString(S2_About)
mnuHelpTopics.Caption = LoadResString(S7_Help_Topics)
End Sub



Contents of the newly created CONST.BAS file.
Option Explicit

'This section of public constant assignments for LoadResString referencing was created on Friday, May 28 1999 at 04:00 AM.
Public Const S2_About = 2 ' "&About"
Public Const S3_Edit = 3 ' "&Edit"
Public Const S4_Exit = 4 ' "&Exit"
Public Const S5_File = 5 ' "&File"
Public Const S6_Help = 6 ' "&Help"
Public Const S7_Help_Topics = 7 ' "&Help Topics"
Public Const S8_Open = 8 ' "&Open"
Public Const S9_View = 9 ' "&View"

Public Const S10_Cancel = 10 ' "Cancel"
Public Const S11_Default_Information = 11 ' "Default Information"
Public Const S12_Log_Results = 12 ' "Log Results"
Public Const S13_Master_Control = 13 ' "Master Control"
Public Const S14_Start = 14 ' "Start"
Public Const S15_Stop = 15 ' "Stop"
Public Const S16_System_Control_Dialo = 16 ' "System Control Dialog"