[Dev-C++] [C\C++][Windows GUI]Problems changing a Edit control's background color, with WM_CTLCOLOR
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
From: Frederico M. <the...@ho...> - 2009-05-14 09:50:50
|
Hello everyone. As I have already told you, on an earlier post, I am currently developing a InstallShield(R) 'Setup' app look-alike. However I have run into, what seems to be, a dead end. While displaying the "License Agreement" frame, the Edit control that displays the licensing text is created with code : /*************** *** Assume : *** static HWND phControls[10]; *** size_t editControl = 2; */ phControls[ editControl ] = CreateWindowEx( WS_EX_LEFT|WS_EX_RIGHTSCROLLBAR|WS_EX_CLIENTEDGE, "EDIT", NULL, (WS_BORDER|WS_CHILD|!WS_VISIBLE|ES_LEFT|ES_MULTILINE|ES_AUTOVSCROLL|WS_VSCROLL|ES_READONLY), 30, 100, 440, 120, hAncestor, (HMENU)0, hInstance, NULL ); /****************/ I do all the necessary checkings, and load the text, to the control, with code: /**************** *** For simplicity I remove auxiliar error checking, and I ask you to assume : *** const size_t maximumAllowedStringToBeLoaded = 4096; *** char buffer[ maximumAllowedStringToBeLoaded ]; *** # define scSoftwareEULA 0x000000003 */ *** STRINGTABLE { *** scSoftwareEULA, "EULA : ............\r\n" *** } // In GuiResources.RC. if ( LoadString( GetModuleHandle(NULL), scSoftwareEULA , buffer, maximumAllowedStringToBeLoaded-1 ) != 0 ) SendMessage( phControls[ iterator ], WM_SETTEXT, ( WPARAM )( 0 ),( LPARAM )( buffer ) ) /************/ After all the other controls in the second frame are created, I apply a pre-initialized HFONT to the controls, including this editcontrol. The result, is a formatted control, corresponding to the defined flags in the CreateWindow call. However the control displays a grayish background. In attempting to resolve the issue I tried coloring the control when it is required. Below is the logic applied. code: /** *** This snippet resides within the hwnd, which is the main window of the application. *** It's handle is passed to the editcontrol as hAncestor. *** Therefore this window is EditControl's parent. *** *** Please, when reading the following snippet, assume EditBox_handle returns the correct EditBox handle. */ case WM_CTLCOLORSTATIC : { static int color = 0; if ( (HWND)lParam != (HWND)EditBox_handle ) return DefWindowProc (hwnd, message, wParam, lParam); else { if ( EditBox_handle != NULL && (HWND)lParam == (HWND)EditBox_handle && color < 1 ) { HDC deviceContext = (HDC)wParam; if ( ( deviceContext ) == NULL ) { return DefWindowProc (hwnd, message, wParam, lParam); } SetBkMode( deviceContext, TRANSPARENT ); SetBkColor( deviceContext, RGB( 0 , 0 , 0 ) ); if ( color < 1 ) { ShowWindow( EditBox_handle, FALSE ); color++; ShowWindow( EditBox_handle, TRUE ); } SetBkMode( deviceContext, OPAQUE ); } } /************/ This code does change the edit control background color. However this does not occour when the window is created. The lines that are displayed by the control, upon its first creation, display a gray background. The background changes only, when scrolling happens. I have, also found, that if we "hold" the vertical bar, and try to push it bellow the scroll limit, the last lines display again the gray background. Obviously I have miss something, beacause other applications do not suffer this situation. Could anyone please advice me on how to resolve this issue? Thank you for having the time to read all this :) Frederico Marques _________________________________________________________________ Emoticons e Winks super diferentes para o Messenger. Baixe agora, é grátis! http://specials.br.msn.com/ilovemessenger/pacotes.aspx |