我设法在此控件中绘制了一个矩形,但有两个问题。首先是在用鼠标移动选择文件夹对话框后显示白色矩形。我知道这里的问题是连接到正确的信息。我选择了在创建对话框窗口时触发的 WM_ERASEBKGND,但它没有任何效果,必须在之前未显示的控件部分返回屏幕时调用它,所以我必须将窗口拖到边缘,所以部分控件不可见并将其拖回,然后显示白色矩形。但是出现了第二个问题。它还涵盖了控件的文本。
所以这是我的尝试,有什么想法吗?
#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);
}
}
它的样子:
它当然应该是这样的: