Set background color on Editfield

hi i am creating a program...

look att the code:
program GUI;

uses Windows, Messages;

{$R *.RES}

var wClass: TWndClass;
    Msg: TMsg;
    Handle, hEdit: hwnd;

function WndProc(hWnd, Msg, wParam, lParam: Integer): integer; stdcall;
begin
 if Msg = WM_DESTROY then PostQuitMessage(0);
 if Msg = WM_CTLCOLOREDIT then begin
   if lParam = hEdit then begin
     SetBkColor(wParam, $FFFFFFFF);
     Result := GetSysColorBrush(COLOR_WINDOW);
     Exit;
   end;
 end;
 Result := DefWindowProc(hWnd, Msg, wParam, lParam);
end;

begin
 wClass.lpszClassName:= 'CN';
 wClass.lpfnWndProc := @WndProc;
 wClass.hInstance := hInstance;
 wClass.hbrBackground := COLOR_BTNFACE + 1;
 wClass.hIcon := LoadIcon(hInstance, 'MAINICON');
 wClass.hCursor := LoadCursor(0, IDC_ARROW);
 wClass.cbClsExtra := 0;
 wClass.cbWndExtra := 0;
 wClass.lpszMenuName := nil;
 RegisterClass(wClass);

 Handle := CreateWindow(wClass.lpszClassName, 'GUI', WS_OVERLAPPED or WS_MINIMIZEBOX or WS_VISIBLE or WS_SYSMENU, 250, 150, 469, 371, 0, 0, hInstance, nil);
 hEdit := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', '', WS_VISIBLE or WS_CHILD or WS_HSCROLL or WS_VSCROLL or ES_MULTILINE or ES_WANTRETURN or ES_READONLY, 19, 19, 190, 100, Handle, 0, hInstance, nil);

 UpdateWindow(Handle);
 
 while GetMessage(Msg, 0, 0, 0) do begin
   TranslateMessage(Msg);
   DispatchMessage(Msg);
 end;

end.

as you can se in the 'hEdit := CreateWindowEx(...)', there is a parameter 'ES_READONLY'. if i remove that param the editfield gets coloured (and that's what i want). what should i add in the code so the editfield gets coloured even if it's set to ReadOnly?
another problem i got is when the ES_READONLY is removed it's only one line in the field that gets coloured and i want to colour the whole editfield. when i press Enter-key, next line gets coloured.
LVL 1
icos3Asked:
Who is Participating?
 
Slick812Commented:
hello  icos3, I do not think the the system will allow changing the edit colors in the ReadOnly mode, that mode is suppose to sinify to the user that it is read only and the color are suppose to be a button face background color to indicate this. . . In your WM_CTLCOLOREDIT message handling, why do you set the background brush to the COLOR_WINDOW and set the text background to white SetBkColor(wParam, $FFFFFFFF); ? ?
(I think white is more correctly done as $FFFFFF ), the background brush is why to do not get the whole edit field to get colored.

I beleive you need to have a background brush, you might try the folowwing code -

program GUI;

uses Windows, Messages;

{$R *.RES}

var wClass: TWndClass;
    Msg: TMsg;
    Handle, hEdit, hBrush: hwnd; // add brush variable

function WndProc(hWnd, Msg, wParam, lParam: Integer): integer; stdcall;
begin
 if Msg = WM_DESTROY then PostQuitMessage(0);
 if Msg = WM_CTLCOLOREDIT then begin
   if lParam = hEdit then begin
     SetTextColor(wParam, $C03367);
     SetBkColor(wParam,$33ADEE);
     Result := hBrush;
     Exit;
   end;
 end;
 Result := DefWindowProc(hWnd, Msg, wParam, lParam);
end;

begin
 wClass.lpszClassName:= 'CN';
 wClass.lpfnWndProc := @WndProc;
 wClass.hInstance := hInstance;
 wClass.hbrBackground := COLOR_BTNFACE + 1;
 wClass.hIcon := LoadIcon(hInstance, 'MAINICON');
 wClass.hCursor := LoadCursor(0, IDC_ARROW);
 wClass.cbClsExtra := 0;
 wClass.cbWndExtra := 0;
 wClass.lpszMenuName := nil;
 RegisterClass(wClass);

 Handle := CreateWindow(wClass.lpszClassName, 'GUI', WS_OVERLAPPED or WS_VISIBLE, 250, 150, 469, 371, 0, 0, hInstance, nil);
 hEdit := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', '', WS_VISIBLE or WS_CHILD or WS_HSCROLL or WS_VSCROLL or ES_MULTILINE or ES_WANTRETURN, 19, 19, 190, 100, Handle, 0, hInstance, nil);

// you do not need the UpdateWindow here
hBrush := CreateSolidBrush($33ADEE); // create a brush
 while GetMessage(Msg, 0, 0, 0) do begin
   TranslateMessage(Msg);
   DispatchMessage(Msg);
 end;

DeleteObject(hBrush); // be sure to delete the brush
end.

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

if you want some more info about API GUI programming in Delphi you might look at the web site here -
http://www.angelfire.com/hi5/delphizeus/index.html

ask questions if you need more information
0
 
Slick812Commented:
if you are really intent on doing the the Read Only edit coloring, I would guess you will need to subclass the Edit and process it's WM_PAINT message and draw all of the background and text any way you want
0
 
icos3Author Commented:
Thanks! :D how can i subclass the Edit?
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Slick812Commented:
??
Looking at your code and questions, I do not beleive you have enough experience with the API to get any understanding from the subclass methods, you may consider taking API programming a step at a time, you may can use the web site "DelphiZeus" which I gave a link to above to read and experiment with API programming, API methods are not so easy. . . . There is information about SubClassing at the DelphiZeus site, and also info about using the WM_PAINT message handling
0
 
icos3Author Commented:
ok i'll take a look at the link :)
0
 
Eddie ShipmanAll-around developerCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.