Static transparent on Windows Mobile

Creating static text transparent is easy in Win32, you just need to create stock brush with HOLLOW_BRUSH.

Unfortunately this doesn’t work on Windows Mobile, there’s a workaround that you can copy the background image and draw it on the static control.

You must subclass the MFC CStatic control and make it owner drawn control.

code:

 void CCeStatic::OnPaint(){

CPaintDC dc( 

this); // device context for painting

CDC memDC; 

CRect r;
GetClientRect(&r);

 

if
(m_bmpBkgnd.m_hObject!=NULL){
memDC.CreateCompatibleDC(NULL);
memDC.SelectObject(bmpBkgnd);
dc.BitBlt(0,0,r.Width(),r.Height(), &memDC, 0, 0, SRCCOPY);
}

CString text;

GetWindowText(text);

dc.SetBkMode(TRANSPARENT);

dc.SelectObject(m_fontText);

dc.SetTextColor(m_crTextFgColor);

dc.DrawText(text,text.GetLength(),r,DT_VCENTER);

}

 

 

~ by arenosoft on June 6, 2008.

Leave a Reply