UPDOWN Control CUSTOM events

Started by Mark Strickland, July 14, 2005, 07:54:22 PM

Previous topic - Next topic

Mark Strickland

I want to use an UPDOWN control in a very simple method.  Click up or down and I want to process separate events.

It seems that the scroll event will auto increment a param value but I have to keep track if I am going up or down.  I suppose I can do that but it seems that just responding to a CUSTOM event message for the control will work.

I cannot find anything that tells me the wMsg to respond to.

Every piece of documentation references buddy controls.

Anybody know?

There has to be a comprehensive refrence for this stuff.  Frequently MSDN tells you what you need but not on this one.

TechSupport

You can get at it through the notification that the UpDown control sends to the parent (Form).


Function FORM1_CUSTOM ( _
                     hWndForm      As Dword, _  ' handle of Form
                     wMsg          As Long,  _  ' type of message
                     wParam        As Dword, _  ' first message parameter
                     lParam        As Long   _  ' second message parameter
                     ) As Long

Local pNMUPDOWN As NMUPDOWN Ptr

Select Case wMsg
  Case %WM_NOTIFY
     
         pNMUPDOWN = lParam
         
     If @pNMUPDOWN.hdr.hwndFrom = HWND_FORM1_UPDOWN1 Then
        MsgBox Str$(@pNMUPDOWN.iDelta)
     End If  
   
   End Select
   
End Function


Mark Strickland

Paul,

Thanks for the reply.  I will file that away for future reference.  I simply reset the current value every time the control is clicked and it goes up or down from there.

I fixed with with


   if nScrollCode = 8 then
       msgbox str$(nScrollCode) + "/" + str$(nPosition),,"Scroll/Posn"
       SendMessage HWND_FORMPATINFO_UPDOWN1, %UDM_SETPOS32, 0, 10 :'Reset control intial value
   end if

I also had to set an intial value in the form WM_CREATE.

Ahhhhhh Microsoft.

TechSupport

FireFly is set up to fire two messages when the button is clicked. The first is, %SB_THUMBPOSITION (has a value of 4). When the mouse button is released then %SB_ENDSCROLL is fired (value of 8). You can see this via code like the following:


