'------------------------------------------------------------------------------
' Source code generated by FireFly Visual Designer Version: 3.05
' Generated: Sunday  January 03, 2010 at 03:23:30 p.m.
' Visit www.planetsquires.com for more information
'------------------------------------------------------------------------------


#COMPILE EXE "Rowing.exe"

' #BLOAT <num_expr>
' #COMPILER PBWIN
' #DEBUG ERROR ON|OFF
' #DIM ALL|NONE
' #OPTION {VERSION3 | VERSION4 | VERSION5}
' #REGISTER {ALL | DEFAULT | NONE}
' #TOOLS [ON|+ | OFF|-]
' #STACK <num_expr>

' FireFly will automatically replace the JOSEINCLUDES token based on the controls that are present
' in the project. If Jose Roca's includes are not specified in 'Environment Options' for the compiler
' then FireFly will simply use the default PowerBASIC Win32 API Include files that ship with the compiler.

#If Not %DEF( %USE_JOSE_INCLUDES )
#INCLUDE "WIN32API.INC"
#INCLUDE "COMMCTRL.INC"  ' needed for WinXP Theme support
#INCLUDE "COMDLG32.INC"
#INCLUDE "RICHEDIT.INC"
#EndIf

' Place your user defined Declares, Constants, and #Include files below this line. FireFly will not
' parse any of your defined #Include files - it simply includes it in the final generated code.
' -------------------------------------------------------------------------------------------------

'[END_APPSTART]


#Resource "CODEGEN_ROWING_RESOURCE.pbr"

Global gFLY_RichEditClass As Asciiz * %MAX_PATH
Global gFLY_AppID         As Asciiz * %MAX_PATH
Global gFLY_FontNames()   As String
Global gFLY_FontHandles() As Dword
Global gFLY_hDlgCurrent   As Dword

' Structure that holds Form/Control information
Type FLY_DATA                                  
   OldProc               As Dword   ' address to old window procedure 
   hWndControl           As Dword   ' handle of the control
   hWndParent            As Dword   ' handle of the parent
   IsForm                As Long    ' flag indicating that this is a Form
   IsModal               As Long    ' flag indicating modal form
   hFont                 As Dword   ' handle to font
   hAccel                As Dword   ' handle to accelerator table
   hBackBitmap           As Dword   ' handle of background form bitmap                 
   hStatusBarTimer       as Long    ' handle of timer for statusbar
   ControlIndex          As Long    ' controlindex of control
   CtrlFocus             As Long    ' control with current focus
   SelText               As Long    ' flag to highlight text in edit controls
   ProcessCtlColor       As Long    ' flag to process color messages
   IsForeSysColor        As Long    ' flag indicating to use system color
   IsBackSysColor        As Long    ' flag indicating to use system color
   hBackBrush            As Dword   ' brush for background color
   nForeColor            As Long    ' foreground color
   nBackColor            As Long    ' background color
End Type
                         
' Common info that the programmer can access via the global APP variable.
Type APP_TYPE
   Comments        As Asciiz * %MAX_PATH   ' Comments 
   CompanyName     As Asciiz * %MAX_PATH   ' Company Name 
   EXEName         As Asciiz * %MAX_PATH   ' EXE name of program 
   FileDescription As Asciiz * %MAX_PATH   ' File Description 
   hInstance       As Long                 ' Instance handle of the program
   Path            As Asciiz * %MAX_PATH   ' Current Path to the EXE
   ProductName     As Asciiz * %MAX_PATH   ' Product Name 
   LegalCopyright  As Asciiz * %MAX_PATH   ' Legal Copyright 
   LegalTrademarks As Asciiz * %MAX_PATH   ' Legal Trademarks
   ProductMajor    As Long                 ' Product Major number   
   ProductMinor    As Long                 ' Product Minor number   
   ProductRevision As Long                 ' Product Revision number
   ProductBuild    As Long                 ' Product Build number   
   FileMajor       As Long                 ' File Major number     
   FileMinor       As Long                 ' File Minor number     
   FileRevision    As Long                 ' File Revision number  
   FileBuild       As Long                 ' File Build number     
   ReturnValue     As Long                 ' User value returned from FF_FormClose
End Type
Global App As APP_TYPE


