我的意思是为标题栏下方的描述对话框着色。我成功地在那里改变了字体,但背景完全不同。
正如我在各处阅读的那样,它是通过捕获 WM_CTLCOLORSTATIC 消息来完成的,但是没有人在我应该捕获此消息的位置放置完整的代码,此代码是我所理解的,我已将其放入对话框的回调过程中。
问题是 WM_CTLCOLORSTATIC 永远不会被调用。
#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");
}