Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Modifying the background color of an IP address common control

Posted on 2004-10-26
4
Medium Priority
?
502 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
Comment
Question by:Kalvyn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 16

Expert Comment

by:nonubik
ID: 12419318
>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
ID: 12423501
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:
nonubik earned 750 total points
ID: 12423756
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
ID: 12579713
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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

597 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