Solved

Making transparent static text...

Posted on 2002-07-30
22
274 Views
Last Modified: 2013-11-20
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???
0
Comment
Question by:jaeb
  • 10
  • 8
  • 4
22 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
Check

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

Good Luck
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
SetClassLong(yourStaticWnd.m_hWnd, GCL_BACKGROUNDBRUSH, ::GetStockObject(NULL_BRUSH));
0
 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
>> 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
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
>>.....::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
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
--------------------
.....::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
        pDC->SetBkMode(TRANSPARENT);
        return HBRUSH(GetStockObject(HOLLOW_BRUSH));
}
--------------------
0
 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
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
 

Author Comment

by:jaeb
Comment Utility
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
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 200 total points
Comment Utility
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
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
Y this happening because, Windows using OPAQUE drawing for text, and for Border drawing they simply using the Rectangle API/Function.

Roshmon
0
 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
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
 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
Sorry, I meant to write:

HBRUSH CMyDialog::OnCtlColor( ....
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
Hi fl0yd,
But I suspect that, that Frame became Un-Transparent in this way...
0
 

Author Comment

by:jaeb
Comment Utility
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
 

Author Comment

by:jaeb
Comment Utility
To roshmon :

At first, I thought like you.

But I want to solve this problem programmatically...
0
 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
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
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
Not drawing the Frame self, it just putting Bitmap control from the resource...
Its a tricky way...
0
 

Author Comment

by:jaeb
Comment Utility
Well, I think there is not something to solve this problem.

Maybe It's a little boring working. ^^

0
 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
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
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
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
 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
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
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
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
 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now