Skip to content
⌘ NSIS Forum Archive

Locked List plug-in background color

5 posts

kalverson#

Locked List plug-in background color

I am trying to set a background color of white for IDC_HEADING in the locked list plugin dll. I added two lines of code shown below, but it does not appear to be working. Anyone know how you can do this?

GlobalFree(pszParam);

g_hDialog = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_DIALOG), g_hWndParent, (DLGPROC)DlgProc);

HDC hdcStatic = (HDC)GetDlgItem(g_hDialog, IDC_HEADING);
SetBkColor(hdcStatic, RGB(255, 255, 255));
}
Anders#
GetDlgItem returns a HWND not a HDC and you cannot just cast to get what you want. SetBkColor only works in WM_PAINT and other places where you paint anyway so even if you get a HDC it will not work.

What you need to do is to find out what type of control IDC_HEADING is (listbox? listview?) and then lookup the messages that control supports on MSDN. Maybe there is a message you can send or a notify message to respond to. If not you might have to use custom draw/owner draw and if all else fails you would have to subclass the control and try to somehow handle the erase and paint messages.
kalverson#
Thanks for pointing that out. I was able to get the static control white after all. I put the code in the Dialog callback. Here is the segment that worked:

// Dialog procedure.
static LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)

...

case WM_CTLCOLORSTATIC:
{
if(GetDlgItem(hWndDlg, IDC_HEADING) == (HWND)lParam)
{
SetBkColor((HDC) wParam, RGB(255,255,255) );
return (int)CreateSolidBrush(RGB(255,255,255));
}
return 0;
}
Anders#
From MSDN, CreateSolidBrush:
When you no longer need the HBRUSH object, call the DeleteObject function to delete it.
You should not return CreateSolidBrush like that, it leaks a brush every time it paints! Normally you would create the brush once, return the handle when you need to and destroy it on WM_DESTORY but you are in luck, GetStockObject can give you a white brush you don't need to destroy.
kalverson#
Thanks for the tip. The GetStockObject api worked as well. Not only that, but our build specialist suggested I put the modified plugin in a subfolder and call it from there instead so we wouldn't have to do any renaming in the ant script. To my surprise, there is a way in Nullsoft to do that. Now we can have it both ways with conditional compiles depending on which one we want. Regular for default panels and white background for the JavaFX blend in.