Announcement

Collapse
No announcement yet.

Control Add Label

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Control Add Label

    Please add your comments and suggestions as a Reply to this thread.





    PB/WIN - CONTROL ADD LABEL statement

    Purpose
    Add a text label to a dialog. A text label is similar to a conventional static control.
    Syntax
    CONTROL ADD LABEL, hDlg, id&, txt$, x, y, xx, yy [, [style&] [, [exstyle&]]] [[,] CALL callback]
    hDlg
    Handle of the dialog in which the label will be created. The dialog will become the parent of the control.
    id&
    Unique identifier for the control in the range 1 to 65535, frequently specified with numeric equates for clarity of the code. For example, the equate %BlockTitle is more informative than a literal value such as 497. If you will not be changing the text in a line control after it is created, you may use -1 for the id&; however, best practice suggests identifiers should start at 100 to avoid conflict with any of the standard predefined identifiers.
    txt$
    Text to be displayed in text label. An ampersand (&) may be included in txt$ to specify a hot-key. See the Remarks section below.
    x, y
    Integral expressions, variables, or numeric literal values, specifying the location of the control inside the dialog client area. x is the horizontal position, and y is the vertical position. 0,0 refers to the upper left corner of the dialog box client area. Coordinates are specified in the same terms (pixels or dialog units) as the parent dialog.
    xx
    Integral expression, variable, or numeric literal value, specifying the width of the control. The width is given in the same terms (pixels or dialog units) as the parent dialog. The most common value used in the Microsoft Dialog Editor and Visual Studio is 40 dialog units.
    yy
    Integral expression, variable, or numeric literal value, specifying the height of the control. The height is given in the same terms (pixels or dialog units) as the parent dialog. The most common value used in the Microsoft Dialog Editor and Visual Studio is 8 dialog units.
    style&
    Primary style of the label control. The default label style is %SS_LEFT. The default style is used if both the primary and extended style parameters are omitted from the statement. For example:

    Code:
    CONTROL ADD LABEL, hDlg, id&, txt$, 100, 100, 150, 200, , , _
      CALL LabelCallback() ' Use default styles
    Custom style values replace the default values. That is, they are not additional to the default style values - your code must specify all necessary primary and extended style parameters.

    The primary label style value can be a combination of any values below, combined together with the OR operator to form a bitmask:
    %SS_CENTER
    Horizontally center the caption text. The text is formatted before it is displayed. Words that extend past the end of a line are automatically wrapped to the beginning of the next centered line.
    %SS_CENTERIMAGE
    Vertically center the caption text. The text is not wrapped even if it extends beyond the width of the control.
    %SS_ENDELLIPSIS
    Replace the end of the given string with ellipsis as needed to fit the result in the specified rectangle. Windows NT/2000/XP only.
    %SS_ETCHEDFRAME
    Draw the frame of the control using an etched edge style.
    %SS_ETCHEDHORZ
    Draw the horizontal edges of the control using an etched edge style.
    %SS_ETCHEDVERT
    Draw the vertical edges of the control using an etched edge style.
    %SS_LEFT
    Left-align the given text. The text is formatted before it is displayed. Words that extend past the end of a line are automatically wrapped to the beginning of the next left-aligned line. (default)
    %SS_NOPREFIX
    Prevent interpretation of ampersand (&) characters in the label text as control accelerator prefix characters. These are normally displayed with the ampersand removed and the next character in the string underscored.
    %SS_NOTIFY
    Send %STN_CLICKED and %STN_DBLCLK notification messages to the Callback Function when the user clicks or double-clicks the control.
    %SS_NOWORDWRAP
    Left-align the given text. Tabs are expanded but words are not wrapped. Text that extends past the end of a line is clipped.
    %SS_PATHELLIPSIS
    Replace the file path portion of the given string with ellipsis as needed to fit the result in the specified rectangle. Windows 2000/XP only.
    %SS_RIGHT
    Right-align the given text. The text is formatted before it is displayed. Words that extend past the end of a line are automatically wrapped to the beginning of the next right-aligned line.
    %SS_SIMPLE
    The caption text is left-aligned. If the control is colored, color is only applied to the region containing the caption text, and the remainder of the control is drawn in standard colors.
    %SS_SUNKEN
    Draw a half-sunken border around the label control.
    %SS_WORDELLIPSIS
    Truncate text that does not fit, adding ellipsis as needed. Windows NT/2000/XP only
    %WS_GROUP
    Define the start of a group of controls. The first control in each group should also use %WS_TABSTOP style. The next %WS_GROUP control in the tab order defines the end of this group and the start of a new group.
    exstyle&
    Extended style of the label control. The default extended label style comprises %WS_EX_LEFT. The default extended style is used if both the primary and extended parameters are omitted from the CONTROL ADD LABEL statement, in the same manner as style& above.

    The extended label style value can be a combination of any values below, combined together with the OR operator to form a bitmask:
    %WS_EX_CLIENTEDGE
    Apply a sunken edge border to the control.
    %WS_EX_LEFT
    The control has generic "left-aligned" properties. (default)
    %WS_EX_RIGHT
    The control has generic "right-aligned" properties. This style has an effect only if the shell language is Hebrew, Arabic, or another language that supports reading order alignment; otherwise, the style is ignored.
    %WS_EX_STATICEDGE
    Apply a three-dimensional border style to the control (intended to be used for items that do not accept user input).
    %WS_EX_TRANSPARENT
    Controls/windows beneath the control are drawn before the control is drawn. The control is deemed transparent because elements behind the control have already been painted - the control itself is not drawn differently. True transparency is achieved by using Regions - see MSDN for more information.
    %WS_EX_WINDOWEDGE
    Apply a raised edge border to the control.
    callback
    Optional name of a Callback Function that receives all %WM_COMMAND and %WM_NOTIFY messages for the control. See the #MESSAGES metastatement to choose which messages will be received. If a callback for the control is not designated, you must create a dialog Callback Function to process messages from your control.

    If the Callback Function processes a message, it should return TRUE (non-zero) to prevent the message being passed unnecessarily to the dialog callback (if one exists). The dialog callback should also return TRUE if the notification message is processed by that Callback Function. Otherwise, the DDT engine processes unhandled messages.
    Remarks
    If the ampersand (&) character appears in the txt$ parameter, the letter that follows will be displayed underscored. This adds a control accelerator (hot-key) to enable the user to directly "click" the control that immediately follows in the Tab-Order after the Label control, simply by pressing and holding the ALT key while pressing the specified hot-key. For example, "Choose &Security Level" makes ALT+S the hot-key.

    A label control will only send messages to a callback if the %SS_NOTIFY style is used. The following notifications are sent to the Callback Function:
    %STN_CLICKED
    Sent when the user clicks a mouse button, or activates the button with the hot-key (unless the button has been disabled).
    %STN_DBLCLK
    Sent when the user double-clicks on a label control (unless the control has been disabled).
    %STN_DISABLE
    Sent when a button is disabled.
    %STN_ENABLE
    Sent when a label control has been enabled.
    Use the CONTROL SET TEXT statement to change the text in a label control and CONTROL SET FONT to change the font used in a label control. This is only possible if the label has a unique ID value (i.e., id& should not be -1).

    When a Callback Function receives a %WM_COMMAND message, it should explicitly test the value of CB.CTL and CB.CTLMSG to guarantee it is responding appropriately to the notification message.
    See AlsoReferences
    Last edited by Gary Beene; 28 Oct 2014, 06:01 PM.

  • #2
    example needed

    It would be great if there was a small example to show how to use this information:

    A label control will only send messages to a callback if the %SS_NOTIFY style is used. The following notifications are sent to the Callback Function:

    %STN_CLICKED
    Sent when the user clicks a mouse button, or activates the button with the hot-key (unless the button has been disabled).
    %STN_DBLCLK
    Sent when the user double-clicks on a label control (unless the control has been disabled).
    Perhaps a simplified version of one that's in this thread?
    http://www.powerbasic.com/support/pb...k+%25ss_notify


    -John

    P.S. Thanks for all the work in these Help update threads!
    Last edited by John Montenigro; 29 Oct 2014, 10:57 AM.

    Comment


    • #3
      Here's a basic example ...
      Code:
      #Compile EXE
      #Dim All
      %IDC_Label = 500
      #Include "Win32API.inc"
      Global hDlg As Dword
      
      Function PBMain() As Long
         Dialog New Pixels, 0, "Label Test",300,300,200,200, %WS_SysMenu, 0 To hDlg
         Control Add Label, hDlg, %IDC_Label,"Read Me", 50,50,100,20,%SS_Notify Or %WS_Border
         Dialog Show Modal hDlg Call DlgProc
      End Function
      
      CallBack Function DlgProc() As Long
         Select Case Cb.Msg
            Case %WM_Command
               Select Case Cb.Ctl
                  Case %IDC_Label
                     Select Case CB.CtlMsg
                        Case %STN_Clicked
                           Dialog Set Text hDlg, "Clicked"
                        Case %STN_DblClk
                           Dialog Set Text hDlg, "Double Clicked"
                     End Select
               End Select
         End Select
      End Function

      Comment


      • #4
        Wording in remarks re SS_NOTIFY is confusing. (See: https://forum.powerbasic.com/forum/u...833#post800833 10 Oct 2020)

        Should add clarifying text (suggested in bold) so the section reads something like..


        A label control will only send messages to a callback if the %SS_NOTIFY style is used. The following notifications are sent to the Callback Function as CB.CTLMSG when CB.MSG is %WM_COMMAND
        :

        %STN_CLICKED
        Sent when the user clicks a mouse button, or activates the button with the hot-key (unless the button has been disabled).



        %STN_DBLCLK
        Sent when the user double-clicks on a label control (unless the control has been disabled).



        %STN_DISABLE
        Sent when a button is disabled.



        %STN_ENABLE
        Sent when a label control has been enabled.

        MCM
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment

        Working...
        X