Announcement

Collapse
No announcement yet.

How to change the color of a controls text/label?

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

  • How to change the color of a controls text/label?

    The following demo loads a frame on a dialog window and sets it to Bold...
    Can someone please tell me how to modify it to change the colour of that control? many thanks!

    Code:
    #COMPILE EXE
    #INCLUDE "win32api.inc"
    GLOBAL hDlg AS LONG
     
    SUB MakeBold(FontObject AS LONG)
      ON ERROR RESUME NEXT
            LOCAL hFont             AS LONG
            LOCAL lf AS LOGFONT
            CONTROL SEND hDlg, FontObject, %WM_GETFONT, 0, 0 TO hFont
            GetObject hFont, SIZEOF(lf), BYVAL VARPTR(lf)
            lf.lfWeight = %FW_BOLD
            hFont = CreateFontIndirect(lf)
            CONTROL SEND hDlg, FontObject, %WM_SETFONT,hFont, 1
    END SUB
     
    FUNCTION WinMain (BYVAL hInstance     AS LONG, _
                      BYVAL hPrevInstance AS LONG, _
                      lpCmdLine           AS ASCIIZ PTR, _
                      BYVAL iCmdShow      AS LONG) AS LONG
    ON ERROR RESUME NEXT
          Dialog New 0, "Font Test", ,, 203, 89, %WS_CAPTION Or %WS_SYSMENU + %WS_MINIMIZEBOX, To hDlg
          CONTROL ADD FRAME, hDlg, 99, "Caption",         3  ,10, 200,40, %BS_CENTER, 0
          CALL MAKEBOLD(99)
          DIM hDC AS LONG
          Dialog Show Modal hDlg
    End Function
    ------------------
    -

  • #2
    Wayne:

    Here's your code example with a dialog callback added...
    Code:
    #COMPILE EXE
    #INCLUDE "win32api.inc"
    GLOBAL hDlg AS LONG
    
    
    SUB MakeBold(FontObject AS LONG)
      ON ERROR RESUME NEXT
            LOCAL hFont             AS LONG
            LOCAL lf AS LOGFONT
            CONTROL SEND hDlg, FontObject, %WM_GETFONT, 0, 0 TO hFont
            GetObject hFont, SIZEOF(lf), BYVAL VARPTR(lf)
            lf.lfWeight = %FW_BOLD
            hFont = CreateFontIndirect(lf)
            CONTROL SEND hDlg, FontObject, %WM_SETFONT,hFont, 1
    END SUB
    
    
    CALLBACK FUNCTION DlgProc
       SELECT CASE CBMSG
       CASE %WM_CTLCOLORSTATIC
          SELECT CASE GetDlgCtrlId(CBLPARAM)
          CASE 99
             SetTextColor CBWPARAM, %RED
             SetBkColor CBWPARAM, %LTGRAY
             FUNCTION = GetStockObject(%LTGRAY_BRUSH)
          END SELECT
       END SELECT
    END FUNCTION
    
    
    FUNCTION WINMAIN (BYVAL hInstance     AS LONG, _
                      BYVAL hPrevInstance AS LONG, _
                      lpCmdLine           AS ASCIIZ PTR, _
                      BYVAL iCmdShow      AS LONG) AS LONG
    ON ERROR RESUME NEXT
          DIALOG NEW 0, "Font Test", ,, 203, 89, %WS_CAPTION OR %WS_SYSMENU + %WS_MINIMIZEBOX, TO hDlg
          CONTROL ADD FRAME, hDlg, 99, "Caption",         3  ,10, 200,40, %BS_CENTER, 0
          CALL MAKEBOLD(99)
          DIM hDC AS LONG
          DIALOG SHOW MODAL hDlg CALL DlgProc
    END FUNCTION
    Timm



    [This message has been edited by Timm Motl (edited February 01, 2001).]
    mailto:[email protected]
    Tsunami Record Manager

    Comment


    • #3
      Too easy! you have no idea how long I spent searching POFFS and these archives for this
      That has solved my problem, many thanks!


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

      Comment


      • #4
        Wayne, be sure to examine the SMTP.BAS example shipped with PB/DLL... it shows this and related techniques for manipulating control colors, backgrounds, etc.


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

        Comment


        • #5
          Thanks Lance - I had actually checked the SMTP sample as it was referenced in POFFS, but while that demonstrated how to change _all_ of the labels to Yellow, I found it beyond me to modify it to just change 1 particular control, but the solution is just a couple posts above so I'm once again cooking with gas



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

          Comment

          Working...
          X