Announcement

Collapse
No announcement yet.

Transparent label bkgrd on gradient dialog

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

  • BOB MECHLER
    replied
    The following code works fine and I also know now why mine doesn't.
    As long as the CONTROL SET COLOR statements and labels are added prior to the DIALOG SHOW whether MODAL or MODELESS, they work fine. My code does the DIALOG SHOW MODELESS first and add my labels and other controls after that. If the following code had the CONTROLS ADDED after a DIALOG SHOW MODELESS and BEFORE it encountered the DO/LOOP they won't work without Invalidating the Rect.

    That makes me wonder if I should create all the controls my screen will ever use and then hide them prior to the DIALOG SHOW MODELESS STATMENT.

    Code:
    #DIM NONE
    #INCLUDE "WIN32API.INC"
    'Code for SetColor and PaintBg from an example by Chris Boss
    FUNCTION SetColor (BYVAL tCOLOR AS BYTE) AS WORD
        ' the windows api GradientFill routine wants r/g/b colors to be
        ' 16 bit words with the 8 bit color values left shifted 8 bits.
        ' this takes care of that.
        LOCAL clr AS WORD
        clr = tCOLOR
        SHIFT LEFT clr, 8
        FUNCTION = clr
    END FUNCTION
    SUB PaintBg(BYVAL hDialog AS LONG, BYVAL r AS LONG, BYVAL g AS LONG, BYVAL b AS LONG)
         ' this is to paint the background of the dialog
         ' it's all straight out of the MSDN help file.  We can change the values
         ' if we like.
         LOCAL ps AS PAINTSTRUCT
         LOCAL rc AS Rect
         LOCAL hDc AS DWORD
         LOCAL Xin&
         LOCAL Yin&
         DIM vert(1) AS TRIVERTEX
         DIM gRect AS GRADIENT_RECT
         hDC = BeginPaint(hDialog, ps)
           ' Tile the background
         GetClientRect hdialog, rc
         Xin = rc.nRight - rc.nLeft
         Yin = rc.nBottom - rc.nTop
         Xin = rc.nRight - rc.nLeft
         Yin = rc.nBottom - rc.nTop
         vert(0).x      = 0
         vert(0).y      = 0
         vert(0).Red    = SetColor(r)
         vert(0).Green  = SetColor(g)
         vert(0).Blue   = SetColor(b)
         vert(0).Alpha  = &h0000
         vert(1).x      = xin
         vert(1).y      = yin
         vert(1).Red    = SetColor(255)
         vert(1).Green  = SetColor(255)
         vert(1).Blue   = SetColor(255)
         vert(1).Alpha  = &h0000
         gRect.UpperLeft  = 0
         gRect.LowerRight = 1
         GradientFill hDc, vert(0), 2, gRect, 1, %GRADIENT_FILL_RECT_v
         EndPaint hDialog, ps
    END SUB                                 
    CALLBACK FUNCTION hdlgproc
      SELECT CASE CBMSG
        CASE %WM_PAINT
          CALL PaintBg(CBHNDL,0,0,0)
      END SELECT
    END FUNCTION
    FUNCTION PBMAIN
      DIALOG NEW 0,"Transparent label background test",,,200,300,%WS_SYSMENU TO hdlg&
      DIALOG FONT "Arial",10
      CONTROL ADD LABEL, hdlg&,1001,"Test Label",10,100,60,15
      CONTROL ADD LABEL, hdlg&,1002,"Test Label",10,115,60,15
      CONTROL ADD LABEL, hdlg&,1003,"Test Label",10,130,60,15
      CONTROL ADD LABEL, hdlg&,1004,"Test Label",10,145,60,15
      CONTROL ADD LABEL, hdlg&,1005,"Test Label",10,160,60,15
      CONTROL SET COLOR hdlg&,1001,%BLACK,-2&
      CONTROL SET COLOR hdlg&,1002,%BLACK,-2&
      CONTROL SET COLOR hdlg&,1003,%BLACK,-2&
      CONTROL SET COLOR hdlg&,1004,%BLACK,-2&
      CONTROL SET COLOR hdlg&,1005,%BLACK,-2&
      DIALOG SHOW MODAL hdlg& CALL hdlgproc
        
    END FUNCTION

    Leave a comment:


  • Michael Mattias
    replied
    >Is there a way to erase text drawn by textout

    I have cheated on this by doing a FillRect with the background color before TextOut or DrawText....

    I think I posted an example of this somewhere, let me look...yes, I did...

    Listview with Multiple Checkbox Columns Demo 2-20-05

    The FillRect() is even in bold! (I had to add that later after some sharp-eyed user noted that I needed to do 'something' about the old text not going away).

    Don't know how that will work with your gradient.

    Maybe it's just as simple as invalidating the rect (with the erase background flag set) where you want to draw the text and forcing a repaint. But that will no doubt have a 'flicker' unless your paint routine is set up to only paint the invalid portion of the screen. (code not shown).

    MCM
    Last edited by Michael Mattias; 3 Feb 2008, 09:27 AM.

    Leave a comment:


  • BOB MECHLER
    replied
    After I do a DIALOG SHOW MODELESS, I add all my controls to hdlg. Labels act like their is no gradient and even though I now use the %WS_EX_TRANSPARENT property when adding LABELS, it still uses the Dialog color initially set, even though I use a %NULL_BRUSH in the callback. If I specifically cause the entire window to be come Invalid, then the labels are drawn with a transparent background.

    If I use the coordinates of the label and translate them to pixels and use the textout function with setbkmode hdc,%transparent, selectobject hdc,hFontCap instead, it draws right the first time.

    Is there a way to erase text drawn by textout. The only way I've found is to textout the same text but in the background color of the dialog. With a gradient situation I'm not sure how to do that since it is a different color depending on where the textout text was placed. (GetBkColor?) with DC of the dialog client area?

    I'll post code later today of what happens with the two methods. I wasted a lot of hours yesterday trying to get this working without having to invalidate the entire dialog client area to have the lables redraw and honor the WS_EX_TRANSPARENT style. Textout worked the first time with those attributes set.

    BOB MECHLER

    Leave a comment:


  • Michael Mattias
    replied
    If GetStockObject (%NULL_BRUSH) returns zero (I would not be surprised were that so) I think DDT has a little problem.

    Try using a different stock object, eg GetStockObject (%WHITE_BRUSH). If that results in a white background, then your problem is as suggested.

    If that doesn't solve the problem, at least you will know what it isn't.

    If that is the problem, you may have to go to full owner-draw or eschew DDT-style for SDK-style for this screen.

    Leave a comment:


  • Chris Boss
    replied
    Use the WS_EX_TRANSPARENT extended window style with the label controls, so they repaint after the dialog does and only the text.

    If you change the text of the labels dynamically after being created, you will have to invalidate their client areas too, to make sure the background redraws correctly.

    Leave a comment:


  • Chris Holbrook
    replied
    Have you considered PTFC?

    Leave a comment:


  • BOB MECHLER
    replied
    Doing a Dialog Redraw hdlg just before my first textbox got focus did the trick but I'd like somewhere in the dialog call back to be the place where it's called.

    Bob Mechler

    Leave a comment:


  • BOB MECHLER
    started a topic Transparent label bkgrd on gradient dialog

    Transparent label bkgrd on gradient dialog

    I'm using some gradient code to paint my dialog background in the WM_PAINT event. I'm using the code below to color the labels
    Code:
          CASE %WM_CTLCOLORSTATIC
              SELECT CASE GetDlgCtrlID(CBLPARAM) 
                CASE 500 TO 1500
                  SetBkMode CBWPARAM, %Transparent
                  SelectObject CBWPARAM, hFontCap 
                  FUNCTION = GetStockObject(%NULL_BRUSH)
    When my dialog comes up the background is gradient from rgb(202,214,255) down to white but the label background is rgb(202,214,255). If I click a button, the label background turns to the shade of the gradient at that position on the screen which is the way I want it to start out.

    I would like the label background to be transparent, showing the shade behind it from initialization. I would also like to try making the label background itself a gradient but will probably have to subclass the control to do that.

    Bob Mechler
Working...
X