Announcement

Collapse
No announcement yet.

Change TextBox Color on FOCUS and ENDFOCUS

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

  • Change TextBox Color on FOCUS and ENDFOCUS

    I have 7 TEXTBoxes and I'm subclassing all of then via:

    Code:
    SetWindowLong(GetDlgItem(hDlg&, %hDLG_TEXT1), %GWL_WNDPROC, CodePtr(CB_SUB_TEXT1)
    etc etc
    I'm destroying them at %WM_DESTROY in DlgProc

    I can successfully trap %EN_SETFOCUS at the DlgProc level but
    not at the subclassed level, I'm wanting to be able to change
    the color of a textbox when it received focus to:

    Code:
        SetTextColor Cbwparam, %Red
        SetBkColor Cbwparam, %Yellow
    and when it looses focus:

    Code:
    SetTextColor Cbwparam, %Black
    SetBkColor Cbwparam, %White
    I know I will need to create my two brushes %white and %yellow
    and destroy them at %%WM_DESTROY

    Any suggestions? Do I have to do the color changing within
    DlgProc or can I do it in its Own SubClassed Callback?

    I can even get %EN_SETFOCUS notification on my SubClassed
    callback, but I do receive it via DlgProc, and use Cbctl to
    receive the control.

    Thanks


    ------------------
    -Greg

    [This message has been edited by Gregery D Engle (edited March 31, 2001).]
    -Greg
    [email protected]
    MCP,MCSA,MCSE,MCSD

  • #2
    Use GetFocus in your %WM_CTLCOLOR.. handler, like in PB's SMTP sample:
    Code:
        CASE %WM_CTLCOLOREDIT
          IF CBLPARAM = GetFocus THEN
            SetTextColor CBWPARAM, %BLACK
            SetBkColor CBWPARAM, %WHITE
            FUNCTION = GetStockObject(%WHITE_BRUSH)
          ELSE
            SetTextColor CBWPARAM, %BLUE
            SetBkColor CBWPARAM, %LTGRAY 'RGB(255, 255, 196) '%LTGRAY
            FUNCTION = GetStockObject(%LTGRAY_BRUSH)  '%LTGRAY_BRUSH
          END IF
    Note: to be placed in Main dialog's callback procedure..

    ------------------


    [This message has been edited by Borje Hagsten (edited March 31, 2001).]

    Comment

    Working...
    X