Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9251751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:46:46+00:00 2026-06-18T10:46:46+00:00

I managed to draw a rectangle in this control but there are two problems.

  • 0

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 looks like

how it of course should be:

how it of course should be

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:46:47+00:00Added an answer on June 18, 2026 at 10:46 am

    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.

    #include <windows.h>
    #include <shlobj.h>
    
    WNDPROC origBffProc;
    LRESULT CALLBACK bffProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
      static HBRUSH hBrush = (HBRUSH)GetStockObject(HOLLOW_BRUSH);
      switch (uMsg) {
        case WM_CTLCOLORSTATIC: {
          HDC hdcStatic = (HDC) wParam;
          SetTextColor(hdcStatic, RGB(255,0,0));
          SetBkColor(hdcStatic, RGB(255,255,0));
          return (INT_PTR)hBrush;
        }
      }
      return CallWindowProc(origBffProc, 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"));
          PostMessage(static_control, WM_SETFONT, (WPARAM)hFont, TRUE);
          origBffProc = ( WNDPROC ) SetWindowLongW( hwnd, GWL_WNDPROC,( LONG ) bffProc );
          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"You are about to erase a directory, be careful! (and don't blame me)";
        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);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've managed to draw numbers inside custom colored circle annotations (based on this ).
I have finally managed to drop working with VFW after several problems I have
I want to draw a rectangle with two strings in it. I want the
I managed to apply this excellent example to my needs: http://code.google.com/p/galleriffic/issues/attachmentText?id=76&aid=-3045121742886940548&name=example-2.html&token=4nlvmgAfVpc5whcXC9UEqHZaSz0%3A1339257750721 With a small
I managed to request the publish_actions permission, but since it is revocable from the
I managed to found out how to delete field but I have a problem
I have a class that draw some very simple graphics like lines, circles and
I have, after some help ( MSChart - Forcing a line chart to draw
I don't know if this is the correct website, but you guys have been
I am trying to draw a cube that uses 6 different images for textures,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.