#If %Def(%FIREFLY_ZTRACE)
   Declare Function zTrace Lib "zTrace.dll" Alias "zTrace" (zTmp As Asciiz) As Long
#Else
   Function zTrace (zTmp As Asciiz) As Long
   End Function
#EndIf

' Declares/equates for all functions and controls in the project
#Include "CODEGEN_ROWING_DECLARES.inc"    

' Custom Controls Include Files
#Include "CODEGEN_RRBUTTONINC_MODULE.inc"
#Include "CODEGEN_MLG_DLLPBINC_MODULE.inc"
#Include "CODEGEN_FIRELINESINC_MODULE.inc"


' Special FireFly utility functions
#Include "CODEGEN_ROWING_UTILITY.inc"  

' Include code for all Modules
#Include "CODEGEN_ROWING_DBHANDLERINC_MODULE.inc"
#Include "CODEGEN_ROWING_TOOLTIPINC_MODULE.inc"

            
' Include code for all generated Forms
#Include "CODEGEN_ROWING_FRMAVAILABILITY_FORM.inc"
#Include "CODEGEN_ROWING_FRMBUILDCREW_FORM.inc"
#Include "CODEGEN_ROWING_FRMCREWSTATS_FORM.inc"
#Include "CODEGEN_ROWING_FRMSUPPORTITEMS_FORM.inc"
#Include "CODEGEN_ROWING_FRMMAIN_FORM.inc"
#Include "CODEGEN_ROWING_FRMCREW_FORM.inc"
#Include "CODEGEN_ROWING_FRMPERFORMANCE_FORM.inc"
#Include "CODEGEN_ROWING_FRMREGATTAS_FORM.inc"

                    
'#PARSESTART#  'do not delete this line
                    
Function WinMain( ByVal hInstance     As Dword, _
                  ByVal hPrevInstance As Dword, _
                  ByVal lpCmdLine     As Asciiz Ptr, _
                  ByVal iCmdShow      As Long _
                  ) As Long


    ' Initialize the Common Controls. This is necessary on WinXP platforms in order
    ' to ensure that the XP Theme styles work.
    Local uCC  As INIT_COMMON_CONTROLSEX
    Local hLib As Long
 
    uCC.dwSize = SizeOf(uCC)
    uCC.dwICC  = %ICC_NATIVEFNTCTL_CLASS Or %ICC_COOL_CLASSES Or %ICC_BAR_CLASSES Or _
                 %ICC_TAB_CLASSES Or %ICC_USEREX_CLASSES Or %ICC_WIN95_CLASSES Or _
                 %ICC_STANDARD_CLASSES Or %ICC_ANIMATE_CLASS Or %ICC_DATE_CLASSES Or _
                 %ICC_HOTKEY_CLASS Or %ICC_INTERNET_CLASSES Or %ICC_LISTVIEW_CLASSES Or _
                 %ICC_PAGESCROLLER_CLASS Or %ICC_PROGRESS_CLASS Or %ICC_TREEVIEW_CLASSES Or _
                 %ICC_UPDOWN_CLASS

    InitCommonControlsEx uCC

    ' Look for the RichEdit 2.0 control
    hLib = LoadLibrary("RICHED20.Dll") 
    If hLib Then
       gFLY_RichEditClass = "RICHEDIT20A" 
    Else  ' Try to load the original RichEdit control
       hLib = LoadLibrary("RICHED32.Dll")
       If hLib Then 
          gFLY_RichEditClass = "RICHEDIT" 
       End If
    End If
                     
   ' Define variable used to uniquely identify this application. This is used 
   ' by the FireFly function FF_PrevInstance.
   gFLY_AppID = "FORM_Rowing_frmMain_CLASS"


   ' Define Control Arrays if necessary
   FLY_InitializeVariables
   

   ' Set the values for the global App variable 
   App.hInstance = hInstance
   FLY_SetAppVariables
    

   ' Initialize the OCX container
   
    

   ' Load any 3rd party custom controls that need to use LoadLibrary or perform
   ' an Initialization routine.
   hLib = LoadLibrary("MLG.DLL")
   If hLib = 0 Then MsgBox "Could not LoadLibrary 3rd party custom control: MLG.DLL", %MB_ICONWARNING, "FireFly Error"



   

   ' Call the Function FLY_WinMain(). If that function returns True 
   ' then cease to continue execution of this program.
    If FF_WINMAIN(hInstance, hPrevInstance, lpCmdLine, iCmdShow) Then 
       Function = App.ReturnValue
       Exit Function
    End If   
                                       
   ' Create the Startup Form.
   frmMain_Show %HWND_DESKTOP, %TRUE
                                      

   

   Function = App.ReturnValue

