My first FireFly SDK Application with big troubles

Started by Stephane Fonteyne, April 03, 2005, 07:15:55 AM

Previous topic - Next topic

Elias Montoya

Stephane, here is a working code, you need to add 2 labels and a horizontal scroll bar in a form in order to make it work. I wont be
re-explaining anything, sorry. I hope you can make this working
code work. :)

Type Timertype
Interval as Long
ID       as Long
end type

Global Timer1 as Timertype
Global lOutPut As Long
Global TimerID As Long
Global hComm As Long
'------------------------------------------------------------------------------------------------------------------------
Function FORM1_HSCROLL1_WM_HSCROLL ( _
                                  ControlIndex  As Long,  _  ' index in Control Array
                                  hWndForm      As Dword, _  ' handle of Form
                                  hWndControl   As Dword, _  ' handle of Control
                                  nScrollCode   As Long,  _  ' scroll bar value
                                  nPosition     As Long   _  ' current scroll bar position
                                  ) As Long

  Local SI As SCROLLINFO
   Local Interval As Long
   
   'Get the current scroll information
   SI.fMask = %SIF_ALL
   SendMessage HWND_FORM1_HSCROLL1, %SBM_GETSCROLLINFO, 0, VarPtr(SI)
   
   'Calculate the new position based on the action
   Select Case nScrollCode
      Case %SB_LINEDOWN
          Incr SI.nPos
      Case %SB_PAGEDOWN
          SI.nPos = SI.nPos + Si.nPage
      Case %SB_LINEUP
          Decr SI.nPos
      Case %SB_PAGEUP
          SI.nPos = SI.nPos - Si.nPage
      Case %SB_THUMBPOSITION, %SB_THUMBTRACK
          SI.nPos = nPosition
      Case Else
          Exit Function
  End Select
 
  ' Ensure range is correct
  SI.nPos = Max&(Si.nMin, Min&(SI.nPos, Si.nMax - Si.nPage + 1))
 
  ' Update the scroll bar
  Si.fMask = %SIF_POS
  SendMessage HWND_FORM1_HSCROLL1, %SBM_SETSCROLLINFO, %TRUE, VarPtr(Si)
               
  'kill the current timer and create a new one based on the new interval
  If Timer1.ID Then KillTimer %Null, Timer1.ID        
  Timer1.Interval = SI.nPos * 50
   
  'Create the new timer. If the HScroll is not set in milliseconds then you
  'will need to multiple the Interval value by 1000.
  Timer1.ID = SetTimer( %Null, %Null, Timer1.Interval, CodePtr(TimerProc))
 
  FF_Control_SetText HWND_FORM1_LABEL2, format$(Timer1.Interval)

End Function
'------------------------------------------------------------------------------------------------------------------------
Function TimerProc( ByVal hWnd As Dword, _
                   ByVal uMsg As Long, _
                   ByVal idEvent As Long, _
                   ByVal dwTime As Long _
                   ) As Long
                   
  If lOutPut = 1 Then
     lOutput = 0
  Else
     lOutput = 1
  End If
   
  If lOutput = 1 Then
        Comm Set #hComm, DtrFlow  = 1  ' Enable DTR
  Else
        Comm Set #hComm, DtrFlow  = 0  ' Disable DTR
  End If
 
  FF_Control_SetText HWND_FORM1_LABEL1, "Timer event at : " & format$(Timer)
 
End Function

'------------------------------------------------------------------------------------------------------------------------
Function FORM1_WM_DESTROY ( _
                         hWndForm      As Dword _  ' handle of Form
                         ) As Long
                         
  'ensure that the timer is killed                        
  If Timer1.ID Then KillTimer %Null, Timer1.ID  
   
  'CloseComm Port
  Comm Close #hComm

End Function


'------------------------------------------------------------------------------------------------------------------------
Function FORM1_WM_CREATE ( _
                        hWndForm As Dword _  ' handle of Form
                        ) As Long
 
   Local Interval As Long
   
   Comm Open "COM2" As #hComm
  Comm Set #hComm, Baud = 1200   ' 9600 baud
  Comm Set #hComm, Parity = 0      ' No parity
  Comm Set #hComm, Byte   = 8    ' 8 bits
  Comm Set #hComm, Stop   = 0    ' 1 stop bit
   
  If hComm = 0 Then
   FF_Control_SetText HWND_FORM1, "Comport not found, Program stopped"
  Else
   FF_Control_SetText HWND_FORM1, "Comport found and working"  
  End If
   
  'I try this:
  Timer1.Interval = 50
  Timer1.ID = SetTimer(%Null, %Null, Timer1.Interval, CodePtr(TimerProc))
  FF_Control_SetText HWND_FORM1_LABEL2, format$(Timer1.Interval)
 
End Function