Making transparent static text...

Hi..

Now I'm using for transparent static text like below..

--------------------
.....::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
     CBrush m_hollow;
     m_hollow.CreateStockObject(HOLLOW_BRUSH);
     pDC->SetBkMode(TRANSPARENT);
        return HBRUSH(m_hollow);
}
--------------------

This work well..

But There is a big problem.

If There is Group box in Dialog,

Group box's text is transparent..

So Group box's text has center line..

I don't want center line in group box's text.

How can I solve this problem???
jaebAsked:
Who is Participating?
 
Roshan DavisConnect With a Mentor Commented:
Simple way is use Bitmap control from resource-
Need to use 5

---- User Info --------
|                              |
|                              |
----------------------

for 4 side

make it Rectangle Type,
Use style Sunken
And Make it Narrow.

Good Luck
0
 
Roshan DavisCommented:
Check

SetClassLong(youStaticWnd.m_hWnd, GCL_BACKGROUNDBRUSH, ::GetStockObject(NULL_BRUSH));

Good Luck
0
 
Roshan DavisCommented:
SetClassLong(yourStaticWnd.m_hWnd, GCL_BACKGROUNDBRUSH, ::GetStockObject(NULL_BRUSH));
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
fl0ydCommented:
>> This work well..

I think there is a problem. Is your m_hollow declared in ...::OnCtlColor(...)? If so, you are returning a temporary object that doesn't even exist after the function returned. So I assume it is declared as a class member. In that case, you are not checking if it has already been created. You should call m_hollow.DeleteObjet() if it already exists ( NULL != m_hollow.m_hObject ). Otherwise this will result in a resource leak.

I don't quite understand your question. Could you be more precise, please.
0
 
Roshan DavisCommented:
>>.....::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
>>{
>>    CBrush m_hollow;
>>    m_hollow.CreateStockObject(HOLLOW_BRUSH);
>>    pDC->SetBkMode(TRANSPARENT);
>>       return HBRUSH(m_hollow);
>>}

And NO neede to create brush using CreateStockObject,

You can use GetStockObject API directly

--------------------
.....::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    return HBRUSH(GetStockObject(HOLLOW_BRUSH));
}
--------------------


Good Luck
0
 
Roshan DavisCommented:
--------------------
.....::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
        pDC->SetBkMode(TRANSPARENT);
        return HBRUSH(GetStockObject(HOLLOW_BRUSH));
}
--------------------
0
 
fl0ydCommented:
I'm sorry, didn't see that the first time around. You are using StockObject's -- in that case there is no need to destroy them. In fact, you aren't even allowed to destroy them, so if you use roshmon's code you should be safe.

I still have trouble understanding exactly what your problem is. What do you mean by 'center line'?
0
 
jaebAuthor Commented:
Firstly Thank you for comments.

To roshmon :

I tried to insert code,
---
::SetClassLong(m_IsTrained.m_hWnd, GCL_HBRBACKGROUND, (LONG)::GetStockObject(NULL_BRUSH));
---

But It doesn't work.

A static text doesn't do transparent.


To fl0yd :

A center line is like below.

http://dsplab.kangwon.ac.kr/~miru/a.bmp

have a look.

0
 
Roshan DavisCommented:
Y this happening because, Windows using OPAQUE drawing for text, and for Border drawing they simply using the Rectangle API/Function.

Roshmon
0
 
fl0ydCommented:
jaeb,
    thanks for the bitmap. A picture says more than a thousand words :) To solve the problem, you should change the OnCtlColor-fxn to something like:

CSomeCtl::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor ) {
    if( IDC_STATIC_FRAME != ::GetDlgCtrlID() ) {
        pDC->SetBkMode(TRANSPARENT);
        return HBRUSH(GetStockObject(HOLLOW_BRUSH));
    }
    return CDialog::OnCtlColor( pDC, pWnd, nCtlColor );
}

and change the frame's control ID to IDC_STATIC_FRAME in the resource editor [Rightclick->Properties->General].

Hope that helps solve it.
0
 
fl0ydCommented:
Sorry, I meant to write:

HBRUSH CMyDialog::OnCtlColor( ....
0
 
Roshan DavisCommented:
Hi fl0yd,
But I suspect that, that Frame became Un-Transparent in this way...
0
 
jaebAuthor Commented:
To fl0yd :

In fact, I already tried to do like your comment.

However If I did like that,

Group box's text is not transparent.

So If my dialog is skinned, a Image is not good...

Because If group box's text is not transparent,

a group box's background is default window's dialog  background...

It's awful in skinned dialog. :)
0
 
jaebAuthor Commented:
To roshmon :

At first, I thought like you.

But I want to solve this problem programmatically...
0
 
fl0ydCommented:
That's true, it uses the dialog background color to draw over the frame and make it disappear. If you want the described behaviour, you will have to procede as described in roshmon's 4th post and make the frame-control owner-drawn, i.e. draw the frame yourself. This is a bit more complex, though.
0
 
Roshan DavisCommented:
Not drawing the Frame self, it just putting Bitmap control from the resource...
Its a tricky way...
0
 
jaebAuthor Commented:
Well, I think there is not something to solve this problem.

Maybe It's a little boring working. ^^

0
 
fl0ydCommented:
roshmon, how do you make sure to use system colors in the bitmap control? Unless I'm missing somethin here this will result in one of those apps that look ugly when run on a system other than the developer's machine.
0
 
Roshan DavisCommented:
No, I mean that

Put a bitmap control

don't set anything

Set its Type to "Rectangle"

And set its style to "Sunken"

Then it will look like a 3D line same as windows draws.

That will change for every color scheme.

Roshmon
0
 
fl0ydCommented:
Yes, but the problem remains: The heading will be an extra static text control on top of the bitmap-control. To make the heading transparent you will have the bitmap control's frame show through it again. Jaeb will have to make it transparent, otherwise he cannot put an image in the background of the dialog/window. So there isn't anything gained from that, in my opinion at least.
0
 
Roshan DavisCommented:
No on the Top

One on left side Horizontal, one on Right Horizontal

and others as you think

Thats y I mentioned 5 Rectangles....
0
 
fl0ydCommented:
I see... I'm slow at times.........

This should even be safe if the user of the application is unsing a larger font, since the dialog resource has logical coordinates rather than actual pixels. Really not too bad :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.