Drawing on Dialog using DC
-
Hi all, i have a dialog, i catch the OnPaint() message. here is the code
void CMyDialog::OnPaint()
{
CPaintDC dc(this); // device context for painting
GetWindowRect(m_rectDlg);
PlaceTitleBorder(dc);
}in in the PlaceTitleBorder() method i draw a bitmap:
void CMyDialog::PlaceTitleBorder(CPaintDC &dc)
{
BITMAP bmp;
memset(&bmp,0,sizeof(bmp));
::GetObject(m_hTitleBorder,sizeof(bmp),&bmp);
HDC compatibleDC = ::CreateCompatibleDC(dc);
HBITMAP hSavedObj;
hSavedObj = (HBITMAP)::SelectObject(compatibleDC,m_hTitleBorder);
BOOL bRes = StretchBlt(dc,
m_rectTitleBorder->left,
m_rectTitleBorder->top,
m_rectTitleBorder->Width(),
m_rectTitleBorder->Height(),
compatibleDC,
0,
0,
bmp.bmWidth,
bmp.bmHeight,
SRCCOPY);
::SelectObject(compatibleDC,hSavedObj);
::DeleteDC(compatibleDC);
}when dialog appear i see the bitmap ok. when i move the dialog around the screen and go out of the bounds of the screen, and then return to the screen, the bitmap disappears (not redrawn???) can any1 help me?? thanks in advanced Yaron Ask not what your application can do for you, Ask what you can do for your application
-
Hi all, i have a dialog, i catch the OnPaint() message. here is the code
void CMyDialog::OnPaint()
{
CPaintDC dc(this); // device context for painting
GetWindowRect(m_rectDlg);
PlaceTitleBorder(dc);
}in in the PlaceTitleBorder() method i draw a bitmap:
void CMyDialog::PlaceTitleBorder(CPaintDC &dc)
{
BITMAP bmp;
memset(&bmp,0,sizeof(bmp));
::GetObject(m_hTitleBorder,sizeof(bmp),&bmp);
HDC compatibleDC = ::CreateCompatibleDC(dc);
HBITMAP hSavedObj;
hSavedObj = (HBITMAP)::SelectObject(compatibleDC,m_hTitleBorder);
BOOL bRes = StretchBlt(dc,
m_rectTitleBorder->left,
m_rectTitleBorder->top,
m_rectTitleBorder->Width(),
m_rectTitleBorder->Height(),
compatibleDC,
0,
0,
bmp.bmWidth,
bmp.bmHeight,
SRCCOPY);
::SelectObject(compatibleDC,hSavedObj);
::DeleteDC(compatibleDC);
}when dialog appear i see the bitmap ok. when i move the dialog around the screen and go out of the bounds of the screen, and then return to the screen, the bitmap disappears (not redrawn???) can any1 help me?? thanks in advanced Yaron Ask not what your application can do for you, Ask what you can do for your application
Hi YaronNir, I think this is not good way to rewrite OnPaint in dialog (hmmm - f.e. because dialog may contain other elements). Insted this let try to put cpecial element on the dialog and draw bitmap in to it. Hope this help. Vitali http://www.creative-case.com[^]
-
Hi YaronNir, I think this is not good way to rewrite OnPaint in dialog (hmmm - f.e. because dialog may contain other elements). Insted this let try to put cpecial element on the dialog and draw bitmap in to it. Hope this help. Vitali http://www.creative-case.com[^]
-
Hi all, i have a dialog, i catch the OnPaint() message. here is the code
void CMyDialog::OnPaint()
{
CPaintDC dc(this); // device context for painting
GetWindowRect(m_rectDlg);
PlaceTitleBorder(dc);
}in in the PlaceTitleBorder() method i draw a bitmap:
void CMyDialog::PlaceTitleBorder(CPaintDC &dc)
{
BITMAP bmp;
memset(&bmp,0,sizeof(bmp));
::GetObject(m_hTitleBorder,sizeof(bmp),&bmp);
HDC compatibleDC = ::CreateCompatibleDC(dc);
HBITMAP hSavedObj;
hSavedObj = (HBITMAP)::SelectObject(compatibleDC,m_hTitleBorder);
BOOL bRes = StretchBlt(dc,
m_rectTitleBorder->left,
m_rectTitleBorder->top,
m_rectTitleBorder->Width(),
m_rectTitleBorder->Height(),
compatibleDC,
0,
0,
bmp.bmWidth,
bmp.bmHeight,
SRCCOPY);
::SelectObject(compatibleDC,hSavedObj);
::DeleteDC(compatibleDC);
}when dialog appear i see the bitmap ok. when i move the dialog around the screen and go out of the bounds of the screen, and then return to the screen, the bitmap disappears (not redrawn???) can any1 help me?? thanks in advanced Yaron Ask not what your application can do for you, Ask what you can do for your application
I'm doing that too, but it works. Even if the dialog needs a refresh / redraw. Just to show an example, which should not look very strange from your point of view : 1) Define the handlers for InitDialog and OnPaint and add a CBitmap object in the dialogs header : class CMyDialog : public CDialog { : virtual BOOL OnInitDialog(); afx_msg void OnPaint(); : CBitmap m_bmMyBitmap; : }; 2) make sure that the OnPaint:handler are in the CPP-File : BEGIN_MESSAGE_MAP(CMyDialog, CDialog) //{{AFX_MSG_MAP(CMyDialog) ON_WM_PAINT() //}}AFX_MSG_MAP END_MESSAGE_MAP() 3) Init the Bitmap object in the OnInitDialog function BOOL CMyDialog::OnInitDialog() { CDialog::OnInitDialog(); m_bmMyBitmap.LoadBitmap( IDB_MY_BITMAP ); } 4) Fill the OnPaint-Handler : void CDialogDruckauswahl::OnPaint() { CPaintDC dc(this); // device context for painting // fill dialog background with some color..... CRect crRect; GetClientRect( &crRect ); COLORREF crColor = RGB( 255,255,255 ); CBrush* pFillBrush = new CBrush( crColor ); CBrush* pOldBrush = dc.SelectObject( pFillBrush ); CPen* pNewPen = new CPen( PS_SOLID, 1, crColor ); CPen* pOldPen = dc.SelectObject( pNewPen ); dc.Rectangle( crRect ); dc.SelectObject( pOldPen ); delete pNewPen; pNewPen = NULL; dc.SelectObject( pOldBrush ); delete pFillBrush; pFillBrush = NULL; // in welchen Bereich ? DrawBitmap( &dc, crRect, &m_bmMyBitmap ); } 5) at least : define the bitmap drawing function : void CMyDialog::DrawBitmap( CDC* pDC, CRect crRect, CBitmap* pBM ) { // create a memory dc to prepare drawing via bitblt ... CDC* pmemDCBitBlt = new CDC(); pmemDCBitBlt->CreateCompatibleDC( pDC ); CBitmap* pOldBM = pmemDCBitBlt->SelectObject( pBM ); // blit the bitmap into our view using the bitblt-xor-mode pDC->BitBlt(crRect.TopLeft().x, crRect.TopLeft().y, crRect.Width(), crRect.Height(), pmemDCBitBlt, 0, 0, SRCCOPY ); // free the memory dc and the bitmap .... pmemDCBitBlt->SelectObject( pOldBM ); delete pmemDCBitBlt; pmemDCBitBlt = NULL; }
-
I'm doing that too, but it works. Even if the dialog needs a refresh / redraw. Just to show an example, which should not look very strange from your point of view : 1) Define the handlers for InitDialog and OnPaint and add a CBitmap object in the dialogs header : class CMyDialog : public CDialog { : virtual BOOL OnInitDialog(); afx_msg void OnPaint(); : CBitmap m_bmMyBitmap; : }; 2) make sure that the OnPaint:handler are in the CPP-File : BEGIN_MESSAGE_MAP(CMyDialog, CDialog) //{{AFX_MSG_MAP(CMyDialog) ON_WM_PAINT() //}}AFX_MSG_MAP END_MESSAGE_MAP() 3) Init the Bitmap object in the OnInitDialog function BOOL CMyDialog::OnInitDialog() { CDialog::OnInitDialog(); m_bmMyBitmap.LoadBitmap( IDB_MY_BITMAP ); } 4) Fill the OnPaint-Handler : void CDialogDruckauswahl::OnPaint() { CPaintDC dc(this); // device context for painting // fill dialog background with some color..... CRect crRect; GetClientRect( &crRect ); COLORREF crColor = RGB( 255,255,255 ); CBrush* pFillBrush = new CBrush( crColor ); CBrush* pOldBrush = dc.SelectObject( pFillBrush ); CPen* pNewPen = new CPen( PS_SOLID, 1, crColor ); CPen* pOldPen = dc.SelectObject( pNewPen ); dc.Rectangle( crRect ); dc.SelectObject( pOldPen ); delete pNewPen; pNewPen = NULL; dc.SelectObject( pOldBrush ); delete pFillBrush; pFillBrush = NULL; // in welchen Bereich ? DrawBitmap( &dc, crRect, &m_bmMyBitmap ); } 5) at least : define the bitmap drawing function : void CMyDialog::DrawBitmap( CDC* pDC, CRect crRect, CBitmap* pBM ) { // create a memory dc to prepare drawing via bitblt ... CDC* pmemDCBitBlt = new CDC(); pmemDCBitBlt->CreateCompatibleDC( pDC ); CBitmap* pOldBM = pmemDCBitBlt->SelectObject( pBM ); // blit the bitmap into our view using the bitblt-xor-mode pDC->BitBlt(crRect.TopLeft().x, crRect.TopLeft().y, crRect.Width(), crRect.Height(), pmemDCBitBlt, 0, 0, SRCCOPY ); // free the memory dc and the bitmap .... pmemDCBitBlt->SelectObject( pOldBM ); delete pmemDCBitBlt; pmemDCBitBlt = NULL; }
-
hi, thanks for the reply... What can you suggest i do ?? Ask not what your application can do for you, Ask what you can do for your application
I usualy put some element in the dialog such as image or button and put image in to it. Vitali http://www.creative-case.com[^]