win32 : display editbox with black color in text a

2019-09-15 03:14发布

问题:

I am writing simple UI application on windows mobile 5, i want to display a editbox to user with back color in whole edit box but i am not successful with any approach........ whenever i catch the window event for edit control and call setBkColor(), it will display only text area with given color not entire edit box.

I want the given color to be displayed to the user when the window presented to the user not when user enters the data in the edit box.

Please let me know the solution , again its native win32 application code not MFC

regds Suhail

回答1:

SetBkColor only sets the background colour for the text. To change the background of the entire control, you need to process the WM_CTLCOLOREDIT message and return a brush of your choice. You can do this in your WndProc like this: (assuming hEdit is the handle of your edit control)

case WM_CTLCOLOREDIT:
  if ((HWND)lParam == hEdit) {
    HDC hDC = (HDC)wParam;
    SetBkMode(hDC, TRANSPARENT);
    return (LRESULT)GetStockObject(BLACK_BRUSH); // or any other brush you want
  }
  break;

By setting the background mode to transparent, you don't need a separate SetBkColor call -- the text will be painted transparently over the background.