Announcement

Collapse
No announcement yet.

sdk transparent labels on gradient bkgrnd

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
    Michael Mattias
    Member

  • Michael Mattias
    replied
    DDT has some quirks re returning values directly, as required by the handling of WM_CTLCOLORSTATIC, specifcially you can't return the value zero. If GetStockObject(%NULL_BRUSH) = 0 (which it might well be), that will never get thru... a zero return gets read by DDT as "do default stuff" which is exactly what you are trying to NOT do.

    No, I don't know how to get around that other than using SDK-style coding syntax for the dialog.

    Leave a comment:

  • BOB MECHLER
    Member

  • BOB MECHLER
    replied
    Static sdk labels work DDT label has a little problem

    The following code takes some of the suggestions and tests a DDT label (which is why I started to learn about the SDK version) against SDK ones. I set an SDK label before the Dialog Show Modeless. Then I add a DDT label and an SDK label after the Dialog Show Modeless but before the message loop. I then add 4 more labels based on a button click. I tried to make the DDT LABEL work with the same styles, but as you can see it doesn't turn transparent. (I know about the -1,-2 approach prior to the Dialog Show Modeless but in my testing, this doesn't work on labels placed after the Dialog Show Modeless. A separate InvalidateRect is required for the DDT labels. Only the SDK labels work the way I want them too.
    Code:
    #DIM ALL
    #REGISTER ALL
    #INCLUDE "win32api.inc"
    
    GLOBAL ghMain AS DWORD,hFontCap AS LONG
        %LBL_LABEL = 1001
        %LBL_AFTER = 1002
        %LBL_DDT   = 1003
        %NEW_LBL1  = 1004
        %NEW_LBL2  = 1005
        %NEW_LBL3  = 1006
        %NEW_LBL4  = 1007
        %BUT_DDT   = 2001
    
    FUNCTION MakeFont(BYVAL CFont AS STRING, BYVAL PointSize AS LONG) AS LONG
    
      LOCAL hDC      AS LONG
      LOCAL CyPixels AS LONG
    
      hDC = GetDC(%HWND_DESKTOP)
      CyPixels  = GetDeviceCaps(hDC, %LOGPIXELSY)
      ReleaseDC %HWND_DESKTOP, hDC
    
      PointSize = (PointSize * CyPixels) \ 72
      FUNCTION = CreateFont(0 - PointSize, 0, 0, 0, %FW_NORMAL, 0, 0, 0, _
                %ANSI_CHARSET, %OUT_TT_PRECIS, %CLIP_DEFAULT_PRECIS, _
                %DEFAULT_QUALITY, %FF_DONTCARE, BYCOPY CFONT)
    END FUNCTION 
    
    CALLBACK FUNCTION dlgMain
      LOCAL szNewStaticText AS STRING 
      DIM hWndControl AS DWORD
      SELECT CASE CBMSG
          hFontCap = MakeFont("Ms Sans Serif",10)   
        CASE %WM_CTLCOLORSTATIC
          SELECT CASE GetDlgCtrlId(CBLPARAM) 
            CASE %LBL_LABEL TO %NEW_LBL4      'in case other labels need different handling
              SelectObject CBWPARAM, hFontCap
              SetBkMode CBWPARAM,%Transparent
             FUNCTION = GetStockObject(%NULL_BRUSH)
          END SELECT    
        CASE %WM_PAINT
          CALL PaintBg(CBHNDL,0,0,0)
        CASE %WM_COMMAND
          SELECT CASE CBCTL
            CASE %BUT_DDT
              szNewStaticText = "New Label 1"
              hWndControl = CreateWindowEx(%WS_EX_TRANSPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING , _
                                     "Static", _  ' window class name
                                     BYCOPY szNewStaticText, _    ' window caption
                                     %SS_LEFT OR %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN, _
                                     10, 64, 150, 18, _
                                     ghMain, %NEW_LBL1, GetModuleHandle(BYVAL 0&), BYVAL %NULL)
              szNewStaticText = "New Label 2"
              hWndControl = CreateWindowEx(%WS_EX_TRANSPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING , _
                                     "Static", _  ' window class name
                                     BYCOPY szNewStaticText, _    ' window caption
                                     %SS_LEFT OR %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN, _
                                     10, 84, 150, 18, _
                                     ghMain, %NEW_LBL2, GetModuleHandle(BYVAL 0&), BYVAL %NULL)
              szNewStaticText = "New Label 3"
              hWndControl = CreateWindowEx(%WS_EX_TRANSPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING , _
                                     "Static", _  ' window class name
                                     BYCOPY szNewStaticText, _    ' window caption
                                     %SS_LEFT OR %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN, _
                                     10, 104, 150, 18, _
                                     ghMain, %NEW_LBL3, GetModuleHandle(BYVAL 0&), BYVAL %NULL)
              szNewStaticText = "New Label 4"
              hWndControl = CreateWindowEx(%WS_EX_TRANSPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING , _
                                     "Static", _  ' window class name
                                     BYCOPY szNewStaticText, _    ' window caption
                                     %SS_LEFT OR %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN, _
                                     10, 124, 150, 18, _
                                     ghMain, %NEW_LBL4, GetModuleHandle(BYVAL 0&), BYVAL %NULL)
              
          END SELECT  
      END SELECT    
    END FUNCTION
    
    FUNCTION PBMAIN
        DIM hWndControl AS DWORD,szControlText AS STRING,cnt AS LONG
    
        DIALOG NEW 0, "Transparent sdk style label ",,,200,170,%WS_SYSMENU TO ghMain
    
        szControlText = "Before Show ghMain"
        hWndControl = CreateWindowEx(%WS_EX_TRANSPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING , _
                                     "Static", _  ' window class name
                                     BYCOPY szControlText, _    ' window caption
                                     %SS_LEFT OR %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN, _
                                     10, 10, 150, 18, _
                                     ghMain, %LBL_LABEL, GetModuleHandle(BYVAL 0&), BYVAL %Null)
        DIALOG SHOW MODELESS ghMain CALL dlgMain
        
        szControlText = "After Show ghMain"
        hWndControl = CreateWindowEx(%WS_EX_TRANSPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING , _
                                     "Static", _  ' window class name
                                     BYCOPY szControlText, _    ' window caption
                                     %SS_LEFT OR %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN, _
                                     10, 30, 150, 18, _
                                     ghMain, %LBL_AFTER, GetModuleHandle(BYVAL 0&), BYVAL %NULL)
    
        CONTROL ADD LABEL, ghMain,%LBL_DDT,"After Show ghMain DDT",7,30,60,10,%SS_LEFT OR %WS_CHILD OR %WS_VISIBLE _
                                                                   OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN, _
                                                                   %WS_EX_TRANSPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING
        CONTROL ADD BUTTON, ghMain,%BUT_DDT,"Add more labels",120,130,60,14                                                                                                                                 
        DO
          DIALOG DOEVENTS TO cnt      
        LOOP UNTIL cnt = 0
    END FUNCTION
    
    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&,Temp&,cRed&,cGreen&,cBlue&
         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
         Temp& = RGB(205,214,255)
         IF Temp& <> 0 THEN
           cRed&   = Temp& MOD 256
           cGreen& = (Temp& \ 256) MOD 256
           cBlue&  = ((Temp& \ 256) \ 256) MOD 256
         ELSE
           cRed&   = 192
           cGreen& = 224
           cBlue&  = 192
         END IF
         vert(0).x      = 0
         vert(0).y      = 0
         vert(0).Red    = SetColor(cRed& - 90)
         vert(0).Green  = SetColor(cGreen& - 90)
         vert(0).Blue   = SetColor(cBlue& - 90)
         vert(0).Alpha  = &h0000
         vert(1).x      = xin
         vert(1).y      = yin
         vert(1).Red    = SetColor(cRed&)
         vert(1).Green  = SetColor(cGreen&)
         vert(1).Blue   = SetColor(cBlue&)
         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

    Leave a comment:

  • Chris Boss
    Member

  • Chris Boss
    replied
    Frank,

    I would suggest that using a brush is not the best way to go there.

    You need to be able to draw a Bitmap which has transparent pixels.
    Your graphic tool should be able to do this, I would think.

    Using the API, you can use ImageLists, since they can draw bitmaps with transparent pixels (one unique RGB color is used to define the trasnparent pixels)

    Another technique is to BitBlt a Bitmap, but use a round cliiping region to draw only within the region. This can be done to draw a round image.

    Another technique is to use something like PB's GETBITs commands to get the pixels of the background and an image and then pixel by pixel combine them and then copy the pixels back.

    Leave a comment:

  • Chris Boss
    Member

  • Chris Boss
    replied
    Michael is correct about the color message. I was in a hurry to demonstrate the key method to make it work, not to handle multiple controls.

    Now to handle multiple controls it may be good to not test for control ID's but simply test for the WS_EX_TRANSPARENT extended window style of the control. This way multiple static controls could be used and the ones which are transparent would be handled correctly.

    Leave a comment:

  • Michael Mattias
    Member

  • Michael Mattias
    replied
    Code:
    CASE %WM_CTLCOLORSTATIC
             SetBKMode CBWPARAM, %TRANSPARENT
             FUNCTION=GetStockObject(%NULL_BRUSH)
             EXIT FUNCTION
    Works here because only one control is sending WM_CTLCOLORSTATIC. In general you'd want to trap to which control the notification message applies...
    Code:
    CASE %WM_CTLCOLORSTATIC
    [b]  IF GetDlgCtlId(CBLPARAM) = %LBL_LABEL THEN [/b]
             SetBKMode CBWPARAM, %TRANSPARENT
             FUNCTION=GetStockObject(%NULL_BRUSH)
             EXIT FUNCTION
    [b]  END IF  [/b]
    GetDlgCtlID(CBLPARAM) "might" equal CBCTL, but I'm not a DDT guy and don't feel like testing it myself.

    Leave a comment:

  • Frank Kestens
    Member

  • Frank Kestens
    replied
    Bitmap question

    Somehow off topic here , but i wanted to rephrase my question here to EZGUI
    http://www.powerbasic.com/support/pb...ad.php?t=36318

    Leave a comment:

  • Chris Boss
    Member

  • Chris Boss
    replied
    Another solution to the redrawing of the gradient background when resizing:

    Code:
        CASE %WM_SIZE
             InvalidateRect CBHNDL, BYVAL %NULL,1
    Forces the entire client area to be redrawn, when ever reiszed.

    I fixed the code I posted above to reflect this fix.

    Leave a comment:

  • Dominic Mitchell
    Member

  • Dominic Mitchell
    replied
    There is another problem you might have to deal with. If the window is resizeable, add the following code right after the DIALOG NEW statement.
    Code:
     SetClassLong ghMain, %GCL_STYLE, GetClassLong(ghMain, %GCL_STYLE) OR %CS_HREDRAW OR %CS_VREDRAW
    Click the maximize image(button) in the caption to see why.

    Leave a comment:

  • Chris Boss
    Member

  • Chris Boss
    replied
    Here is your code with the problem fixed. They key is handling the WM_CTLCOLORSTATIC message properly.

    Code:
    #DIM ALL
    #REGISTER ALL
    #INCLUDE "win32api.inc"
    GLOBAL ghMain AS DWORD
    CALLBACK FUNCTION dlgMain
      SELECT CASE CBMSG
        CASE %WM_ERASEBKGND
             FUNCTION=1
             EXIT FUNCTION
        CASE %WM_SIZE
             InvalidateRect CBHNDL, BYVAL %NULL,1
        CASE %WM_CTLCOLORSTATIC
             SetBKMode CBWPARAM, %TRANSPARENT
             FUNCTION=GetStockObject(%NULL_BRUSH)
             EXIT FUNCTION
        CASE %WM_PAINT
          CALL PaintBg(CBHNDL,0,0,0)
          FUNCTION=1    ' required for dialog procedure
          EXIT FUNCTION
      END SELECT
    END FUNCTION
     
    FUNCTION PBMAIN
        %LBL_LABEL = 1001
        DIM hWndControl AS DWORD,szControlText AS STRING
        DIALOG NEW 0, "Transparent sdk style label ", 0,0,150,170, %WS_OVERLAPPEDWINDOW OR %DS_CENTER OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN TO ghMain
        szControlText = "Sample Text"
        hWndControl = CreateWindowEx(%WS_EX_TRANSPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING , _
                                     "Static", _  ' window class name
                                     BYCOPY szControlText, _    ' window caption
                                     %SS_LEFT OR %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN, _
                                     10, 10, 150, 15, _
                                     ghMain, %LBL_LABEL, GetModuleHandle(BYVAL 0&), BYVAL %Null)
        DIALOG SHOW MODAL ghMain CALL dlgMain
    END FUNCTION
    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&,Temp&,cRed&,cGreen&,cBlue&
         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
         Temp& = RGB(205,214,255)
         IF Temp& <> 0 THEN
           cRed&   = Temp& MOD 256
           cGreen& = (Temp& \ 256) MOD 256
           cBlue&  = ((Temp& \ 256) \ 256) MOD 256
         ELSE
           cRed&   = 192
           cGreen& = 224
           cBlue&  = 192
         END IF
         vert(0).x      = 0
         vert(0).y      = 0
         vert(0).Red    = SetColor(cRed& - 90)
         vert(0).Green  = SetColor(cGreen& - 90)
         vert(0).Blue   = SetColor(cBlue& - 90)
         vert(0).Alpha  = &h0000
         vert(1).x      = xin
         vert(1).y      = yin
         vert(1).Red    = SetColor(cRed&)
         vert(1).Green  = SetColor(cGreen&)
         vert(1).Blue   = SetColor(cBlue&)
         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
    Chris Boss
    Member
    Last edited by Chris Boss; 16 Feb 2008, 12:38 AM.

    Leave a comment:

  • BOB MECHLER
    Member

  • BOB MECHLER
    started a topic sdk transparent labels on gradient bkgrnd

    sdk transparent labels on gradient bkgrnd

    I can't figure out why the following code doesn't produce a transparent sdk label since I use the ws_ex_transparent style. I paint the background with a gradient.

    First, am I doing the 'static' control correctly. Secondly, is it required to use a null_brush in the dialog call back to get it to go transparent?

    I've started looking at ownerdrawn but don't see how I can remove the drawtext or textout output.

    Code:
    #DIM ALL
    #REGISTER ALL
    #INCLUDE "win32api.inc"
    
    GLOBAL ghMain AS DWORD
    
    CALLBACK FUNCTION dlgMain 
      SELECT CASE CBMSG
        CASE %WM_PAINT
          CALL PaintBg(CBHNDL,0,0,0)
      END SELECT    
    END FUNCTION
    
    
    FUNCTION PBMAIN
        %LBL_LABEL = 1001
        DIM hWndControl AS DWORD,szControlText AS STRING
    
        DIALOG NEW 0, "Transparent sdk style label ", 0,0,150,170, %WS_OVERLAPPEDWINDOW OR %DS_CENTER TO ghMain
        szControlText = "Sample Text"
        hWndControl = CreateWindowEx(%WS_EX_TRANSPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING , _
                                     "Static", _  ' window class name
                                     BYCOPY szControlText, _    ' window caption
                                     %SS_LEFT OR %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN, _
                                     10, 10, 150, 15, _
                                     ghMain, %LBL_LABEL, GetModuleHandle(BYVAL 0&), BYVAL %Null)
        DIALOG SHOW MODAL ghMain CALL dlgMain
    
    END FUNCTION
    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&,Temp&,cRed&,cGreen&,cBlue&
         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
         Temp& = RGB(205,214,255)
         IF Temp& <> 0 THEN
           cRed&   = Temp& MOD 256
           cGreen& = (Temp& \ 256) MOD 256
           cBlue&  = ((Temp& \ 256) \ 256) MOD 256
         ELSE
           cRed&   = 192
           cGreen& = 224
           cBlue&  = 192
         END IF
         vert(0).x      = 0
         vert(0).y      = 0
         vert(0).Red    = SetColor(cRed& - 90)
         vert(0).Green  = SetColor(cGreen& - 90)
         vert(0).Blue   = SetColor(cBlue& - 90)
         vert(0).Alpha  = &h0000
         vert(1).x      = xin
         vert(1).y      = yin
         vert(1).Red    = SetColor(cRed&)
         vert(1).Green  = SetColor(cGreen&)
         vert(1).Blue   = SetColor(cBlue&)
         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
Working...
X