finally i have the static control transparent:
//creating the form:
hwnd = CreateWindowEx(0, classname, strCaption.c_str(),WS_OVERLAPPEDWINDOW | WS_TABSTOP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, parent, NULL, mod, this);
//sending a message for subclassing:
case WM_CTLCOLORSTATIC:
{
return DefWindowProc(HandleWindow, msg, wParam, lParam);
}
break;
//heres how i create a static control with ownerdraw style:
hwnd = CreateWindowEx(
0,
TEXT("CSTATIC"),//these must be the same of LabelClass.lpszClassName
strCaption.c_str(), WS_TABSTOP|
WS_CHILD | WS_VISIBLE | SS_NOTIFY | SS_OWNERDRAW | WS_TABSTOP,
intLeft, intTop, intWidth, intHeight,
parent,
NULL,
mod,
(LPVOID)this);
//now here the static messages for draw it:
case WM_CTLCOLORSTATIC:
{
HDC hdcStatic = (HDC) wParam;
SetTextColor(hdcStatic, RGB(0,0,0));
SetBkMode (hdcStatic, TRANSPARENT);
return (LRESULT)GetStockObject(NULL_BRUSH);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(inst->hwnd, &ps);//inst is the static object pointer
if(inst->Paint==NULL)
{
if(inst->blnTransparent!=true)
FillRect(ps.hdc,&ps.rcPaint, CreateSolidBrush(inst->clrBackColor));
if(inst->imgtest.haveimage())
DrawHICONtoHDC(ps.hdc, inst->imgtest,1,1);
SetBkMode(ps.hdc,TRANSPARENT);
char *text=(char*)inst->strCaption.c_str();
SetTextColor(ps.hdc,inst->clrTextColor );
DrawTextEx(ps.hdc,text,-1,&ps.rcPaint,DT_LEFT,NULL);
if(inst->blnBorder==true)
DrawEdge(ps.hdc, &ps.rcPaint,BDR_SUNKENINNER | BDR_RAISEDOUTER,BF_RECT);
}
EndPaint(inst->hwnd, &ps);
}
break;
//and now heres the code for make it transparent:
void setTransparent(bool transparent)
{
blnTransparent = transparent;
LONG_PTR s;
if(transparent==true)
{
blnTransparent=true;
s=GetWindowLongPtr(hwnd,GWL_EXSTYLE);
s|=WS_EX_TRANSPARENT;
SetWindowLongPtr(hwnd,GWL_EXSTYLE,s);
}
else
{
s=GetWindowLongPtr(hwnd,GWL_EXSTYLE);
s&=~WS_EX_TRANSPARENT;
SetWindowLongPtr(hwnd,GWL_EXSTYLE,s);
blnTransparent=false;
}
InvalidateRect(hwnd,NULL,FALSE);
}
some code is from my header file. but i think that it's easy to follow.
readers: any problems please tell me.
but these label transparent have 1 problem:
(see the image)
(if i fill 1 color, that color is showed)
how can i clean the image before repaint?