Solved

Modifying the background color of an IP address common control

Posted on 2004-10-26
472 Views
Last Modified: 2013-12-03
The following code segment changes the background color of an edit control

  case WM_CTLCOLOREDIT:
    {
      HDC hdc = (HDC)wParam;
      SetTextColor(hdc, RGB(0,0,0));
      SetBkColor(hdc, RGB(196,196,169));
    }
    return (int)GetSysColorBrush(0);

I cannot figure out how to change the background color of an IP Address control.  I tried to disable the window to get it to grey out in a dialog box, but it looks the same as when enabled.  Would I have to subclass the control?  
0
Question by:Kalvyn
    4 Comments
     
    LVL 16

    Expert Comment

    by:nonubik
    >Would I have to subclass the control?
    Not necessarly. You can handle the control's parent WM_CTLCOLOR message. Check whether lParam is the handle to your IP Address control and then change the color.
    0
     

    Author Comment

    by:Kalvyn
    nonubik,  I tried

      case WM_CTLCOLOR:
        {
          HDC hdc = (HDC)wParam;
          SetTextColor(hdc, RGB(0,0,0));
          SetBkColor(hdc, RGB(196,196,169));
        }
        return (int)GetSysColorBrush(3);

    which should change the background color of all controls, but a breakpoint at this point is never triggered.
    0
     
    LVL 16

    Accepted Solution

    by:
    I found out more:
    An IP Address control (SysIPAddress32 class) has 4 edit controls as children. Try subclassing all of them and change the background from there.
    0
     

    Author Comment

    by:Kalvyn
    Thanks for your input nonubik,  I ended up using the following procedure to subclass the address control

    static long WINAPI IPClass1 (HWND hWnd, UINT message, UINT wParam,LONG lParam)
    {
      switch (message)
      {
      case WM_ERASEBKGND:
        GetClientRect (hWnd,&rect);
        SelectObject((HDC)wParam,GetSysColorBrush(3));
        Rectangle((HDC)wParam,rect.left,rect.top,rect.right,rect.bottom);
        return 1;
      case WM_PAINT:
        GetClientRect (hWnd,&rect) ;
        BeginPaint(hWnd,&ps);
        app.DrawBitmap(ps.hdc,app.bmApp,0,0);
        EndPaint(hWnd,&ps);            
        return 0;
      case WM_CTLCOLOREDIT:
        {
          HDC hdc = (HDC)wParam;
          SetTextColor(hdc, RGB(0,0,0));
          SetBkColor(hdc, RGB(255,255,196));
        }
        return (int)app.hBrush;
      }
      return CallWindowProc (lpIPClass1,hWnd,message,wParam,lParam) ;
    }
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: Foundations of Front-End Development

    Jump-start a lucrative career in front-end web development, with zero previous coding experience required. This course covers the basic programming concepts and languages required for creating engaging websites from scratch.

    This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
    Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now