How to show the Bitmap at top ?
-
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
-
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
-
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
void MyDlg::OnPaint() { CPaintDC dc(this); ShowBitmap(&dc); } this is the only paint you need to do... NG
-
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