End Function


' Global sDBasePath As String   ' moved to Declare include file.
' Global sCountry As String   ' moved to Declare include file.
' Global sUsage As String   ' moved to Declare include file.
' Global sDateFormat As String   ' moved to Declare include file.
' Global sErgUnit As String   ' moved to Declare include file.
' Global sWeightUnit As String   ' moved to Declare include file.
' Global sLanguage As String   ' moved to Declare include file.
' Global sAgeRoll As String   ' moved to Declare include file.
' Global sTRackUsed As String   ' moved to Declare include file.
' Global sReportLead As String   ' moved to Declare include file.
' Global sInWaterLead As String   ' moved to Declare include file.
' Global sGender As String   ' moved to Declare include file.
   

' #INCLUDE "WIN32API.inc"   ' moved to Declare include file.
'--------------------------------------------------------------------------------
Function FF_WINMAIN( ByVal hInstance     As Dword, _
                     ByVal hPrevInstance As Dword, _
                     ByVal lpCmdLine     As Asciiz Ptr, _
                     ByVal iCmdShow      As Long ) As Long
sDBasePath = FF_INI_GetKey( Exe.Path$ & "\Rowing.ini","Main", "dBasePath","")
sCountry =  FF_INI_GetKey( Exe.Path$ & "\Rowing.ini","Main", "Country","")
Dim sSQL As String
Dim lRow As Long
   
sSQL="Select * from Parameters where Country = '" & sCountry  & "'"
lRow = MakeRS(sDbasePath,sSQL)
If lRow <> 1 Then
   MsgBox "Missing parameter"
   Exit Function
 End If
sErgUnit = myRs(2,1)
sWeightUnit = myRs(3,1)
sAgeRoll = myRs(5,1)
sDateFormat=myRs(6,1)
sTrackUsed = myRs(7,1)
sReportLead = myRs(8,1)
sInWaterLead = myRs(9,1)
sGender = myRs(10,1)
Function = %fALSE    'return %TRUE if you want the program to end.

End Function

'[END_WINMAIN]

Function FF_PUMPHOOK( Msg As tagMsg ) As Long


   ' If this function returns FALSE (zero) then the processing of the regular
   ' FireFly message pump will continue. Returning TRUE (non-zero) will bypass
   ' the regular message pump.

   Function = %FALSE    'return %TRUE if you need to bypass the FireFly message pump

   ' If you are dealing with a 'normal' OCX control then the following code will
   ' allow the message to be forwarded to the OCX.
   #If %DEF( %USE_JOSE_INCLUDES )
      #If %DEF( %USE_JOSE_OCX )
         Function = OC_ForwardMessage( GetFocus(), Msg)
      #EndIf
   #EndIf

End Function

'[END_PUMPHOOK]


Sub FLY_InitializeVariables()    
   ' All FireFly variables relating to Forms and Controls are initialized here. This
   ' includes any Control Arrays that have been defined and control identifiers
   ' per the listing in the Declares include file.
   
    IDC_FRMAVAILABILITY_FRAME1 = 1000
    IDC_FRMAVAILABILITY_CBB = 1001
    IDC_FRMAVAILABILITY_CBC = 1002
    IDC_FRMAVAILABILITY_LABEL4 = 1003
    IDC_FRMAVAILABILITY_LABEL1 = 1004
    IDC_FRMAVAILABILITY_CBA = 1005
    IDC_FRMAVAILABILITY_LABEL2 = 1006
    IDC_FRMAVAILABILITY_MLG1 = 1007
    IDC_FRMAVAILABILITY_CBX = 1008
    IDC_FRMAVAILABILITY_OBUNAVAILABLE = 1009
    IDC_FRMAVAILABILITY_OBAVAILABLE = 1010
    IDC_FRMAVAILABILITY_LABEL3 = 1011
    IDC_FRMBUILDCREW_CBSCOX = 1000
    IDC_FRMBUILDCREW_CBBCOX = 1001
    IDC_FRMBUILDCREW_CB6 = 1002
    IDC_FRMBUILDCREW_CB4 = 1003
    IDC_FRMBUILDCREW_CB3 = 1004
    IDC_FRMBUILDCREW_CB1 = 1005
    IDC_FRMBUILDCREW_CB2 = 1006
    IDC_FRMBUILDCREW_CB7 = 1007
    IDC_FRMBUILDCREW_CB5 = 1008
    IDC_FRMBUILDCREW_CB8 = 1009
    IDC_FRMBUILDCREW_CBB = 1010
    IDC_FRMBUILDCREW_CBA = 1011
    IDC_FRMBUILDCREW_CBX = 1012
    IDC_FRMBUILDCREW_COMBOBOAT = 1013
    IDC_FRMBUILDCREW_ONMALE = 1014
    IDC_FRMBUILDCREW_OBFEMALE = 1015
    IDC_FRMBUILDCREW_LABEL2 = 1016
    IDC_FRMBUILDCREW_OPTSTBD = 1017
    IDC_FRMBUILDCREW_OPTPORT = 1018
    IDC_FRMBUILDCREW_FRAME1 = 1019
    IDC_FRMBUILDCREW_COMBOAGE = 1020
    IDC_FRMBUILDCREW_LABEL6 = 1021
    IDC_FRMBUILDCREW_LABEL3 = 1022
    IDC_FRMBUILDCREW_CBADD = 1023
    IDC_FRMBUILDCREW_COMBOREGATTA = 1024
    IDC_FRMBUILDCREW_LABEL5 = 1025
    IDC_FRMBUILDCREW_COMBOBOATCONFIG = 1026
    IDC_FRMBUILDCREW_LABEL7 = 1027
    IDC_FRMBUILDCREW_EIGHT = 1028
    IDC_FRMBUILDCREW_LB8 = 1029
    IDC_FRMBUILDCREW_LBSTROKE = 1030
    IDC_FRMBUILDCREW_LP8 = 1031
    IDC_FRMBUILDCREW_LS7 = 1032
    IDC_FRMBUILDCREW_LP6 = 1033
    IDC_FRMBUILDCREW_LS5 = 1034
    IDC_FRMBUILDCREW_LP4 = 1035
    IDC_FRMBUILDCREW_LS3 = 1036
    IDC_FRMBUILDCREW_LP2 = 1037
    IDC_FRMBUILDCREW_LS1 = 1038
    IDC_FRMBUILDCREW_LS8 = 1039
    IDC_FRMBUILDCREW_LP7 = 1040
    IDC_FRMBUILDCREW_LS6 = 1041
    IDC_FRMBUILDCREW_LP5 = 1042
    IDC_FRMBUILDCREW_LS4 = 1043
    IDC_FRMBUILDCREW_LP3 = 1044
    IDC_FRMBUILDCREW_LS2 = 1045
    IDC_FRMBUILDCREW_LP1 = 1046
    IDC_FRMBUILDCREW_LABEL1 = 1047
    IDC_FRMBUILDCREW_LABEL4 = 1048
    IDC_FRMBUILDCREW_GENDER = 1049
    IDC_FRMCREWSTATS_CBRETURN = 1000
    IDC_FRMCREWSTATS_CBPLACE = 1001
    IDC_FRMCREWSTATS_LABEL1 = 1002
    IDC_FRMCREWSTATS_LABEL2 = 1003
    IDC_FRMMAIN_RRBUTTON1 = 1000
    IDC_FRMMAIN_CBD = 1001
    IDC_FRMMAIN_CBX = 1002
    IDC_FRMMAIN_COMMAND1 = 1003
    IDC_FRMMAIN_CBE = 1004
    IDC_FRMMAIN_CBC = 1005
    IDC_FRMMAIN_CBB = 1006
    IDC_FRMMAIN_CBA = 1007
    IDC_FRMMAIN_FRAME1 = 1008
    IDC_FRMMAIN_LBA = 1009
    IDC_FRMMAIN_LBB = 1010
    IDC_FRMMAIN_LABEL1 = 1011
    IDC_FRMMAIN_LABEL2 = 1012
    IDC_FRMMAIN_LABEL3 = 1013
    IDC_FRMMAIN_LBD = 1014
    IDC_FRMCREW_COMBOBOATPREF = 1000
    IDC_FRMCREW_COMBONAME = 1001
    IDC_FRMCREW_TXFORENAME = 1002
    IDC_FRMCREW_TXSURNAME = 1003
    IDC_FRMCREW_TXBIRTHDATE = 1004
    IDC_FRMCREW_TXWEIGHT = 1005
    IDC_FRMCREW_CHCOX = 1006
    IDC_FRMCREW_CHINACTIVE = 1007
    IDC_FRMCREW_COMBOSIDE = 1008
    IDC_FRMCREW_TXEMAIL = 1009
    IDC_FRMCREW_TXPHONE = 1010
    IDC_FRMCREW_RRBUTTON1 = 1011
    IDC_FRMCREW_LABEL3 = 1012
    IDC_FRMCREW_TXMOBILE = 1013
    IDC_FRMCREW_LABEL4 = 1014
    IDC_FRMCREW_LABEL5 = 1015
    IDC_FRMCREW_LABEL6 = 1016
    IDC_FRMCREW_LABEL7 = 1017
    IDC_FRMCREW_LBACCEPT = 1018
    IDC_FRMCREW_LABEL10 = 1019
    IDC_FRMCREW_LABEL11 = 1020
    IDC_FRMCREW_LABEL12 = 1021
    IDC_FRMCREW_LABEL13 = 1022
    IDC_FRMCREW_LBDATEFORMAT = 1023
    IDC_FRMCREW_CBA = 1024
    IDC_FRMCREW_OBAMEND = 1025
    IDC_FRMCREW_OBADD = 1026
    IDC_FRMCREW_LABEL1 = 1027
    IDC_FRMCREW_LABEL14 = 1028
    IDC_FRMCREW_FRAME1 = 1029
    IDC_FRMPERFORMANCE_CBX = 1000
    IDC_FRMPERFORMANCE_CHCOX = 1001
    IDC_FRMPERFORMANCE_CBA = 1002
    IDC_FRMPERFORMANCE_MLG1 = 1003
    IDC_FRMPERFORMANCE_CHINACTIVE = 1004
    IDC_FRMPERFORMANCE_TXDATE = 1005
    IDC_FRMPERFORMANCE_LABEL1 = 1006
    IDC_FRMPERFORMANCE_LABEL2 = 1007
    IDC_FRMPERFORMANCE_LABEL3 = 1008
    IDC_FRMPERFORMANCE_LABEL4 = 1009
    IDC_FRMPERFORMANCE_LBDATEFORMAT = 1010
    IDC_FRMPERFORMANCE_LABEL5 = 1011
    IDC_FRMPERFORMANCE_LABEL6 = 1012
    IDC_FRMPERFORMANCE_LABEL7 = 1013
    IDC_FRMPERFORMANCE_LABEL8 = 1014
    IDC_FRMPERFORMANCE_LABEL9 = 1015
    IDC_FRMREGATTAS_CBA = 1000
    IDC_FRMREGATTAS_LABEL1 = 1001
    IDC_FRMREGATTAS_OBAMEND = 1002
    IDC_FRMREGATTAS_OBADD = 1003
    IDC_FRMREGATTAS_LABEL2 = 1004
    IDC_FRMREGATTAS_LABEL3 = 1005
    IDC_FRMREGATTAS_FRAME1 = 1006
    IDC_FRMREGATTAS_COMBOREGATTANAME = 1007
    IDC_FRMREGATTAS_LABEL4 = 1008
    IDC_FRMREGATTAS_LABEL5 = 1009
    IDC_FRMREGATTAS_MLG1 = 1010
    IDC_FRMREGATTAS_LABEL6 = 1011
    IDC_FRMREGATTAS_CBC = 1012
    IDC_FRMREGATTAS_LABEL7 = 1013
    IDC_FRMREGATTAS_LBDATEFORMAT = 1014
    IDC_FRMREGATTAS_LABEL9 = 1015
    IDC_FRMREGATTAS_FRAME2 = 1016
    IDC_FRMREGATTAS_CBB = 1017
    IDC_FRMREGATTAS_TXDATE = 1018
    IDC_FRMREGATTAS_LABEL8 = 1019
    IDC_FRMREGATTAS_TXTREGATTANAME = 1020
    IDC_FRMREGATTAS_CBX = 1021
    IDC_FRMREGATTAS_TXREPORT = 1022
    IDC_FRMREGATTAS_LABEL10 = 1023
    IDC_FRMREGATTAS_TXINWATER = 1024
    IDC_FRMREGATTAS_LBADDAMEND = 1025
          

