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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to show the Bitmap at top ?

How to show the Bitmap at top ?

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicstutorialquestion
4 Posts 4 Posters 0 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.
  • A Offline
    A Offline
    Amarelia
    wrote on last edited by
    #1

    Hi I am showing a bitmap in my dialog based MFC programm. I have also put some Static Control and that goes overlapped to the bitmap I want to saw. Is there any way to show bitmap at forground and static control in background so that we can see the bitmap still overlapping the static control My code is as follow : MyDlg.cpp ========= BOOL MyDlg::OnInitDialog() { CDialog::OnInitDialog(); OnInitBitmap(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon return TRUE; } void CMyDlg::OnInitBitmap() { //Give the path and name of bitmap file to the given Bitmap variable m_sBitmap = "C:\\Test.bmp"; HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), m_sBitmap, IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION); if(hBitmap) { if (m_bmpBitmap.DeleteObject()) m_bmpBitmap.Detach(); m_bmpBitmap.Attach(hBitmap); } return; } void MyDlg::ShowBitmap(CPaintDC *pdc) { BITMAP bm; int iStartX,iStartY, iHeight, iWidth; HWND hWnd; bool bRes; CRect myRect; hWnd = ::GetDesktopWindow(); bRes = ::GetWindowRect(hWnd,myRect); ClientToScreen(myRect); m_bmpBitmap.GetBitmap(&bm); CDC dcMem; dcMem.CreateCompatibleDC(pdc); CBitmap *pOldBitmap = (CBitmap *) dcMem.SelectObject(m_bmpBitmap); CRect lRect; GetClientRect(lRect); lRect.NormalizeRect(); iStartX = m_BorderWidth; iStartY = myRect.Height(); iHeight = bm.bmHeight-20; pdc->StretchBlt(iStartX,iStartY,iWidth, iHeight, &dcMem, 0,0, bm.bmWidth,bm.bmHeight, SRCCOPY); return; } void MyDlg::OnPaint() { CPaintDC dc(this); ShowBitmap(&dc); if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else CDialog::OnPaint(); } Amarelia Maehsh Gujarat India

    E N 2 Replies Last reply
    0
    • A Amarelia

      Hi I am showing a bitmap in my dialog based MFC programm. I have also put some Static Control and that goes overlapped to the bitmap I want to saw. Is there any way to show bitmap at forground and static control in background so that we can see the bitmap still overlapping the static control My code is as follow : MyDlg.cpp ========= BOOL MyDlg::OnInitDialog() { CDialog::OnInitDialog(); OnInitBitmap(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon return TRUE; } void CMyDlg::OnInitBitmap() { //Give the path and name of bitmap file to the given Bitmap variable m_sBitmap = "C:\\Test.bmp"; HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), m_sBitmap, IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION); if(hBitmap) { if (m_bmpBitmap.DeleteObject()) m_bmpBitmap.Detach(); m_bmpBitmap.Attach(hBitmap); } return; } void MyDlg::ShowBitmap(CPaintDC *pdc) { BITMAP bm; int iStartX,iStartY, iHeight, iWidth; HWND hWnd; bool bRes; CRect myRect; hWnd = ::GetDesktopWindow(); bRes = ::GetWindowRect(hWnd,myRect); ClientToScreen(myRect); m_bmpBitmap.GetBitmap(&bm); CDC dcMem; dcMem.CreateCompatibleDC(pdc); CBitmap *pOldBitmap = (CBitmap *) dcMem.SelectObject(m_bmpBitmap); CRect lRect; GetClientRect(lRect); lRect.NormalizeRect(); iStartX = m_BorderWidth; iStartY = myRect.Height(); iHeight = bm.bmHeight-20; pdc->StretchBlt(iStartX,iStartY,iWidth, iHeight, &dcMem, 0,0, bm.bmWidth,bm.bmHeight, SRCCOPY); return; } void MyDlg::OnPaint() { CPaintDC dc(this); ShowBitmap(&dc); if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else CDialog::OnPaint(); } Amarelia Maehsh Gujarat India

      E Offline
      E Offline
      Eytukan
      wrote on last edited by
      #2

      is there anything like zindex in MFC? i'm not sure..:~ Regards, V

      T 1 Reply Last reply
      0
      • A Amarelia

        Hi I am showing a bitmap in my dialog based MFC programm. I have also put some Static Control and that goes overlapped to the bitmap I want to saw. Is there any way to show bitmap at forground and static control in background so that we can see the bitmap still overlapping the static control My code is as follow : MyDlg.cpp ========= BOOL MyDlg::OnInitDialog() { CDialog::OnInitDialog(); OnInitBitmap(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon return TRUE; } void CMyDlg::OnInitBitmap() { //Give the path and name of bitmap file to the given Bitmap variable m_sBitmap = "C:\\Test.bmp"; HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), m_sBitmap, IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION); if(hBitmap) { if (m_bmpBitmap.DeleteObject()) m_bmpBitmap.Detach(); m_bmpBitmap.Attach(hBitmap); } return; } void MyDlg::ShowBitmap(CPaintDC *pdc) { BITMAP bm; int iStartX,iStartY, iHeight, iWidth; HWND hWnd; bool bRes; CRect myRect; hWnd = ::GetDesktopWindow(); bRes = ::GetWindowRect(hWnd,myRect); ClientToScreen(myRect); m_bmpBitmap.GetBitmap(&bm); CDC dcMem; dcMem.CreateCompatibleDC(pdc); CBitmap *pOldBitmap = (CBitmap *) dcMem.SelectObject(m_bmpBitmap); CRect lRect; GetClientRect(lRect); lRect.NormalizeRect(); iStartX = m_BorderWidth; iStartY = myRect.Height(); iHeight = bm.bmHeight-20; pdc->StretchBlt(iStartX,iStartY,iWidth, iHeight, &dcMem, 0,0, bm.bmWidth,bm.bmHeight, SRCCOPY); return; } void MyDlg::OnPaint() { CPaintDC dc(this); ShowBitmap(&dc); if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else CDialog::OnPaint(); } Amarelia Maehsh Gujarat India

        N Offline
        N Offline
        Neagoe Gabriel
        wrote on last edited by
        #3

        void MyDlg::OnPaint() { CPaintDC dc(this); ShowBitmap(&dc); } this is the only paint you need to do... NG

        1 Reply Last reply
        0
        • E Eytukan

          is there anything like zindex in MFC? i'm not sure..:~ Regards, V

          T Offline
          T Offline
          ThatsAlok
          wrote on last edited by
          #4

          Vivekuniq wrote: like zindex in MFC Zindex or Z-order is way application windows are placed in Windows Enviornment

          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

          cheers, Alok Gupta VC Forum Q&A :- I/ IV

          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