Edit-Feld-Eintrag hervorheben oder Hintergrundfarbe ändern
-
Hallo,
ich habe in einer Dialoganwendung ein zwei Edit-Felder. Zwischen denen springe ich immer hin und her für die eingabe eines Zahlenwertes. Wenn man zwischen den Fenstern mit der Tab Taste wechselt, ist am Anfang der Text im Edit Feld blau hervorgehoben. Sobald man aber eine Eingabe macht, verschindet diese Hervorhebung. Ich würde die gerne beibehalten. Hab das schon mit SetSel versucht, hat aber nicht geklappt.
Falls das nicht so einfach ist, würde ich gerne die Hintergrundfarbe des EDIT-Feldes verändern, solange das Feld den Eingabe-Focus hat.
Kann mir da jemand mit Rat zur Seite stehen. Was ich bisher habe sind lediglich die beiden Edit-Felder. Jedes davon hat eine int Variable für die Wertzuweisung bekommen, mehr ist noch nicht da.
-
MSDN OnCtlColor
-
Aber wie benutze ich das? hab jetzt schon mit dem Assistenten eine Funktion erstellt, die aufgerufen wird, wenn diese Nachricht kommt. Aber ich weiss nicht weiter. Bin leider nur Anfänger in c++;
-
versuch das mal, vielleicht funktionierts ja
HBRUSH CDeinDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); //------------------------------------------------------------------- switch(pWnd->GetDlgCtrlID()) { case IDC_EDIT1: pDC->SetBkColor(RGB(0,0,255)); break; } //------------------------------------------------------------------- return hbr; }
-
Danke, dass sieht doch schon recht gut aus.
weiss jetzt zufällig noch jemand, wie der RGB Wert der vom System vorgegebenen blauen Farbe ist, der gesetzt wird, wenn man zwischen einzelnen Edit-Feldern mit der TAB Taste springt
-
Such mal nach GetSysColor
MSDN:
GetSysColor
The GetSysColor function retrieves the current color of the specified display element. Display elements are the parts of a window and the display that appear on the system display screen.DWORD GetSysColor(
int nIndex // display element
);
Parameters
nIndex
[in] Specifies the display element whose color is to be retrieved. This parameter can be one of the following values. Value Meaning
COLOR_3DDKSHADOW Dark shadow for three-dimensional display elements.
COLOR_3DFACE, COLOR_BTNFACE Face color for three-dimensional display elements and for dialog box backgrounds.
COLOR_3DHILIGHT, COLOR_3DHIGHLIGHT, COLOR_BTNHILIGHT, COLOR_BTNHIGHLIGHT Highlight color for three-dimensional display elements (for edges facing the light source.)
COLOR_3DLIGHT Light color for three-dimensional display elements (for edges facing the light source.)
COLOR_3DSHADOW, COLOR_BTNSHADOW Shadow color for three-dimensional display elements (for edges facing away from the light source).
COLOR_ACTIVEBORDER Active window border.
COLOR_ACTIVECAPTION Active window title bar.
Windows 98/Me, Windows 2000 or later: Specifies the left side color in the color gradient of an active window's title bar if the gradient effect is enabled.COLOR_APPWORKSPACE Background color of multiple document interface (MDI) applications.
COLOR_BACKGROUND, COLOR_DESKTOP Desktop.
COLOR_BTNTEXT Text on push buttons.
COLOR_CAPTIONTEXT Text in caption, size box, and scroll bar arrow box.
COLOR_GRADIENTACTIVECAPTION Windows 98/Me, Windows 2000 or later: Right side color in the color gradient of an active window's title bar. COLOR_ACTIVECAPTION specifies the left side color. Use SPI_GETGRADIENTCAPTIONS with the SystemParametersInfo function to determine whether the gradient effect is enabled.
COLOR_GRADIENTINACTIVECAPTION Windows 98/Me, Windows 2000 or later: Right side color in the color gradient of an inactive window's title bar. COLOR_INACTIVECAPTION specifies the left side color.
COLOR_GRAYTEXT Grayed (disabled) text. This color is set to 0 if the current display driver does not support a solid gray color.
COLOR_HIGHLIGHT Item(s) selected in a control.
COLOR_HIGHLIGHTTEXT Text of item(s) selected in a control.
COLOR_HOTLIGHT Windows 98/Me, Windows 2000 or later: Color for a hot-tracked item. Single clicking a hot-tracked item executes the item.
COLOR_INACTIVEBORDER Inactive window border.
COLOR_INACTIVECAPTION Inactive window caption.
Windows 98/Me, Windows 2000 or later: Specifies the left side color in the color gradient of an inactive window's title bar if the gradient effect is enabled.COLOR_INACTIVECAPTIONTEXT Color of text in an inactive caption.
COLOR_INFOBK Background color for tooltip controls.
COLOR_INFOTEXT Text color for tooltip controls.
COLOR_MENU Menu background.
COLOR_MENUHILIGHT Whistler: The color used to highlight menu items when the menu appears as a flat menu (see SystemParametersInfo). The highlighted menu item is outlined with COLOR_HIGHLIGHT.
COLOR_MENUBAR Whistler: The background color for the menu bar when menus appear as flat menus (see SystemParametersInfo). However, COLOR_MENU continues to specify the background color of the menu popup.
COLOR_MENUTEXT Text in menus.
COLOR_SCROLLBAR Scroll bar gray area.
COLOR_WINDOW Window background.
COLOR_WINDOWFRAME Window frame.
COLOR_WINDOWTEXT Text in windows.Return Values
The function returns the red, green, blue (RGB) color value of the given element.If the nIndex parameter is out of range, the return value is zero. Because zero is also a valid RGB value, you cannot use GetSysColor to determine whether a system color is supported by the current platform. Instead, use the GetSysColorBrush function, which returns NULL if the color is not supported.
Remarks
System colors for monochrome displays are usually interpreted as shades of gray.To paint with a system color brush, an application should use GetSysColorBrush(nIndex) instead of CreateSolidBrush(GetSysColor(nIndex)), because GetSysColorBrush returns a cached brush (instead of allocating a new one).
For an example, see Changing the Colors of Window Elements.
Requirements
Windows NT/2000 or later: Requires Windows NT 3.1 or later.
Windows 95/98/Me: Requires Windows 95 or later.
Header: Declared in Winuser.h; include Windows.h.
Library: Use User32.lib.See Also
System Information Overview, System Information Functions, CreateSolidBrush, GetSysColorBrush, SetSysColors, SystemParametersInfo
-
Die Funktion OnCtlColor übergibt doch einen Pointer CDC pDC bei jedem aufruf.
Kann ich mir nicht irgendwie einen solchen Pointer von meinen beiden Edit-Feldern ständig einrichten?
Dann könnte ich auf die Funktionen SetBkColor einfach zugreifen wenn ich sie brauche