End Sub   


Sub FLY_SetAppVariables()    
   ' All FireFly App variables are initialized here. This Type variable provides
   ' easy access to many commonly used FireFly settings.
   
   Local zTemp As Asciiz * %MAX_PATH
   Local x     As Long
   
   App.CompanyName       =  ""
   App.FileDescription   =  ""
   App.ProductName       =  ""
   App.LegalCopyright    =  ""
   App.LegalTrademarks   =  ""
   App.Comments          =  ""

   App.ProductMajor      =  1
   App.ProductMinor      =  0
   App.ProductRevision   =  0
   App.ProductBuild      =  0

   App.FileMajor         =  1
   App.FileMinor         =  0
   App.FileRevision      =  0
   App.FileBuild         =  0

   ' App.hInstance is set in WinMain/LibMain

   ' Retrieve program full path and EXE/DLL name
   GetModuleFileName App.hInstance, zTemp, %MAX_PATH
   
   x = InStr(-1, zTemp, Any ":/\")

   If x Then 
      App.Path           =  Left$(zTemp, x) 
      App.EXEname        =  Mid$(zTemp, x + 1)
   Else
      App.Path           =  "" 
      App.EXEname        =  zTemp
   End If


   ' The following two arrays are used to allow FireFly to reuse font
   ' handles that are common to one or more Controls. This saves us
   ' from consuming a GDI resource for every created control font.
   ReDim gFLY_FontNames(0)   As Global String
   ReDim gFLY_FontHandles(0) As Global DWord
   
End Sub


Function FLY_AdjustWindowRect( ByVal hWndForm As DWord, _
                               ByVal cxClient As Long, _
                               ByVal cyClient As Long _
                               ) As Long
                               
   Local dwStyle As DWord
   Local hMenu   As DWord
   Local rc      As Rect
   
   If (cxClient <> 0) And (cyClient <> 0) Then
      dwStyle = GetWindowLong( hWndForm, %GWL_STYLE )
      rc.nLeft = 0: rc.nTop = 0: rc.nRight = cxClient: rc.nBottom = cyClient
      hMenu = GetMenu( hWndForm )
      AdjustWindowRectEx rc, dwStyle, (hMenu <> %Null), GetWindowLong(hWndForm, %GWL_EXSTYLE)
      If (dwStyle and %WS_HSCROLL) = %WS_HSCROLL Then rc.nBottom = rc.nBottom + GetSystemMetrics(%SM_CYHSCROLL)
      If (dwStyle and %WS_VSCROLL) = %WS_VSCROLL Then rc.nRight  = rc.nRight  + GetSystemMetrics(%SM_CXVSCROLL)
      SetWindowPos hWndForm, %Null, 0, 0, _
                   rc.nRight-rc.nLeft, rc.nBottom-rc.nTop, _
                   %SWP_NOZORDER Or %SWP_NOMOVE Or %SWP_NOACTIVATE
   End If

End Function



' Enum all child windows of the Form (basically, all Controls) in order to handle
' the %WM_SYSCOLORCHANGE message. This will delete existing brushes and recreate 
' them using the new system colors.
Function FLY_EnumSysColorChangeProc( ByVal hWnd As Dword, lParam As Long ) As Long
   Local ff As FLY_DATA Ptr 
    
   ff = GetProp(hWnd, "FLY_PTR")
   If ff Then
      If @ff.ProcessCtlColor Then
          
         ' Create the new colors/brushes if we are using System colors 
         If @ff.IsForeSysColor Then @ff.nForeColor = GetSysColor(@ff.nForeColor)
         If @ff.IsBackSysColor Then 
            @ff.nBackColor = GetSysColor(@ff.nBackColor)
            If @ff.hBackBrush Then DeleteObject @ff.hBackBrush
            @ff.hBackBrush = GetSysColorBrush(@ff.nBackColor)
         End If   

      End If
   End If
    
   Function = %TRUE
End Function

Function FLY_SetControlData( ByVal hWndControl    As Dword, _
                             ByVal AllowSubclass  As Long, _
                             ByVal AllowSetFont   As Long, _
                             ByVal sFontString    As String, _
                             ByVal nControlIndex  As Long, _
                             ByVal nProcessColor  As Long, _
                             ByVal IsForeSysColor As Long, _
                             ByVal IsBackSysColor As Long, _
                             ByVal nForeColor     As Long, _
                             ByVal nBackColor     As Long, _
                             ByVal nTransparentBrush As Long, _
                             ByVal CodeProcedure  As Dword _
                             ) As DWord
                            
    Local zClassName As Asciiz * 50            
    Local sFont      As String
    Local ff As FLY_DATA Ptr 

    ff = HeapAlloc( GetProcessHeap(), %HEAP_ZERO_MEMORY, SizeOf(@ff) )
    If ff Then
       ' Store the pointer for later use
       SetProp hWndControl, "FLY_PTR", ff  
    
       ' Subclass the control
       If AllowSubclass = %TRUE Then
          @ff.OldProc = SetWindowLong( hWndControl, %GWL_WNDPROC, ByVal CodeProcedure )  
       End If
    
       ' Set the Font for this Form/Control
       If AllowSetFont = %TRUE Then
          GetClassName hWndControl, zClassName, SizeOf(zClassName)
          If UCase$(zClassName) = "SYSIPADDRESS32" Then
             ' Must make a new font for IP Control because that control deletes the font when
             ' it is destroyed. This would cause other controls that depend on the font to 
             ' resort back to the default system font.
             @ff.hFont = FF_MakeFontEx( $Dq & Parse$(sFontString, ",", 1) & $Dq, _ 
                             Val(Parse$(sFontString, ",", 2)), _ 
                             Val(Parse$(sFontString, ",", 6)), _   
                             Val(Parse$(sFontString, ",", 7)), _   
                             Val(Parse$(sFontString, ",", 8)), _   
                             Val(Parse$(sFontString, ",", 9)) )  
              
          Else   
             @ff.hFont = FF_MakeFontEx_Internal( sFontString )
          End If

          If @ff.hFont Then 
             SendMessage hWndControl, %WM_SETFONT, @ff.hFont, %TRUE
             If UCase$(zClassName) = "SYSDATETIMEPICK32" Then
                SendMessage hWndControl, %DTM_SETMCFONT, @ff.hFont, %TRUE
             End If
          End If
       End If
       
       @ff.ControlIndex = nControlIndex
       @ff.IsForm       = %FALSE          
       @ff.hwndControl  = hWndControl 
    
       ' Flag to process the %WM_CTLCOLOR??? messages.
       @ff.ProcessCtlColor = nProcessColor
       If @ff.ProcessCtlColor Then
          @ff.IsForeSysColor = IsForeSysColor
          @ff.IsBackSysColor = IsBackSysColor
          @ff.nForeColor     = nForeColor
          @ff.nBackColor     = nBackColor
          ' Create a Brush for painting the background of this Control.
          If nTransparentBrush <> -1 Then
             @ff.hBackBrush = nTransparentBrush
          Else 
             @ff.hBackBrush = IIF&( @ff.IsBackSysColor, GetSysColorBrush(@ff.nBackColor), CreateSolidBrush(@ff.nBackColor) )
          End If
       End If
    
    End If

    Function = ff  ' return the pointer to the data structure

End Function



Function FLY_GetActiveHandle( ByVal hWnd As DWord ) as DWord

  Static szClassName As Asciiz * 30

  ' Determine the top level window of the active control
  WHILE ISTRUE (GetWindowLong(hWnd, %GWL_STYLE) AND %WS_CHILD)
    IF ISTRUE (GetWindowLong(hWnd, %GWL_EXSTYLE) AND %WS_EX_MDICHILD) THEN EXIT LOOP
    GetClassName hWnd, szClassName, SizeOf(szClassName)
    If Left$(szClassName, 5) = "FORM_" Then EXIT LOOP
    hWnd = GetParent(hWnd)
  WEND

  FUNCTION = hWnd

End Function
