==Reviewing the Stylebits Parameters==

The four parameters of stylebits are AddBit, RemoveBit, AddExtendedBit, RemoveExtendedBit.  For a review of these four parameters, and an introduction to Stylebits in general, please view [[Stylebits - Windows|Stylebits - Windows]].

==Stylebits and Formatted Text==

Many of the stylebits commands used with windows and textboxes can also be used with statictext controls.  Since statictext doesn't accept user input, most of the stylebits effects involve text formatting and borders.  Statictext can be justified horizontally using these commands -
[[code format="vb"]]
_ES_LEFT
_ES_CENTER
_ES_RIGHT
[[code]]
Statictext can also be centered vertically using the command -
[[code format="vb"]]
_SS_CENTERIMAGE
[[code]]
It is possible to create a nice etched look in your text using the command -
[[code format="vb"]]
_WS_DISABLED
[[code]]
Use this strategy with caution, though.  Any control disabled with the stylebits will require an API call to cause the statictext to later become enabled.  The same look can be achieved using the native Liberty BASIC command **!Disable** and affords the programmer the opportunity to normalize the text look using **!Enable** later in the code.

There are some very interesting visual effects that can be achieved using a stylebits created border around your statictext.

||  **Stylebits**                                                         ||
||  _WS_DLGFRAME, 0, 0, 0                                             || ..... ||  Raised Background            ||
||  0, 0, _WS_EX_STATICEDGE, 0                                        || ..... ||  Slightly Recessed Background ||
||  0, 0, _WS_EX_CLIENTEDGE, 0                                        || ..... ||  Deeper Recessed Background   ||
||  0, 0, _WS_EX_STATICEDGE or _WS_EX_CLIENTEDGE, 0                   || ..... ||  Double Recessed Background   ||
||  _WS_BORDER, 0, 0, 0                                               || ..... ||  Thin Line Border             ||
||  0, 0, _WS_EX_DLGMODALFRAME or _WS_EX_CLIENTEDGE, 0                || ..... ||  Raised Frame                 ||
||  _WS_THICKFRAME, 0, _WS_EX_DLGMODALFRAME or _WS_EX_CLIENTEDGE, 0   || ..... ||  Double Raised Frame          ||

===Stylebits and API Calls===

Stylebits allow statictext to display images, but only when accompanied by an API call to user32.dll (SendMessageA).  The height and width of the statictext will initially cause a smaller bitmap to stretch and fill the originally defined statictext dimensions.  You can prevent this distortion by either making certain the statictext width and height is the same as the loaded bitmap or using the _SS_CENTERIMAGE stylebits.  Recessed, raised and flat effects can be achieved using window edge stylebits.
Right - Click and save this bitmap as "boy.bmp" on your computer.  Run the demo from the same folder in which you saved the bitmap.  Once the code is run, maximizing the window will demonstrate how the bitmap stretches to fill the defined statictext area.
[[image:boy.bmp width="54" height="100"]]

[[code format="vb"]]
    WindowWidth=600
    WindowHeight=450

    UpperLeftX = Int((DisplayWidth - WindowWidth)/2)
    UpperLeftY = Int((DisplayHeight - WindowHeight)/2) - 14

    Nomainwin

    Loadbmp "boy", "boy.bmp"

    Statictext #main.st0, "", 10, 10, 54, 100
    Stylebits #main.st0, _SS_BITMAP, 0, 0, 0
    Statictext #main, "The bitmap boy.bmp 54 x 100.", 90, 30, 150, 56

    Statictext #main.st1, "", 10, 140, 80, 120
    Stylebits #main.st1, _SS_BITMAP or _WS_BORDER, 0, 0, 0
    Statictext #main, "Thin Line Border, Bitmap expands to fit defined statictext area (80 x 120) when window resized.", _
        100, 120, 150, 140

    Statictext #main.st2, "", 10, 300, 80, 120
    Stylebits #main.st2, _SS_BITMAP or _WS_BORDER, 0, _WS_EX_STATICEDGE, 0
    Statictext #main, "Etched look with _WS_BORDER and _WS_EX_STATEDGE, also resizes when window resized.", _
        100, 280, 150, 140

    Statictext #main.st3, "", 480, 70, 100, 150
    Stylebits #main.st3, _SS_BITMAP or _SS_CENTERIMAGE, 0, _WS_EX_CLIENTEDGE, 0
    Statictext #main, "_SS_ CENTERIMAGE prevents resizing when window resized.", 320, 90, 150, 140

    Statictext #main.st4, "", 480, 250, 100, 150
    Stylebits #main.st4, _SS_BITMAP or _SS_CENTERIMAGE, 0, _WS_EX_DLGMODALFRAME, 0
    Statictext #main, "Borders can be raised, recessed or flat.", 320, 280, 150, 140

    Open "Stylebits for Images on Statictext" for Window as #main
    #main, "Trapclose [closeDemo]"
    #main, "Font Times_New_Roman 14 Bold"
    hStatic0 = hWnd(#main.st0)
    hStatic1 = hWnd(#main.st1)
    hStatic2 = hWnd(#main.st2)
    hStatic3 = hWnd(#main.st3)
    hStatic4 = hWnd(#main.st4)
    hImage = hBmp("boy")
    Call setImage hStatic0, hImage
    Call setImage hStatic1, hImage
    Call setImage hStatic2, hImage
    Call setImage hStatic3, hImage
    Call setImage hStatic4, hImage
    Wait

    Sub setImage hStatic, hImage
    CallDLL #user32, "SendMessageA", _
        hStatic as Ulong, _
        _STM_SETIMAGE as Long, _
        _IMAGE_BITMAP as Long, _
        hImage as Ulong, _
        result as Long
    End Sub

[closeDemo]
    Close #main
    Unloadbmp "boy"
    End
[[code]]

These are just some examples of what you can do with stylebits and statictext.  With experimentation, you may find more.

===A List of Stylebits===

You can get a list of all dwStyles and dwExStyles available with the Stylebits command at the [[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_Styles_used_by_mfc.asp|MSDN Library Center]].