win32-改变Combox的编辑框和下拉列表的背景颜色和文本字体颜色
2021-01-03 15:29
标签:osi ext 背景 ase simple 接下来 ica inf cal 只需要调用WM_CTLCOLORLISTBOX和WM_CTLCOLOREDIT来分别处理编辑框和下拉列表。 Combox的创建: 这部分可以参考: How to Create a Simple Combo Box 接下来处理窗口处理过程: 最后的调试结果: win32-改变Combox的编辑框和下拉列表的背景颜色和文本字体颜色 标签:osi ext 背景 ase simple 接下来 ica inf cal 原文地址:https://www.cnblogs.com/strive-sun/p/13206712.htmlint xpos = 100; // Horizontal position of the window.
int ypos = 100; // Vertical position of the window.
int nwidth = 200; // Width of the window
int nheight = 200; // Height of the window
HWND hwndParent = hWnd; // Handle to the parent window
hWndComboBox = CreateWindow(WC_COMBOBOX, TEXT(""),
CBS_DROPDOWNLIST | WS_CHILD | WS_VISIBLE, // CBS_HASSTRINGS | WS_OVERLAPPED |
xpos, ypos, nwidth, nheight, hwndParent, NULL, hInstance,
NULL);
// load the combobox with item list.
// Send a CB_ADDSTRING message to load each item
TCHAR Planets[9][10] =
{
TEXT("Mercury"), TEXT("Venus"), TEXT("Terra"), TEXT("Mars"),
TEXT("Jupiter"), TEXT("Saturn"), TEXT("Uranus"), TEXT("Neptune"),
TEXT("Pluto??")
};
TCHAR A[16];
int k = 0;
memset(&A, 0, sizeof(A));
for (k = 0; k 8; k += 1)
{
wcscpy_s(A, sizeof(A) / sizeof(TCHAR), (TCHAR*)Planets[k]);
// Add string to combobox.
SendMessage(hWndComboBox, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)A);
}
// Send the CB_SETCURSEL message to display an initial item
// in the selection field
SendMessage(hWndComboBox, CB_SETCURSEL, (WPARAM)2, (LPARAM)0);
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CTLCOLORLISTBOX:
{
HDC dc = (HDC)wParam;
SetBkMode(dc, OPAQUE);
SetTextColor(dc, RGB(255, 255, 255));
SetBkColor(dc, 0x383838); //0x383838
HBRUSH comboBrush = CreateSolidBrush(0x383838); //global var
return (LRESULT)comboBrush;
}
case WM_CTLCOLOREDIT:
{
HDC dc = (HDC)wParam;
SetBkMode(dc, OPAQUE);
SetTextColor(dc, RGB(255, 255, 255));
SetBkColor(dc, 0x383838); //0x383838
HBRUSH comboBrush = CreateSolidBrush(0x383838);
return (LRESULT)comboBrush;
}
...
文章标题:win32-改变Combox的编辑框和下拉列表的背景颜色和文本字体颜色
文章链接:http://soscw.com/index.php/essay/39850.html