Reputation: 29377
I mean to color the description dialog that is just below title bar. I succeeded in changing font there but the background is done completely different.
As I read everywhere it is done by capturing WM_CTLCOLORSTATIC message, but no one has put a complete code where I should catch this message, this code is as I understand it, I've put it into dialog's callback procedure.
The problem is that the WM_CTLCOLORSTATIC never gets called.
#include <windows.h>
#include <iostream>
#include <shlobj.h> //for Shell API, dir dialog
#include <commctrl.h>
int CALLBACK BrowseCallBackProc( HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) {
switch(uMsg) {
case BFFM_INITIALIZED: {
HWND static_control = NULL;
char szClassName[_MAX_PATH];
for (HWND hChild = GetWindow(hwnd, GW_CHILD); hChild != NULL; hChild = GetNextWindow(hChild, GW_HWNDNEXT))
{
if ((GetWindowLong(hChild, GWL_STYLE) & WS_VISIBLE) == 0) continue;
GetClassName(hChild, szClassName, _countof(szClassName));
if (!strcmp("Static",szClassName)) {
static_control = hChild;
break;
}
}
HFONT hFont = CreateFont (13, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Fixedsys"));
SendMessage(static_control, WM_SETFONT, (WPARAM)hFont, TRUE);
break;
}
case WM_CTLCOLORSTATIC: {
std::cout << "WM_CTLCOLORSTATIC fired!" << std::endl;
break;
}
}
}
int main() {
using namespace std;
BROWSEINFOW bi;
LPITEMIDLIST pidl;
LPMALLOC pMalloc;
if (SUCCEEDED (::SHGetMalloc (&pMalloc))) {
::ZeroMemory (&bi,sizeof(bi));
bi.hwndOwner = NULL;
bi.lpszTitle = L"ok, now how to make my background... yellow for example ?";
bi.pszDisplayName = 0;
bi.pidlRoot = 0;
bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_VALIDATE | BIF_USENEWUI | BIF_UAHINT;
bi.lpfn = BrowseCallBackProc;
bi.lParam = (LPARAM)L"d:\\";
pidl = ::SHBrowseForFolderW(&bi);
}
system("pause");
}
Upvotes: 0
Views: 273
Reputation: 126412
The MSDN documentation mentions that the callback procedure you pass to ::SHBrowseForFolder
is only meant to receive events of four types:
BFFM_INITIALIZED
BFFM_IUNKNOWN
BFFM_SELCHANGED
BFFM_VALIDATEFAILE
These events are all unrelated with the WM_CTLCOLORSTATIC
message, which is sent to the window procedure of the parent window.
Upvotes: 0
Reputation: 28050
You can subclass the dialog window using the SetWindowSubclass function.
In the specified callback function you will receive WM_CTLCOLORSTATIC
messages.
Upvotes: 1