views:

530

answers:

3

How do I change the border color of focused/unfocused CEdit, CListCntl, CButton in WinCE/Windows Mobile 5/6 with MFC or Win32 API?

A: 

I'm not sure you can without implementing custom draw.

MFC in Windows Mobile works almost exactly the same as the win32 version. So if you can find examples of what you want that works in win32 it will most likely work under windows mobile as well.

Shane Powell
I found examples on how to use Custom Draw message (NM_CUSTOMDRAW) to change the background color of CListCntl, but I haven't found one which changes the border color.
afriza
+1  A: 

You can achieve such an effect by deriving your own CEdit class and override WM_NCPAINT message, this allows you to paint the non-client area yourself and draw you own border when focus is changed:

void CMyEdit::OnNcPaint() 
{
    CWindowDC dc(this);
    CRect rect;
    GetWindowRect(&rect);
    dc.Draw3dRect(0, 0, rect.Width(), rect.Height(), RGB(0,0,255) , RGB(255,0,0) );
}
Gordon Freeman
AFAIK Non-Client Messages such as WM_NCPAINT are generally not available in Windows CE based OS.
afriza
A: 

There's this trick I found here to draw a borderless control and then draw the border from its parent. or make a static control slightly bigger than the control just to draw the border.

Is there any better Idea? such as making use of Window Clipping Region or something?

update:
Here is a discussion with an MSFT on the topic

afriza