• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 507
  • Last Modified:

Modifying the background color of an IP address common control

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
Kalvyn
Asked:
Kalvyn
  • 2
  • 2
1 Solution
 
nonubikCommented:
>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
 
KalvynAuthor Commented:
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
 
nonubikCommented:
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
 
KalvynAuthor Commented:
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

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now