Help - Search - Members - Calendar
Full Version: Processing WM_CTLCOLORSTATIC -> Dialog Window slowdown
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
mixcherry
I'm wondering, how do developers implement their 'pick-color' boxes - i mean static rectangles that are filled with chosen color (like in Default UI Preferenes or Playlist switcher Preferences). I'm trying to do this using WM_CTLCOLORSTATIC:

CODE
case WM_CTLCOLORSTATIC:
{
console::info("WM_CTLCOLORSTATIC");
int nCntrlID = GetDlgCtrlID((HWND) lparam);
HDC hdc = (HDC) wparam;
SetBkMode(hdc, TRANSPARENT);
switch (nCntrlID)
{
case IDC_COLOR_TEXT:
return (LRESULT) hbrText;
case IDC_COLOR_SELECTION_TEXT:
return (LRESULT) hbrSelectionText;
case IDC_COLOR_BACKGROUND:
return (LRESULT) hbrBackground;
case IDC_COLOR_SELECTION_BACKGROUND:
return (LRESULT) hbrSelectionBackground;
}
}
return NULL; //don't change colour of any other static control



Where hbrText, hbrSelectionText, etc. are my solid-color-brushes (they are created elsewhere), and IDC_COLOR_TEXT, IDC_COLOR_SELECTION_TEXT, etd. are IDs of my static rectangles (code from my *.rc: "CONTROL "",IDC_COLOR_TEXT,"Static",SS_LEFTNOWORDWRAP | SS_NOTIFY | WS_GROUP,84,156,64,14,WS_EX_STATICEDGE").

Here is the problem: everything is painted OK, but the Dialog is created slow and its responsiveness is *terribly* slow (but only when I'm using CTLCOLORSTATIC) -> just look here (go to plugin's preferences and try to select some text in 'Available fields'). I also noticed that WM_CTLCOLORSTATIC is processed way more times than the number of statics I have on my dialog. Is there any other way to color those statics?
foosion
The available fields control is a read-only edit box which also sends WM_CTLCOLORSTATIC notifications when it is redrawn. To improve performance you could:
  • Remove the SetBkMode() call, I'm quite sure it is unnecessary and in the current implementation it affects all static or read-only edit control on your dialog.
  • Cache the window handles of the relevant static controls and compare window handles instead of retrieving the control ID. This will probably have only a minor effect, if it is noticable at all.
  • Get rid of the biggest performance killer in your WM_CTLCOLORSTATIC handler: the console output.

I also noticed that the Apply button gets enabled when I click one of the color chooser but then click cancel.
mixcherry
QUOTE
Get rid of the biggest performance killer in your WM_CTLCOLORSTATIC handler: the console output.

Thanks, that was the point.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.