Announcement

Collapse
No announcement yet.

Help with Edit Control Color?

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

  • Help with Edit Control Color?

    I have been though the POFFS database (offline!) but I still can't figure out how to do something.

    Using PB/DLL 6.0 SDK/API-style (non-DDT) I have a dialog box; one of the controls on the box is a 5-line "edit" control which I am using for output. The resource file (*.rc) entry:

    Code:
       EDITTEXT IDD_OUTPUT_BOX,   156, 132, 108, 56, ES_LEFT|ES_READONLY|ES_MULTILINE, WS_EX_CLIENTEDGE
    The way the dialog works (and it DOES work!) is the user plays around with the controls to set some values, then presses an "OK" button. At that point I do some calculations (they do NOT work yet) and display the results in this edit control. The user can then change values and press "OK" again to get new calculations (or press "Quit" to exit).

    What I want to do with this control is twofold.

    First, I would like to "color" the control so that the output stands out on the screen; ie... does not just look like a dark area on the screen. (Just blue/red text on white background would be fine).

    Second (and this may not even be possible). If the user changes something on the screen which means a "recalculation" is necessary, I wish to then "dim" or "recolor" the control's text (not erase it!) so the user knows that what's in the output box is no longer valid. (Actually, this could just revert to the default colors).

    I could just disable the "OK" button unless the current output is valid, but that does not have the visual impact I am seeking.

    Can anyone point me in the right direction? Do I need to change to a "richedit" control to do this? Subclass the edit control?

    FWIW, this is not a "for profit" venture - my plans are to give away the executable program (it's an IBM mainframe VSAM allocation space calculator) with lots of advertising in the "about" box which says, "see, I *can* do Windows as well as mainframe."

    Thanks in advance,


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

  • #2
    Check out %WM_CTLCOLOREDIT

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      That was a good tip. It led me to WM_CTLCOLORSTATIC which is what you are supposed to used with a STATIC (label) control.

      I am intercepting the message OK in the DialogProc, but what I am returning to the function may be wrong.

      I do this:

      Code:
          Static hbrush as long, hbrushobject as long
      
          SELECT CASE iMsg
            CASE %wm_initdialog
               hBrush = CreateSolidBrush (%WHITE_BRUSH)
            ...
      
            CASE %WM_CTLCOLORSTATIC
                   IF GETDlgCtrlId (lParam) = %IDD_OUTPUT_BOX THEN
                      hBrushObject = SelectObject( WParam, hBrush)   ' set static var
                      IF hBrushObject = %NULL THEN
                        MSGBOX "%NULL return from SelectObject= " & STR$(HbrushObject)
                      END IF
                      FUNCTION = hBrushObject
                      EXIT FUNCTION
                   END IF
            ...
            CASE %WM_COMMAND
                SELECT CASE LOWRD(wParam)
                CASE %IDD_QUIT
                  DeleteObject hBrushObject
                  EndDialog hWnd, 0
      I've tried %WHITE_BRUSH, %LTGRAY_BRUSH and %GRAY_BRUSH, and the background of my static (LTEXT) control is always white. It looks good this way, but I can't help but think it should different depending on the %xxx_BRUSH color.

      Shouldn't the background color be different?

      Anyone wants to play with this, I can send it (about 900 lines + 100-line resource file)


      MCM

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

      Comment


      • #4
        1. You should be destroying your custom brush in the %WM_DESTROY handler, not in your own close handler. If you do not do this, then you open the app up to a memory leak while it is running.

        2. When you intercept %WM_CTLCOLORxxxx, you only need to returnt he handle of the your brush, not the handle of the previous brush which SelectObject() returns. ie, your code is doing way too much.
        Code:
        ...
        CASE %WM_CTLCOLORSTATIC
           FUNCTION = hBrush
           EXIT FUNCTION
        CASE...

        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          FOUND IT!

          Should not be

          Code:
          hbrush = CreateSolidBrush (%WHITE_BRUSH) 
          ....
             FUNCTION = hBrush
          It should be:
          Code:
          hBrush = GetStockObject (%WHITE_BRUSH)
           ...
             FUNCTION = hBrush
          Works with white, gray, ltgray (well, with ltgray it's the same color as the dialog box, so that's not much of a test, but it's obviously different from white or ltgray)

          I'll also change to destroy hbrush in WM_DESTROY

          MCM




          [This message has been edited by Michael Mattias (edited August 19, 2000).]
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment

          Working...
          X