case WM_CTLCOLORSTATIC:
if ((HWND)lParam == GetDlgItem(hDlg, IDC_NAME))
{
SetBkMode((HDC)wParam,TRANSPARENT);
SetTextColor((HDC)wParam, RGB(255,255,255));
return (LRESULT)GetStockObject(NULL_BRUSH);
}
else
{
return TRUE;
}
in this code, the SETCOLOR works properly adn changes the color of my text,
But the
SetBkMode((HDC)wParam,TRANSPARENT);
is not working, ive waisted a lot of time on it, please someone help me to
sort out the problem
Thanks
uo will have to follow some proper sequence in order to show ur static
control tranparent,
First do this
if ((HWND)lParam == GetDlgItem(hDlg, IDC_NAME))
{
SetBkMode((HDC)wParam,TRANSPARENT);
SetTextColor((HDC)wParam, RGB(255,255,255));
return (LRESULT)GetStockObject(NULL_BRUSH);
}
else
{
return TRUE;
}
and then, you will have to manually make the Re Draw behavior of Ur control.
I mean to say that if u suppose your control's background is changing
dynamically, you will have to Hide Then show again ur static control. This
will make it transparent OVER the latest item in its background.
Check it n see what happens.
Regards
i try you sugestion but does not work!
my code is this:
if ((HWND)lParam == GetDlgItem(hDlg, IDC_LB03))
{
SetBkMode((HDC)wParam,TRANSPARENT);
SetTextColor((HDC)wParam, RGB(255,255,255));
//HIDE AND SHOW THE STATIC
ShowWindow(GetDlgItem(hDlg, IDC_LB03),SW_HIDE);
ShowWindow(GetDlgItem(hDlg, IDC_LB03),SW_SHOW);
return (LRESULT)GetStockObject(NULL_BRUSH);
}
else
{
return TRUE;
}
that is right?
thanks
case WM_CTLCOLORSTATIC:
if ((HWND)lParam == GetDlgItem(hDlg, IDC_NAME))
{
COLORREF crefText=RGB(255,255,255);
SetTextColor((HDC)wParam, crefText);
SetBkMode((HDC)wParam,TRANSPARENT);
return (LRESULT)GetStockObject(NULL_BRUSH);
}
else
return TRUE;
The upper code will add in the WINDPROC's WM_CTLCOLORSTATIC message..
It will work fine a bit. But the win32 programing limitation in embeded os
is that is DO not repaint any window if its background is changed. say, a
bitmap haveing RED color was behing static control NAME. It gets transparent
by copying red into its windows,but if the picture control beneath it changes
the bitmap with BLUE one, the upper statics window do not repaint itself. so
it still have the prev RED BG(not transparent BLUE indeed).
So to overcome this, we must know that where in out applicaton or code, the
backgroung of TRANSPARENT STATIC control will change, say, it changes in a
function f1( ) line 2. Then we will have have to notify STATIC NAME control
in our example to repaint its windows(line 3 of f1( ) ), for that, i asked u
to do this by hiding n showing the static window, like
say we are at the dummy function f1 where it is supposed that STATIC name
control's BG is gonna change at line 2. then well make it repaint at line 3 as
f1( )
{
/////some bg contents changed
////some bg contents changed
///line 3 in my discution////
hWnd = GetDlgItem(hDlg,IDC_NAME);
ShowWindow(hWnd, SW_HIDE);
UpdateWindow(hWnd);
//these 3 lines will make the IDC_NAME to repaint its window, which will be
done according to CTLCOLORSTATIC message where we r passing null brush,
white text color and transprant bk mod. So after line 3,4,5 in this function,
our IDC_STATIC will look transparent evern if its background is changed in
ine 1,2
}
try it.
Best of luck
Regard
Then
thanks!!
//these 3 lines will make the IDC_NAME to repaint its window, which will be
done according to CTLCOLORSTATIC message where we r passing null brush,
white text color and transprant bk mod. So after line 3,4,5 in this function,
our IDC_STATIC will look transparent evern if its background is changed in
ine 1,2
thanks
then in WM_initiate message
case WM_initiate:
you will hide ur static control, show it and then update it like
{
HWND hWnd;
hWnd = GetDlgItem(hDlg,IDC_NAME);
ShowWindow(hWnd, SW_HIDE);
UpdateWindow(hWnd);
}
Do this and look what happens with the static control you want to make
transparent. Here, im taking the ID of that control as IDC_NAME. u'll use ur
own
(sorry for my english)
In MFC I've found that controls which are not visible (include items
changed by SW_HIDE), aren't executed by OnCtlColor. (Maybe it's only
in MFC???)
but my problem is elsewhere.
i'm trying dialog with picture background with lot of CEdit cotrols
every with transparent CStatic label.
but when main dialog window is first time painted, it has number holes
(incuding bmp painting using BitBlt) - for every one control that will
be used.
For transparent CStatic is a problem - label is completely transparent
throught all aplication to shell desktop :-(((
It's possible solve this with starting with property novisible for
labels and using SW_HIDE/SW_SHOW, but for lots of labels it's not very
efectively.
How can I turn off/on this for main dialog (in Win32 it paint dialog
window correct)
Thanks
All we have to do in normal win32 is settings transparent background an
returning NULL brush in "OnCtlColor"
But in embeded devices, wince, win mobile etc,. .. i think it is not
sufficient, so i said that you shuld manually force the CONTROL (UR static)
to repaint itself whenever u suppose that its background is changing,,,
Another idea is the use of BITBLT..on the initiation of ur dialog, u can
bitblt all the "holes U SAID", ...
using bitbilt , u can manually draw the backgroung within all ur controls
over windows which are making holes, so that the window beneath them is shown
within them, which creates transparency...
case WM_CTLCOLORSTATIC:
if ((HWND)lParam == GetDlgItem(hDlg, IDC_NAME))
{
SetBkMode((HDC)wParam,TRANSPARENT);
HDC hdc = (HDC)wParam;
if(user_bg==FALSE)
{
RECT wRect;
GetWindowRect((HWND)lParam,&wRect);
HDC bitmapDC = CreateCompatibleDC(hdc);
HGDIOBJ old_bitmap = SelectObject(bitmapDC,hBmBg);
BitBlt(hdc,0,0,wRect.right-wRect.left,
wRect.bottom-wRect.top,bitmapDC,0,0,SRCCOPY);
SelectObject(bitmapDC,old_bitmap);
DeleteDC(bitmapDC);
}
return (LRESULT)GetStockObject(NULL_BRUSH);
}
else
{
return TRUE;
}
case WM_ERASEBKGND:
return FALSE;