Need help on MemDC , Drawtext() coding
-
Hi,with the following code, I marked 3 statements, with the following statements, nothing on the screen,I mean no "TEST,TEST" string and no black box.
pStatic->GetWindowRect(&rect); //display nothing
ScreenToClient(&rect); //display nothingwhile with
/pStatic->GetClientRect(&rect); //Display well
"TEST,TEST",black background box display well. Is anybody know the reason? Thanks
void CStaticTextTstDlg::OnPaint()
{
if (IsIconic())
{
...
}
else
{
CDC *pDC = GetDC();
CBitmap memBmp;
CBitmap *pBmpOld;
CDC memDC;CStatic \*pStatic = (CStatic\*)GetDlgItem(IDC\_STATIC\_TXT1); pStatic->ModifyStyle(0, BS\_OWNERDRAW); CRect rect;
//pStatic->GetClientRect(&rect); //Display well
pStatic->GetWindowRect(&rect); //display nothing
ScreenToClient(&rect); //display nothingmemBmp.CreateCompatibleBitmap(pDC,176,50); memDC.CreateCompatibleDC(NULL); pBmpOld = memDC.SelectObject(&memBmp); memDC.SetTextColor(RGB(0,230,0)); memDC.SetBkMode(TRANSPARENT); memDC.FillSolidRect(rect.left,rect.top,176,50,RGB(0,0,0)); memDC.DrawText(\_T("TEST TEST"),-1,&rect,DT\_CENTER|DT\_VCENTER|DT\_SINGLELINE);
CPaintDC dc(this);
dc.BitBlt(137,107,176,50,&memDC,rect.left,rect.top,SRCCOPY); memDC.SelectObject(pBmpOld); memBmp.DeleteObject(); memDC.DeleteDC(); CDialog::OnPaint();
}
}
Thanks
-
Hi,with the following code, I marked 3 statements, with the following statements, nothing on the screen,I mean no "TEST,TEST" string and no black box.
pStatic->GetWindowRect(&rect); //display nothing
ScreenToClient(&rect); //display nothingwhile with
/pStatic->GetClientRect(&rect); //Display well
"TEST,TEST",black background box display well. Is anybody know the reason? Thanks
void CStaticTextTstDlg::OnPaint()
{
if (IsIconic())
{
...
}
else
{
CDC *pDC = GetDC();
CBitmap memBmp;
CBitmap *pBmpOld;
CDC memDC;CStatic \*pStatic = (CStatic\*)GetDlgItem(IDC\_STATIC\_TXT1); pStatic->ModifyStyle(0, BS\_OWNERDRAW); CRect rect;
//pStatic->GetClientRect(&rect); //Display well
pStatic->GetWindowRect(&rect); //display nothing
ScreenToClient(&rect); //display nothingmemBmp.CreateCompatibleBitmap(pDC,176,50); memDC.CreateCompatibleDC(NULL); pBmpOld = memDC.SelectObject(&memBmp); memDC.SetTextColor(RGB(0,230,0)); memDC.SetBkMode(TRANSPARENT); memDC.FillSolidRect(rect.left,rect.top,176,50,RGB(0,0,0)); memDC.DrawText(\_T("TEST TEST"),-1,&rect,DT\_CENTER|DT\_VCENTER|DT\_SINGLELINE);
CPaintDC dc(this);
dc.BitBlt(137,107,176,50,&memDC,rect.left,rect.top,SRCCOPY); memDC.SelectObject(pBmpOld); memBmp.DeleteObject(); memDC.DeleteDC(); CDialog::OnPaint();
}
}
Thanks
Is it OK if I record it into mp3 format before mailing it to you? Maybe wav would be too large but today saving a few hundred megabytes is no big deal and it has a bit better quality...
-
Is it OK if I record it into mp3 format before mailing it to you? Maybe wav would be too large but today saving a few hundred megabytes is no big deal and it has a bit better quality...
-
Hi,with the following code, I marked 3 statements, with the following statements, nothing on the screen,I mean no "TEST,TEST" string and no black box.
pStatic->GetWindowRect(&rect); //display nothing
ScreenToClient(&rect); //display nothingwhile with
/pStatic->GetClientRect(&rect); //Display well
"TEST,TEST",black background box display well. Is anybody know the reason? Thanks
void CStaticTextTstDlg::OnPaint()
{
if (IsIconic())
{
...
}
else
{
CDC *pDC = GetDC();
CBitmap memBmp;
CBitmap *pBmpOld;
CDC memDC;CStatic \*pStatic = (CStatic\*)GetDlgItem(IDC\_STATIC\_TXT1); pStatic->ModifyStyle(0, BS\_OWNERDRAW); CRect rect;
//pStatic->GetClientRect(&rect); //Display well
pStatic->GetWindowRect(&rect); //display nothing
ScreenToClient(&rect); //display nothingmemBmp.CreateCompatibleBitmap(pDC,176,50); memDC.CreateCompatibleDC(NULL); pBmpOld = memDC.SelectObject(&memBmp); memDC.SetTextColor(RGB(0,230,0)); memDC.SetBkMode(TRANSPARENT); memDC.FillSolidRect(rect.left,rect.top,176,50,RGB(0,0,0)); memDC.DrawText(\_T("TEST TEST"),-1,&rect,DT\_CENTER|DT\_VCENTER|DT\_SINGLELINE);
CPaintDC dc(this);
dc.BitBlt(137,107,176,50,&memDC,rect.left,rect.top,SRCCOPY); memDC.SelectObject(pBmpOld); memBmp.DeleteObject(); memDC.DeleteDC(); CDialog::OnPaint();
}
}
Thanks
GetClientRect returns the area of the drawable area inside the window. It will usually return something like 0,0,width,height in your rect structure GetWindowRect returns the co-ordinates of the Window itself relative to the upper left of the screen so they will be rather large. If you try to use GetWindowRect co-ordinates to draw on the window they will be way outside the right and bottom and the drawing wont be visible unless you drag the window right up to the top left off screen. You need to use GetClientRect co-ordinates to draw with. Looking at your code I am guessing this line is the problem if you have a position problem
dc.BitBlt(137,107,176,50,&memDC,rect.left,rect.top,SRCCOPY);
Are you sure that is right?