Function FORM1_UPDOWN1_WM_VSCROLL ( _
                                 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

Select Case nScrollCode
 Case %SB_BOTTOM: msg$ = "Scrolls To the lower Right."
 Case %SB_ENDSCROLL: msg$ = "Ends scroll."
 Case %SB_LINEDOWN: msg$ = "Scrolls one line down."
 Case %SB_LINEUP:  msg$ = "Scrolls one line up."
 Case %SB_PAGEDOWN: msg$ = "Scrolls one page down."
 Case %SB_PAGEUP: msg$ = "Scrolls one page up."
 Case %SB_THUMBPOSITION: msg$ = "Scrolls to the absolute position. The current position is specified by the nPos parameter."
 Case %SB_THUMBTRACK: msg$ = "Drags scroll box to the specified position. The current position is specified by the nPos parameter."
 Case %SB_TOP: msg$ = "Scrolls to the upper left."
End Select  

FF_Control_SetText HWND_FORM1_LABEL1, Str$(nPosition) & "  " & msg$

End Function


I am not sure that you would need to reset the Min/Max values. Why don't you just set it in the FireFly PropertyList rather than via code? The default setting is 1 to 100, but you could easily change it to 0, 10.

RhodyRich


Jean-Pierre LEROY

Hello Paul,

How can you create this UpDown Control with FireFly ?

Jean-Pierre

RhodyRich

I use the Visual Designer to add an UpDown control to the right of a Text Box control. I often have more than one of these on a form and I create a control group for the text box and the updown controls. I make sure the index values are the same for each text box / updown set. The following code is an example of the code I use which makes the UpDown control work well together with the Text Box. Let me know if you have any questions.


'------------------------------------------------------------------------------------------------------------------------
FUNCTION MYAPPFORM_WM_CREATE ( _
                                  hWndForm AS DWORD, _  ' handle of Form
                                  BYVAL UserData AS LONG _  'optional user defined Long value
                                  ) AS LONG
  'Assumes initial data for text boxes has been set in array X$()
  '  and allowable range values (Min and Max) are in arrays MinX() and MaxX()
  'Each text box has an associated UpDown control with the same index number
  LOCAL I
  FOR I = 0 TO 9 'Set initial values for 10 text boxes in a control group
    FF_CONTROL_SETTEXT HWND_MYAPPFORM_TEXT1(I), X$(I) 'Set initial value with data in array X$
    SENDMESSAGE HWND_MYAPPFORM_UPDOWN1(I), %UDM_SETPOS, 0, CLNG(VAL(X$(I))) 'Set initial value for UpDown Control
    SENDMESSAGE HWND_MYAPPFORM_UPDOWN1(CI), %UDM_SETRANGE, 0, MAKLNG(MaxX(I), MinX(I)) 'Set Min and Max values for UpDown
  NEXT I
END FUNCTION


'------------------------------------------------------------------------------------------------------------------------
FUNCTION MYAPPFORM_UPDOWN1_WM_VSCROLL ( _
                                           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 LL AS LONG
  SELECT CASE nScrollCode
    CASE %SB_ENDSCROLL 'Respond when user finishes scrolling up or down
      FF_CONTROL_SETTEXT HWND_MYAPPFORM_TEXT1(ControlIndex), STR$(nPosition) 'Get the new value the user scrolled to
      'Call the following function to validate the new value
      LL = MYAPPFORM_TEXT1_EN_KILLFOCUS (ControlIndex, hWndForm, hWndControl, IDC_MYAPPFORM_TEXT1(ControlIndex))
  END SELECT
END FUNCTION

'------------------------------------------------------------------------------------------------------------------------
FUNCTION MYAPPFORM_TEXT1_EN_KILLFOCUS ( _
                                           ControlIndex   AS LONG,  _  ' index in Control Array
                                           hWndForm       AS DWORD, _  ' handle of Form
                                           hWndControl    AS DWORD, _  ' handle of Control
                                           idTextControl  AS LONG   _  ' identifier of text control
                                           ) AS LONG

  DIM X$, K AS LONG
  X$ = FF_CONTROL_GETTEXT(HWND_MYAPPFORM_TEXT1(ControlIndex)) 'Pick up value entered by user
  K = VAL(X$) 'Convert to long integer
  '
  'Code to validate new value entered by user; K adjusted if not valid
  '
  FF_CONTROL_SETTEXT(HWND_MYAPPFORM_TEXT1(ControlIndex), LTRIM$(STR$(K))) 'Set text box to adjusted value
  SENDMESSAGE HWND_MYAPPFORM_UPDOWN1(ControlIndex), %UDM_SETPOS, 0, K 'Set UpDown control to new position
END FUNCTION


Jean-Pierre LEROY

Thank you Rhody for your help.

I create a new project with a Control Array containing 10 TextBox and another Control Array containing 10 UpDown.

For the last UpDown control (index 9), I setup the range from -10 to -1 using this code

SendMessage HWND_MYAPPFORM_UPDOWN1(9), %UDM_SETPOS  , 0, CLng(-5)   
SendMessage HWND_MYAPPFORM_UPDOWN1(9), %UDM_SETRANGE, 0, MakLng(-1, -10)
FF_Control_SetText HWND_MYAPPFORM_TEXT1(9), Format$(-5)


Obviously, when I first run the program, the value (-5) in the textbox is correct  but then when I used the arrows the value displayed in the TextBox by the MYAPPFORM_UPDOWN1_WM_VSCROLL function is incorrect; I get these value : 65526 (where it should displayed -10) and 65535 (where it should displayed -1).

Is there a specific setting to manipulate negative range ? I don't understand why the WM_VSCROLL message doesn't return the right value in the nPosition parameter ? it works without any problem for positive range ? what about mixed range (I don't try so far) ?

Thanks
Jean-Pierre

RhodyRich

Since you are not getting a correctly signed value, this would indicate that the value you are dealing with is a WORD or DWORD and not a LONG integer value. WORD and DWORD integers are always positive and do not have a sign. I personally have not had to use negative numbers with the UpDown control so I do not have any specific help for you on this.

Jean-Pierre LEROY

The value that is displayed is directly the parameter nPosition which is a LONG integer value.

Could it be a problem with the way FireFly manage this parameter for the WM_VSCROLL message in the the MYAPPFORM_UPDOWN1_WM_VSCROLL function ?

Thanks again.
Jean-Pierre

RhodyRich

Sounds like an issue for tech support. Hopefully you will receive a response today.

David Kenny

#12
Looks like Paul didn't know that the values could be <0. If you try to set the min or max values in the properties dialog to a negative number, FF will tell you:
This property value must be between 0 and 32767.
But, as seen below, it can range from -32767 to 32767.

From CommCtrl.inc:
Quote%UD_MAXVAL            = &H7FFF
%UD_MINVAL            = - %UD_MAXVAL

Perhaps some of FF's code doesn't take this into account.

At first, I suspected Jean-Pierre's code because his min value is -1 and  his max value is -10.  But the Remarks, from the Win32 API Help below, show this is valid.  Thanks, Jean-Pierre, for the lesson.

From Win32 API Help:
QuoteUDM_SETRANGE
wParam = 0;
lParam = (LPARAM) MAKELONG((short) nUpper, (short) nLower);

The UDM_SETRANGE message sets the minimum and maximum positions (range) for an up-down control.

Parameters

nUpper and nLower
    Maximum position and minimum position for the up-down control. Neither position can be greater than the
    UD_MAXVAL value or less than the UD_MINVAL value. In addition, the difference between the two positions cannot exceed UD_MAXVAL.

Return Value

No return value.

Remarks

The maximum position can be less than the minimum position. Clicking the up arrow moves the current position closer to the maximum position, and clicking the down arrow moves towards the minimum position.

David

TechSupport

Thanks guys - I'm looking into this problem now. I'll get it all fixed up for the next update.

TechSupport

David - I just fixed that warning error. The Min and Max properties are shared amongst several FireFly controls so I needed to specifically exclude the UPDOWN control from firing this warning.

Still not sure why the negatives entered via code is not working. I just popped together an example app and will now decipher the code generation. Maybe I am cracking the message incorrectly.

Thanks!