Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. [Win32]Set Dialog Bitmap Background

[Win32]Set Dialog Bitmap Background

Scheduled Pinned Locked Moved C / C++ / MFC
questiongraphics
4 Posts 4 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 2965471
    wrote on last edited by
    #1

    Hi, I've a modal dialog box and I've tried to set a bitmap background:

    case WM_ERASEBKGND:
    {
    HDC memDC, hdc;
    HBITMAP hBmp;
    BITMAP bmp;
    RECT rcc;

    hdc = GetDC(hDlg);
    hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BMP));
    memDC = CreateCompatibleDC(hdc);

    SelectObject(memDC,hBmp);
    GetObject(hBmp, sizeof(bmp), &bmp);
    GetClientRect(hDlg,&rcc);

    SetStretchBltMode(hdc, HALFTONE);
    StretchBlt(hdc,
    0,0, rcc.right,rcc.bottom,
    memDC,
    0,0,bmp.bmWidth, bmp.bmHeight,
    SRCCOPY);

    DeleteDC(memDC);
    DeleteObject(hBmp);
    ReleaseDC(hDlg,hdc);

    return (INT_PTR)TRUE;
    }

    this code set a background bitmap, but when I move or resize the dialog controls(edit,button,listbox,...) disappear under the bitmap...what's wrong?how can i repaint correctly the dialog?

    C enhzflepE 2 Replies Last reply
    0
    • M Member 2965471

      Hi, I've a modal dialog box and I've tried to set a bitmap background:

      case WM_ERASEBKGND:
      {
      HDC memDC, hdc;
      HBITMAP hBmp;
      BITMAP bmp;
      RECT rcc;

      hdc = GetDC(hDlg);
      hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BMP));
      memDC = CreateCompatibleDC(hdc);

      SelectObject(memDC,hBmp);
      GetObject(hBmp, sizeof(bmp), &bmp);
      GetClientRect(hDlg,&rcc);

      SetStretchBltMode(hdc, HALFTONE);
      StretchBlt(hdc,
      0,0, rcc.right,rcc.bottom,
      memDC,
      0,0,bmp.bmWidth, bmp.bmHeight,
      SRCCOPY);

      DeleteDC(memDC);
      DeleteObject(hBmp);
      ReleaseDC(hDlg,hdc);

      return (INT_PTR)TRUE;
      }

      this code set a background bitmap, but when I move or resize the dialog controls(edit,button,listbox,...) disappear under the bitmap...what's wrong?how can i repaint correctly the dialog?

      C Offline
      C Offline
      Cheongwadae
      wrote on last edited by
      #2

      Hi, Try creating the window with the WS_CLIPCHILDREN window style. Also... you might be better off painting the bitmap in WM_PAINT and returning TRUE in your WM_ERASEBKGND handler to avoid flicker.

      R 1 Reply Last reply
      0
      • C Cheongwadae

        Hi, Try creating the window with the WS_CLIPCHILDREN window style. Also... you might be better off painting the bitmap in WM_PAINT and returning TRUE in your WM_ERASEBKGND handler to avoid flicker.

        R Offline
        R Offline
        Ram Shelke
        wrote on last edited by
        #3

        Please see the order if u are give the order for bitmap at the last the it will overwrite ur textbox and other things :laugh:

        1 Reply Last reply
        0
        • M Member 2965471

          Hi, I've a modal dialog box and I've tried to set a bitmap background:

          case WM_ERASEBKGND:
          {
          HDC memDC, hdc;
          HBITMAP hBmp;
          BITMAP bmp;
          RECT rcc;

          hdc = GetDC(hDlg);
          hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BMP));
          memDC = CreateCompatibleDC(hdc);

          SelectObject(memDC,hBmp);
          GetObject(hBmp, sizeof(bmp), &bmp);
          GetClientRect(hDlg,&rcc);

          SetStretchBltMode(hdc, HALFTONE);
          StretchBlt(hdc,
          0,0, rcc.right,rcc.bottom,
          memDC,
          0,0,bmp.bmWidth, bmp.bmHeight,
          SRCCOPY);

          DeleteDC(memDC);
          DeleteObject(hBmp);
          ReleaseDC(hDlg,hdc);

          return (INT_PTR)TRUE;
          }

          this code set a background bitmap, but when I move or resize the dialog controls(edit,button,listbox,...) disappear under the bitmap...what's wrong?how can i repaint correctly the dialog?

          enhzflepE Offline
          enhzflepE Offline
          enhzflep
          wrote on last edited by
          #4

          Hi, I seem to remember trying this in the past, though failed miserably (presumably for the same reason) I recall using a frame based window, since I could define the background image (as a HBRUSH) in the windows class (ms class, not c++ class) Anyhow, I just ad a few fresh ideas and seem to have resolved the issue. I'll admit I didn't try with a bmp, but since trying to paint a solid color resulted in the same behaviour, I'll (perhaps foolishly?) assume that the solution would be valid if I had. [EDIT: yup - it works just fine with a bitmap too] It's just a simple matter of calling InvalidateRect along with the hWnd of the dialog, the client area (or NULL for all of it) and False - for do not redraw. I.e, just add the line

          InvalidateRect(hwndDlg, NULL, false);

          after you've done the clean-up and before you return true. Something like so:

                  case WM\_ERASEBKGND:
                  {
                      HDC memDC, hdc;
                      HBITMAP hBmp;
                      BITMAP bmp;
                      RECT rcc;
          
                      hdc = GetDC(hwndDlg);
                      hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB\_BITMAP1));
          
                      memDC = CreateCompatibleDC(hdc);
          
                      SelectObject(memDC,hBmp);
                      GetObject(hBmp, sizeof(bmp), &bmp);
                      GetClientRect(hwndDlg,&rcc);
          
                      SetStretchBltMode(hdc, HALFTONE);
                      StretchBlt(hdc, 0,0, rcc.right,rcc.bottom, memDC, 0,0,bmp.bmWidth, bmp.bmHeight, SRCCOPY);
          
                      DeleteDC(memDC);
                      DeleteObject(hBmp);
                      ReleaseDC(hwndDlg,hdc);
                      InvalidateRect(hwndDlg, NULL, false);
          
                  return (INT\_PTR)TRUE;
                  }
          
          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups