Announcement

Collapse
No announcement yet.

Changing a control's color !

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

  • Gilmar de Paula Fiocca
    replied
    Richard,

    I was using GRAPHIC windows, but in some machines they are REALLY slow, the drawing of "natural" Windows dialogs are much faster. I think it is because Directx... Who knows...

    Sorry, I didn't mean to be rude, just thought you didn't know that in PBCC you could use dialogs !

    Thanks for helping.

    Leave a comment:


  • Richard Angell
    replied
    Richard, I'm using console compiler, but I needed an Dialog ! Yes you can use dialogs in PBCC !!! The problem is that you have to deal with Windows API !
    Yes, you can ... but I was trying to make sure that is what you were really trying to do. For that matter you can do a "dialog", depending on what is in it, with PB's GRAPHICS in a subclassed GW. Many examples since 8.0 was released years ago. and with 9.0 much easier.

    Leave a comment:


  • Gilmar de Paula Fiocca
    replied
    Thank you Michael, but using this way the control's background is set to "WHITE", using a created brush solved my problem.

    Leave a comment:


  • Michael Mattias
    replied
    Code:
    FUNCTION = GetStockObject(%WHITE_[COLOR="Red"][B]BRUSH[/B][/COLOR])

    Leave a comment:


  • jcfuller
    replied
    Here is another alternative.



    James

    Leave a comment:


  • Gilmar de Paula Fiocca
    replied
    Good morning,

    Richard, I'm using console compiler, but I needed an Dialog ! Yes you can use dialogs in PBCC !!! The problem is that you have to deal with Windows API !

    It worked ok, with some minors adaptations in Jerry's code, because I had the dialog created in a resource file, not by code.
    After all, the only thing I had to do is create the brush to use in the callback.

    Thanks for your help Jerry and Kev !

    Leave a comment:


  • Kev Peel
    replied
    FUNCTION = GetStockObject(%WHITE_PEN)
    This is wrong, you can only return a HBRUSH (brush handle) from the WM_CTLCOLORXX functions. If you need a fixed, non-system color, then create the brush with CreateSolidBrush() in somewhere like WM_INITDIALOG and save the handle in a STATIC variable, then you can return this handle in WM_CTLCOLORSTATIC. The brush can be deleted in WM_DESTROY or wherever you are done with it.

    If you need to use a system color, it's very simple: just use GetSysColorBrush().

    Leave a comment:


  • Jerry Fielden
    replied
    I don't know if this is what you are looking for, but here's an example generated by Jaxgui that should work in PBCC.


    Code:
    #CONSOLE OFF ' Delete if using older than PBCC4.03
     #COMPILE EXE 
     #DIM ALL 
    
     #INCLUDE "C:\PBCC40\WINAPI\WIN32API.INC"
    
     GLOBAL hInstance, hwnd AS LONG
    
    
    
    
    
     FUNCTION ProcessWindow (BYVAL hDlg AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam _ 
                      AS DWORD, BYVAL lParam AS LONG) AS LONG
    
       STATIC hStBrush1 AS LONG
       LOCAL wmID AS LONG, wmEvent AS LONG 
       LOCAL ps AS PAINTSTRUCT
       LOCAL BrushClr AS LONG        
       LOCAL hDC, hBrush, hPen AS DWORD  
       LOCAL StBgColor1 AS LONG, StFgColor1 AS LONG
       LOCAL Lt1 AS STRING
        STbgColor1 = &H0000FF     ' Selected background color for a Static control
        STfgColor1 = &H80FFFF     ' Selected foreground color for a Static control
    
      SELECT CASE wMSG
         CASE %WM_CREATE         'Create and initialize Controls 
    
         hSTbrush1  =  CreateSolidBrush(STbgColor1)' Create a logical brush with selected color for a Static/Label control
    
            Lt1=Lt1 + "Now is the time for all good"
    
             CreateWindowEx(0, "static", BYVAL STRPTR( LT1 ), _ 
                 %WS_CHILD OR %WS_VISIBLE, _
                80,  76,  290,  171, _   
                hdlg,  1001, hInstance, BYVAL %NULL)    
    
            SetWindowPos hDlg, %HWND_TOP, 0, 0, 0, 0, %SWP_NoSize OR %SWP_NoMove
    
         CASE %WM_CTLCOLORSTATIC 
            IF GetDlgCtrlId(lParam) =  1001 THEN      '  Check for Static controls ID number
               SetTextColor Wparam, STfgColor1       '  Set the foreground colors for a Static control
               SetBkColor Wparam, STbgColor1         '  Set the background colors for a Static control
               ProcessWindow = hStBrush1 : EXIT FUNCTION  '  Apply the colors for a Static control
            END IF 
         CASE %WM_DESTROY 
            DeleteObject hStBrush1                '  Frees all system resources associated with this brush
    
         CASE %WM_PAINT    ' dialog is to be redrawn
            BeginPaint hDlg, ps  ' get device context to draw in
               BrushClr = &H0000FF
               hPen   = CreatePen(0, 1, BrushClr) ' Want border? chg BrushClr here 
               hPen   = SelectObject(ps.hDC, hPen) ' select it into given dc 
               hBrush = CreateSolidBrush(BrushClr)  
               hBrush = SelectObject(ps.hDC, hBrush) 
               Rectangle ps.hDC, 0, 0,  451,  330
               DeleteObject SelectObject(hDC, hPen) 
               DeleteObject SelectObject(hDC, hBrush)
            EndPaint hDlg, ps 
    
         CASE %WM_CLOSE     ' Message from Clicking on system close Icon
            PostQuitMessage 0 
      END SELECT
      ProcessWindow = DefWindowProc(hdlg, wMsg, wParam, lParam)  
    END FUNCTION 
    
    
    FUNCTION WINMAIN (BYVAL hInstance     AS LONG, _ 
                      BYVAL hPrevInstance AS LONG, _          
                      BYVAL szCmdLine     AS ASCIIZ PTR, _    
                      BYVAL iCmdShow      AS LONG) AS LONG    
    
        LOCAL wMsg       AS tagMsg, hMenu AS LONG     
        LOCAL WindClass AS wndclassex  
        DIM szpgmname AS ASCIIZ * 20, STYLE AS LONG 
    
        'ShowWindow CONSHNDL, %SW_Hide ' Use for older PBCC
        szpgmname = "SDK Samples"
        windclass.cbSize        = SIZEOF(windclass)
        windclass.lpfnWndProc   = CODEPTR(ProcessWindow)  'point to callback
        windclass.hInstance     = hInstance  
        windclass.hIcon         = LoadIcon( hInstance, "MAINICON" ) 
        windclass.hCursor       = LoadCursor( %NULL, BYVAL %IDC_ARROW ) 
        windclass.hbrBackground = %COLOR_3DFACE + 1
        windclass.lpszClassName = VARPTR(szpgmname) 
         RegisterClassEX windclass 
              STYLE =   %WS_VISIBLE OR %WS_OVERLAPPEDWINDOW OR %WS_CLIPCHILDREN 
    
            CreateWindowEx(0, szpgmname, "JaxGUI Example", _
                          STYLE,  200,  114,  459,  355, _ 
                          %HWND_DESKTOP, hMenu, hInstance, BYVAL %NULL) 
    
         ShowWindow hWnd, iCmdShow     
         UpdateWindow hWnd             
         WHILE (GetMessage(wMsg, %NULL, 0, 0) <> %false ) 
            IF IsDialogMessage(hWnd, wMsg) = %FALSE THEN 'For TabKey,  Comment out if using WM_KEYDOWN
               TranslateMessage wMsg  
               DispatchMessage  wMsg  
            END IF                                       'For TabKey,  Comment out if using WM_KEYDOWN
         WEND                            
    
         WINMAIN = wMsg.wParam 
    END FUNCTION

    Leave a comment:


  • Richard Angell
    replied
    Which PBCC compiler version are you using? IOW Doesn't this post belong in the PBWin or Programming forum?

    Leave a comment:


  • Gilmar de Paula Fiocca
    started a topic Changing a control's color !

    Changing a control's color !

    Hi,

    Anyone could help me ?
    I created a dialog using ResEdit/RC. I've managed to change the text and font of the created static controls in it, ie. labels, but I'm having difficulties
    in changing the color of them.
    I know that I have to use the API functions "SetBkColor" and "SetTextColor", but I do not know how to use them.

    Code:
    LOCAL hFont AS LONG ' Handle for font
    LOCAL hControl AS LONG ' Handle for control
    LOCAL hWnd AS LONG ' Handle for window
    LOCAL hDC AS DWORD ' Handle for device context
    LOCAL szText AS ASCIIZ * 50
    
    .
    .
    .
    
    ' Changing font... Works fine !
    hFont = PBFormsMakeFont("Courier", 9, %FW_EXTRABOLD, %FALSE, %FALSE, %FALSE, %DEFAULT_CHARSET)    		
    SendMessage hControl, %WM_SETFONT, hFont, 0&
    
    ' Changing caption... Works fine !
    szText = "Test"
    SetWindowText(hControl, szText)
    
    ' What I'm trying... Didn't work completely right !...
    ' This is the code of my callback procedure
    SELECT CASE wMsg
        CASE %WM_CTLCOLORSTATIC
      	SELECT CASE GetDlgCtrlId(lParam)
      	    CASE %IDC_VISOR5
          		SetBkColor wParam, %RED
          		SetTextColor wParam, %WHITE
          		SetBkMode wParam, %OPAQUE
                                                       
                              ' The objective is to change the background in the hole control to RED ! Now I'm getting only the text to the colors I needed. Not the hole background !
                              ' Don't know which object to use ! Tried BLACK_PEN, BLACK_BRUSH, DC_BRUSH, DC_PEN, neither one worked as I expected.
          		FUNCTION = GetStockObject(%WHITE_PEN) 
          		EXIT FUNCTION
          	END SELECT
    
    .
    .
    .
    Anyone could point me in the right direction ?
    Thanks !
    Last edited by Gilmar de Paula Fiocca; 29 Sep 2008, 10:03 PM.
Working...
X