I've painted the background color of an edit box with WM_CTLCOLOREDIT and now when inputting/adding text , it is overlapping. How avoid this?
case WM_CTLCOLOREDIT:
{
if(IDC_TEXT1 == GetDlgCtrlID((HWND)lParam))
{
textArea1Brush = CreateSolidBrush(RGB(198, 226, 255));
SetBkMode((HDC)wParam, TRANSPARENT);
return(LONG)textArea1Brush;
}
break;
}
Related
Its like the title suggests, i want to draw a "1" texture at mouse coords using a keyboard key press.
I am using switch statements for input:
switch (e.type)
{
case SDL_QUIT:
{
quit = true;
break;
}
case SDL_MOUSEBUTTONDOWN:
{
switch (e.button.button)
{
case SDL_BUTTON_LEFT:
{
SDL_Rect rect = {e.motion.x - 10, e.motion.y - 10, 20, 20};
SDL_RenderCopy(gRenderer, gT[0], NULL, &rect);
printf("nod\n");
break;
}
}
break;
}
case SDL_KEYDOWN:
{
switch (e.key.keysym.sym)
{
case SDLK_c:
{
SDL_SetRenderDrawColor(gRenderer, 255, 255, 255, 255);
SDL_RenderClear(gRenderer);
printf("tot ecranul\n");
break;
}
case SDLK_1:
{
SDL_Rect rect = {e.motion.x - 8, e.motion.y - 8, 16, 16};
SDL_RenderCopy(gRenderer, gT[3], NULL, &rect);
printf("1\n");
break;
}
}
break;
}
}
I tried some random things, and no success so far.
gT[3] is the "1" texture.
e.motion only makes sense when e is a mouse event.
Call SDL_GetMouseState to get the current mouse position.
I am currently subclassing a ListView control to support custom color schemes - especially Dark Mode themes.
So first, I changed the ListView and associated Header with:
SetWindowTheme(hwndListView, isDarkModeEnabled() ? L"Explorer" : nullptr, nullptr);
SetWindowTheme(hwndListViewHeader, isDarkModeEnabled() ? L"ItemsView" : nullptr, nullptr);
I can set the ListView background color to any custom color I choose, while answering to the WM_THEMECHANGED message and doing a ListView_SetBkColor() macro.
Unfortunately, it seems I can't do it with the associated Header Control, I must resort to Custom Draw. So I did. I subclassed the ListView, because this is the window handle that will receive WM_NOTIFY messages from the Header control, and when responding to NM_CUSTOMDRAW message, my code looks like this:
case WM_NOTIFY:
{
LPNMHDR nmhdr = reinterpret_cast<LPNMHDR>(lParam);
if (nmhdr->code == NM_CUSTOMDRAW)
{
LPNMCUSTOMDRAW lpcd = reinterpret_cast<LPNMCUSTOMDRAW>(lParam);
switch (lpcd->dwDrawStage)
{
case CDDS_PREPAINT:
{
if (!PluginDarkMode::isEnabled())
return CDRF_DODEFAULT;
FillRect(lpcd->hdc, &lpcd->rc, getDarkerBackgroundBrush());
return CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYPOSTPAINT;
}
case CDDS_ITEMPREPAINT:
{
return DrawListViewHeaderItem(lParam); // This function draws the item entirely and then returns CDRF_SKIPDEFAULT.
}
case CDDS_POSTPAINT:
// Calculates the undrawn border outside columns
HWND hHeader = lpcd->hdr.hwndFrom;
int count = static_cast<int>(Header_GetItemCount(hHeader));
int colsWidth = 0;
RECT wRc = {};
for (int i = 0; i < count; i++)
{
Header_GetItemRect(hHeader, i, &wRc);
colsWidth += wRc.right - wRc.left;
}
RECT clientRect;
GetClientRect(hHeader, &clientRect);
if (clientRect.right > (colsWidth + 1))
{
clientRect.left = colsWidth + 1;
HDC hdc = GetDC(hHeader);
FillRect(hdc, &clientRect, getDarkerBackgroundBrush());
ReleaseDC(hHeader, hdc);
}
return CDRF_SKIPDEFAULT;
}
}
break;
}
Now, my problem is that, although this seems fine, my control will always end up with a black rectangle outside the column's area (the empty space where no column exists). And this effect persists up until I move the mouse outside the header control area.
For example:
And when the mouse leaves the area:
Any ideas of how to solve this?
So I'm using the code written here to redraw a static text but I've noticed that everytime I do so the system take it to the back(behind a static picture) and I can't see it. Is there a way to put it back in position or to prevent this action?
The code I use to redraw it:
vHWND = Control's HWND
wHWND = Window's HWND
RECT rect;
GetClientRect(vHWND, &rect);
InvalidateRect(vHWND, &rect, TRUE);
MapWindowPoints(vHWND, wHWND, (POINT *)&rect, 2);
RedrawWindow(wHWND, &rect, NULL, RDW_ERASE | RDW_INVALIDATE);
The code to have transparent bg:
case WM_CTLCOLORSTATIC: //Draw views transparent background
{
SetBkMode((HDC)wParam, TRANSPARENT); //BG Transp
return (LRESULT)GetStockObject(HOLLOW_BRUSH);
break;
}
Nevermind, I solved it using SetWindowPos.
Here is a picture of my program:
As you can see, the icons aren't transparent, simply white. This is problematic, because I've coded the list-view to alternate colors and the white looks very ugly on grey.
Right now, I'm using a bitmap with a pink background for the icons, and using the pink color as a mask. Here's the code for my HIMAGELIST:
hImageList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, ICON_COUNT, 0);
if (hImageList != NULL)
{
HBITMAP hBitmap = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_ICONS));
if (hBitmap != NULL)
{
ImageList_AddMasked(hImageList, hBitmap, RGB(0xFF, 0, 0xFF)); // pink mask
DeleteObject(hBitmap);
}
ImageList_SetBkColor(hImageList, CLR_NONE);
}
ListView_SetImageList(hWnd, hImageList, LVSIL_SMALL);
Here is the code for the list-view's Custom Draw (the alternating colors)
LRESULT WhiteFlagUI::PaintListView(__in HWND hwndListView, __in LPARAM lParam)
{
LPNMLVCUSTOMDRAW lpListDraw = reinterpret_cast<LPNMLVCUSTOMDRAW>(lParam);
switch (lpListDraw->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
return (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYSUBITEMDRAW);
break;
case (CDDS_PREPAINT | CDDS_ITEM):
{
RECT rect;
if (ListView_GetSubItemRect(hwndListView, lpListDraw->nmcd.dwItemSpec, lpListDraw->iSubItem, LVIR_BOUNDS, &rect))
{
COLORREF color;
// determine color
if (lpListDraw->nmcd.uItemState & CDIS_SELECTED)
color = RGB(157, 173, 215);
else if (lpListDraw->nmcd.dwItemSpec % 2)
color = RGB(240, 240, 240);
else
color = RGB(255, 255, 255);
// paint
HBRUSH hBrush = CreateSolidBrush(color);
if (hBrush != NULL)
{
FillRect(lpListDraw->nmcd.hdc, &rect, hBrush);
DeleteObject(hBrush);
}
// return color info
lpListDraw->clrTextBk = color;
return CDRF_NEWFONT;
}
}
break;
}
return CDRF_DODEFAULT;
}
Quite frankly, I'm completely lost as to how to approach this. Does anyone have any ideas?
I found a bit of a hack around this problem. If you set the background image to a blank white bitmap using ListView_SetBkImage it will force the icons to draw transparently. Unfortunately, doing this causes NM_CUSTOMDRAW to ignore the background color set with CDRF_NEWFONT. To get around it, call FillRect to fill background of the item in CDDS_ITEMPREPAINT and return CDRF_DODEFAULT or CDRF_NEWFONT if you are changing the foreground color as well.
I was faced with this problem as well.
I've solved it by adding SetBkColor(RGB(...)) where RGB(...) alternates from foreground color to background one in the custom draw procedure. I use 16x16 4b BMP with white background. Instead of using FillRect(), I set clrTextBk too. The last works for texts.
As I see from my experiments with CListCtrl, function SetBkColor() sets background color for icons only and does not for text (I found nothing about this in docs).
All this works only for non-empty items. To draw empty rows with this style, I override OnEraseBkgnd() notification function. For fully empty list, simple rectangles are drawn.
I hope this will help
Olexiy
how to change highlight color in list control in mfc.
i havn't found any api in clistctrl.
i have override NM_CUSTOMDRAW as descripbed in msdn
but when i clicked on any item on list it showing half blue color and half black color
why blue is coming ?
You need to override NM_CUSTOMDRAW handler. Check this sample.
I managed to change the color of the selected item based on Kirill V. Lyadvinsky's answer.
My dialog class contains a CTreeCtrl member that uses the resource ID IDC_TEST_DEF_TREE.
The method OnNMCustomdraw sets the color of the selected item. The message handler is registered in the message map like this:
ON_NOTIFY(NM_CUSTOMDRAW, IDC_TEST_DEF_TREE, OnNMCustomdraw)
The method's implementation:
void CSelectTestDefinitionDlg::OnNMCustomdraw(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMLVCUSTOMDRAW lpLVCustomDraw = reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR);
switch (lpLVCustomDraw->nmcd.dwDrawStage)
{
case CDDS_ITEMPREPAINT:
case CDDS_SUBITEM:
if (lpLVCustomDraw->nmcd.uItemState & CDIS_SELECTED)
{
// Your color definitions here:
lpLVCustomDraw->clrText = RGB(255, 255, 255);
lpLVCustomDraw->clrTextBk = RGB(0, 70, 60);
}
break;
default:
break;
}
*pResult = 0;
*pResult |= CDRF_NOTIFYPOSTPAINT;
*pResult |= CDRF_NOTIFYITEMDRAW;
*pResult |= CDRF_NOTIFYSUBITEMDRAW;
}