I managed to draw a rectangle in this control but there are two problems. First is that the white rectangle is shown after moving the select folder dialog around with a mouse. I know that the problem here is to hook up to the right message. I’ve chosen WM_ERASEBKGND that is fired when dialog window is created but then it has no effect, it must be called when portion of the control not shown before is back on screen, so I must drag the window to the edge so part of the control is not visible and drag it back, then the white rectangle is shown. But there second problem emerges. It also covers text of the control.
So here’s my try, any ideas ?
#include <windows.h>
#include <shlobj.h>
WNDPROC origStaticProc;
LRESULT CALLBACK myStaticProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch (uMsg) {
case WM_ERASEBKGND: {
HDC dc = GetDC(hWnd);
RECT clientRect;
GetClientRect(hWnd,&clientRect);
FillRect(dc, &clientRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
ReleaseDC(hWnd, dc);
break;
}
}
return CallWindowProc(origStaticProc, hWnd, uMsg, wParam, lParam );
}
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);
origStaticProc = ( WNDPROC ) SetWindowLongW( static_control, GWL_WNDPROC,( LONG ) myStaticProc );
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"I should be visible on a white background. Now you must drag me to edge of the screen and back.";
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);
}
}
how it looks like:

how it of course should be:

Got it. The problem is that I didn’t know that the callback function used for SHBrowseForFolder is different than the callback for window itself. It came out I must do another function to subclass the dialog.
It’s UGLY and unsafe code but it compiles and illustrates the principle.