|
CONGRATULATIONS
You are the unique that resolve my problem with the background color! THANK U VERY MUCH
|
|
|
|
|
|
Hi,
I am not using MFC and doing this windows Mobile UI App for the first time.
I have a dialog box with one static control which shows a message. that message changes at every tic of timer( every second).
The dialog box is gradient fill with blue color.
I did equivalent of one of the method but still the new text overwrites on old, the old text keep sitting in the background.
This is what I modified in your code to ensure I am using same APIs. when these API call works on your side, what wrong am I doing.
LRESULT CTransparentStatic::OnSetText(WPARAM wParam,LPARAM lParam)
{
#if 0
LRESULT Result = Default();
CRect Rect;
GetWindowRect(&Rect);
GetParent()->ScreenToClient(&Rect);
GetParent()->InvalidateRect(&Rect);
GetParent()->UpdateWindow();
#else
LRESULT Result = DefWindowProc(WM_SETTEXT,wParam,lParam);
GetParent()->UpdateWindow();
CRect Rect;
POINT pt;
CWnd *parent;
GetWindowRect(&Rect);
InvalidateRect(&Rect);
pt.y = Rect.top;
pt.x = Rect.left;
GetParent()->ScreenToClient(&pt);
Rect.top = pt.y;
Rect.left = pt.x;
pt.y= Rect.bottom;
pt.x = Rect.right;
GetParent()->ScreenToClient(&pt);
Rect.bottom = pt.y;
Rect.right = pt.x;
GetParent()->InvalidateRect(&Rect);
GetParent()->UpdateWindow();
#endif
return Result;
}
Afetr this change your code still work fine.
but on my side:
INT_PTR CALLBACK HandleTextChange(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_SETTEXT:
{
LRESULT Result = DefWindowProc(hDlg,message,wParam,lParam);
HWND hwd;
RECT rc;
HDC hdc;
POINT pt;
#if 1
GetWindowRect(hDlg,&rc);
hwd = GetParent(hDlg);
pt.y = rc.top;
pt.x = rc.left;
ScreenToClient(hwd,&pt);
rc.top= pt.y;
rc.left = pt.x ;
pt.y = rc.bottom;
pt.x = rc.right;
ScreenToClient(hwd,&pt);
rc.bottom=pt.y;
rc.right =pt.x ;
InvalidateRect(hwd,&rc,TRUE);
UpdateWindow(hwd);
#endif
return Result;
}
break;
I have already wasted 2.5 days.
Please help.
|
|
|
|
|
The code looks good, if you can email me a sample app it would make it easier to track down the problem.
You can email it to AliR at learnstar.com
Ali
AliR.
Visual C++ MVP
|
|
|
|
|
I dropped in your CTransparentStatic2 and CTransparentListBox classes and they worked perfectly and simply. Thanks.
I was just wondering where I can find the mentioned transparent edit control. Or is that not finished?
Andrew Phillips
aphillips @ expertcomsoft.com
|
|
|
|
|
Hi Andrew,
I am glad you found my classes helpful. I am sorry I haven't had a chance to post the transparent edit control.
Here is one from Dany Cantin
http://www.codeproject.com/editctrl/ctrltrans.asp[^]
I will email you mine.
Ali
AliR.
Visual C++ MVP
|
|
|
|
|
Download for Transparent edit control.
http://www.learnstar.com/alir/TransparentEdit.zip
AliR.
Visual C++ MVP
|
|
|
|
|
There is not necessary to use derived class from static or edit control.
Set brush to ::GetStockObject (HOLLOW_BRUSH).
HBRUSH SomeDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hBrush = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
switch (nCtlColor) {
case CTLCOLOR_STATIC:
case CTLCOLOR_EDIT:
hBrush = (HBRUSH)::GetStockObject (HOLLOW_BRUSH);
pDC->SetBkMode (TRANSPARENT);
break;
....
return (hBrush);
}
|
|
|
|
|
That will work just fine as long as you're not going to change the text of the static control, and what's displayed behind the control is not changing either.
If you notice CTransparentStatic2::CtlColor is doing exactly what you are saying (I would argue that doing this in CStatic is much cleaner than catching WM_CTLCOLOR in the Dialog, you will only have to do it once in CStatic vers. many times if you have more than one dialog that will need to display transparent static controls).
The rest of the code in OnEraseBkgnd and OnSetText is to allow the user to call SetWindowText and change the Text of the static.
Using your approach try changing the static controls text by calling SetWindowText. You will see that old text is there along with the new text, unless you redraw force a redraw of the background window (that will cause flickering)
Ali
|
|
|
|
|
Thanks Ali for this summary!
I never understood this behaviour of WinAPI (background is not refreshed if you change text of an owner-draw static control), even WS_EX_TRANSPARENT style does not help. You seam to have two alternatives: take care of that yourself and paint the background in OnPaint() handler (bad if you're painting inside a property sheet with XP theme) or send an invalidate to the parent to force it to repaint the client's area.
/M
|
|
|
|
|
Hi,
Thanks for your Transparent Static.
But i have a problem with my application.
I build a CDialog dynamicaly with all the control not showed until all the control are created.
And when i show the dialog with all the control the background of the static is the image of my VC++ because the bmp background is calculate when my dialog is not showed.
Have you any idea how to get the right background or force to paint when the dialog is visible.
Thanks.
|
|
|
|
|
The problem her is that when the Static control is created it will receive a WM_ERASEBKGND message where it is getting the background it needs in order to draw itself..
There are three ways you can get around this problem.
1. Is to user CTransparentStatic instead of CTransparentStatic2 (I should have named these classes better). This class assumes that the background of the Parent is dynamically changing. So right after you show your controls, call the Static controls SetWindowText, and things will show up fine.
Example
CString Text;
m_TransStatic.GetWindowText(Text);
m_TransStatic.SetWindowText(Text);
2. You can add a method to the CTransparnetStatic2 class to clear it's cached background so that it is in an uninitialized state. Call that method right before you display your dialog box.
3. Instead of not showing the dialog, you can move it off screen, once everything is setup move it back to it's orginal place.
Ali
|
|
|
|
|
thanks for your help but the 3 ways don't work.
Arh !
When you say : "
2. You can add a method to the CTransparnetStatic2 class to clear it's cached background so that it is in an uninitialized state. Call that method right before you display your dialog box.
"
It is correct to do a m_bmp.deleteObject() ?
Any other idea ?
Thanks
|
|
|
|
|
Yes m_Bmp.DeleteObject() will do the trick.
Ali
|
|
|
|
|
Arh ! it doesn't work ! any other idea ?
|
|
|
|
|
The dialog doesn't have to be "visible" for this to work. In fact, if it is visible it won't work because all controls will have been drawn and you won't get a clean blank background to take a picture of. So I'm inclined to believe that the issue is with "layering" or ZOrder of the bitmap or something...
Here's my guess... the bitmap itself should be a static control, so that it can be "layered" at the bottom of the ZOrder. If your other controls are receiving the OnEraseBkgrnd() message BEFORE the bitmap control has been initialized then you will get a system color background. Make sure your bitmap is contained in a static control, that it's at the bottom of the ZOrder, and that it is created before all other controls.
In business, if two people always agree, one of them is unnecessary.
|
|
|
|
|
I have the same problem.
We should do the background copy right after the show of parent window and before the show our control.
But where is it?
|
|
|
|
|
I have the same problem.
We should do the background copy right after the show of parent window and before the show our control.
But where is it?
Hawk
|
|
|
|
|
Hi !
Has anybody managed to realize a Transparent Radio Button (based on CButton or special class)?.
All solutions I found, tested etc. always do not seem to care about what is written in OnEraseBkgnd... and always display an annoying block underneath the control. Very nasty when trying to put the control upon a picture.
I would appreciate any help !
On the other hand: Very good work this TransparentStatic !!!!
Best regards, Norbert
|
|
|
|
|
|
thanks your good example first,
but I could not figure out why
bitmp static or mystatic/mystatic2 can show up?
since the bitmp static and mystatic/mystatic2 overlaped each other.
so i could not understand why in OnSetText() procedure, the parent can show the bitmap .
would you give some details on this?
thanks much.
nothing nothing nothing
|
|
|
|
|
If I understand correctly, you are asking how does the system know to draw the two static text control on top of the static bitmap control.
That has to do with the ZOrder of the controls. The controls with higher ZOrder will show up on top of controls with a lower ZOrder.
This can be set in the dialog editor by setting the tab order of the controls. And you can also set this programatically using SetWindowPos, the first parameter is used to change the ZOrder of a window.
Ali
|
|
|
|
|
AliRafiee wrote:
That has to do with the ZOrder of the controls. The controls with higher ZOrder will show up on top of controls with a lower ZOrder.
after a few try, I think so, but I have not gotten the inferior from the tries.
1)
I new a project with two statics, one Labled "aaaa",
another one labled "bbbbbbbbbbbbbbbbb",
and the "aaaa" is bigger than "bbbbbbbbbbbbbbbbbbbbb" in size.
2)
in the resource file,
i changed the occurence of the two static to change their Zorders.
also I have test the WS_EX_TRANSPARENT.
the test cases and the corresponding results are:
a)
LTEXT "bbbbbbbbbbbbbbbbbbbbbbb",IDC_STATIC,42,41,98,20,0,
LTEXT "aaaa",IDC_STATIC,31,15,123,67,0
result:only "aaaa" is visible.
i think this is normal because aaaa is larger than bbbbbbbbbbbb, and aaaa is on top of bbbbbbbbbbb.
b)
LTEXT "bbbbbbbbbbbbbbbbbbbbbbb",IDC_STATIC,42,41,98,20,0,
WS_EX_TRANSPARENT
LTEXT "aaaa",IDC_STATIC,31,15,123,67
result: both are visible;
why??? MSDN states if a window with WS_EX_TRANSPARENT set,windows below it at the position where the original window was initially placed are not obscured and show through.
c)
LTEXT "bbbbbbbbbbbbbbbbbbbbbbb",IDC_STATIC,42,41,98,20,0,
WS_EX_TRANSPARENT
LTEXT "aaaa",IDC_STATIC,31,15,123,67,0,WS_EX_TRANSPARENT
result: same as a) case, only "aaaa" is visible
why????
d)
LTEXT "bbbbbbbbbbbbbbbbbbbbbbb",IDC_STATIC,42,41,98,20
LTEXT "aaaa",IDC_STATIC,31,15,123,67,0,WS_EX_TRANSPARENT
result: same as a) case, only "aaaa" visible
why???
e)
LTEXT "aaaa",IDC_STATIC,31,15,123,67,0,WS_EX_TRANSPARENT
LTEXT "bbbbbbbbbbbbbbbbbbbbbbb",IDC_STATIC,42,41,98,20
result: only "aaaa" is visible
why????
f)
LTEXT "aaaa",IDC_STATIC,31,15,123,67
LTEXT "bbbbbbbbbbbbbbbbbbbbbbb",IDC_STATIC,42,41,98,20
result:both "aaaa" and "bbbbbbbbbbbbbbbbbbbb" is visible.
this case i see why, because bbb is smaller than aaaa, and the Zorder is bbbb above aaaa.
g)
LTEXT "aaaa",IDC_STATIC,31,15,123,67,0,WS_EX_TRANSPARENT
LTEXT "bbbbbbbbbbbbbbbbbbbbbbb",IDC_STATIC,42,41,98,20,0,WS_EX_TRANSPARENT
result: both visible.
h)
LTEXT "aaaa",IDC_STATIC,31,15,123,67
LTEXT "bbbbbbbbbbbbbbbbbbbbbbb",IDC_STATIC,42,41,98,20,0,WS_EX_TRANSPARENT
result: both visible
in e,f,g,h I will think both static should be visible because bbbbb is above "aaaa" no matter whether WS_EX_TRANSPARENT is set with or not. but case e) defeated me.
would you be kind to give me more details? thanks
|
|
|
|
|
Try this. And get rid of those WS_EX_TRANSPARENTS
LTEXT "aaaa",IDC_STATIC,31,15,123,67,0
LTEXT "bbbbbbbbbbbbbbbbbbbbbbb",IDC_STATIC,42,41,98,20,0,
Like I said in the last message. The control with the higher ZOrder will show up on top of the other controls.
In the above code "aaaa" has a lower zorder than "bbbbbbb" so bbbb will show up on top of aaaaaa
in your example
LTEXT "bbbbbbbbbbbbbbbbbbbbbbb",IDC_STATIC,42,41,98,20,0,
LTEXT "aaaa",IDC_STATIC,31,15,123,67,0
aaaa has a higher zorder
Keep in mind that if you want to change the text for the larger static control ("aaaaaaaa"), then you will need to reset the text for the smaller ("bbbbbbbbbbb") one also
Ali
|
|
|
|
|
Hi,
You mentioned a possible forthcoming Transparent ListBox. Just wondering if it exists?
Thanks,
-Vin
|
|
|
|
|