Announcement

Collapse
No announcement yet.

Dynamically Changing DDT Label Color

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

  • Mark Newman
    replied
    I didn't! The WinAPI help file said to use RemoveProp() for each property
    that was added using SetProp. I put RemoveProp() in the WM_DESTROY message
    handler, so as each control in the dialog is destroyed the properties are
    removed as well. I haven't checked for memory leaks yet, but I think I have
    it right.

    Thanks for pointing that out though.


    ------------------
    Mark Newman

    Leave a comment:


  • Edwin Knoppert
    replied
    Don't forget removeprop()

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

    Leave a comment:


  • Mark Newman
    replied
    I didn't know about SetProp(), it's not even in Petzold's book. Hmmm.

    I changed my code as suggested and it works great - thanks for the help!


    ------------------
    Mark Newman

    Leave a comment:


  • Lance Edmonds
    replied
    Mark, your code looks like a snippet from a drawing routine (WM_PAINT)... if the conrtol is not drawn by you (ie, it is a standard control), the callback must intercept %WM_CTLCOLORxxxx messages.

    The "usual" approach is to define a custom message in the callback, say, (%WM_USER + 700&) and the code in that handler stores the color information and invalidates the control. This triggers the control repaint, which sends the appropriate %WM_CTLCOLORxxx message, and your new color for the control are used.

    You could use STATIC variables to save the color state, or like Edwin suggests, SetProp() and GetProp().

    So, when you wish to change the color from outside of the callback, you simply send the custom message to the parent window.

    While there are other ways to do it, this strategy keeps all of the dialog-specific code within the callback, and not scattered throughout the program.

    There is one fly in the ointment though - the %WM_CTLCOLORBTN message wont allow you to change the color of buttons... the usual workaround here is to use owner-draw or superclassed buttons.

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

    Leave a comment:


  • Edwin Knoppert
    replied
    If you try FreeDDT from my site, you'll see i make use of SetProp/GetProp for colors.
    Idea?


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

    Leave a comment:


  • Mark Newman
    started a topic Dynamically Changing DDT Label Color

    Dynamically Changing DDT Label Color

    How does one change the fore/background colors of a DDT Label control outside of
    the dialog callback? I've searched the forums and found examples of how to change
    the colors inside the callback but nothing else. I tried this code but it didn't work:
    Code:
       hWnd = GetDlgItem(hDlg, %LABEL_STATUS)
       hDC = GetDC(hWnd)
       SetTextColor hDC, %White
       SetBkColor hDC, %Red
    I need to be able to set the colors to indicate a failure condition to the user.

    Thanks!



    ------------------
    Mark Newman
Working...
X