CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2000
    Posts
    26

    how to change the edit background color

    Hi
    I created a document based application use window programming
    I mean not VC++. On the document view i created a edit box
    , and try to chang the background color but I don't know How? I Any help and example

    Thanks

    robin

    email to : [email protected]

  2. #2
    Join Date
    Dec 2000
    Posts
    26

    how to use WM_CTLCOLOREDIT?

    Actually My code:

    RECT rect // this is the Edit box Rect
    LRESULT CALLBACK EditClassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    case WM_PAINT:
    HBRUSH hBrush;
    PAINTSTRUCT ps;
    hdc = BeginPaint( m_hWnd, &ps );
    hBrush = CreateSolidBrush(rgb);

    FillRect (hdc, &rect, hBrush);
    DeleteObject (hBrush);
    EndPaint( m_hWnd, &ps );

    .................
    .............
    }

    it changed the Edit background color but in different position, why,
    or how to fix this?

    robin luo bin

    [email protected]

  3. #3
    Join Date
    Aug 2002
    Location
    United States
    Posts
    729
    you dont need to handle this in WM_PAINT at all.


    process the WM_CTLCOLOREDIT message in your parent window's window procedure and it will handle the wm_paint stuff itself.

    the WPARAM is the HDC you'll be working with and the LPARAM is a HWND to whatever is processing this....

    for example....

    Code:
    case WM_CTLCOLOREDIT:
    	SetTextColor((HDC)wParam, ftext);
    	SetBkColor((HDC)wParam, tback);
    	return (LRESULT)CreateSolidBrush(tback);
    where ftext is a COLORREF structure holding the text color and tback is another one w/ith the background color..... *COLORREF ftext = RGB(255, 255, 255); * for example.

    hope this helps

  4. #4
    Join Date
    May 2002
    Location
    Somewhere over the rainbow
    Posts
    423
    Code:
    // globals
    HBRUSH hbrushEditBox = CreateSolidBrush(RGB(34,94,144)); // making a brush color (API)
    //----------------------------------------------------------
    
    case WM_CTLCOLOREDIT: // Same as Static, only for EditBoxes
            {
                HDC hdcEdit = (HDC)wParam; //Get handles
                SetTextColor(hdcEdit, RGB(255, 255, 255)); // Text color
                SetBkMode(hdcEdit, TRANSPARENT); // EditBox Backround Mode (note: OPAQUE can be used)
                SetBkColor(hdcEdit,(LONG)hbrushEditBox); // Backround color for EditBox
                return (LONG)hbrushEditBox; // Paint it
            }
            break;
    Bengi

  5. #5
    Join Date
    Dec 2000
    Posts
    26

    Tnanks, one more question

    How to create bitmap button?

  6. #6
    Join Date
    Oct 2002
    Location
    India
    Posts
    138
    hi,

    u can use CBitmapButton in MFC, which show all 4 bitmap in Button

    regards
    thomas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured