Solved

Making transparent static text...

Posted on 2002-07-30
22
276 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
ID: 7187442
Check

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

Good Luck
0
 
LVL 23

Expert Comment

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

Expert Comment

by:fl0yd
ID: 7187528
>> 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 23

Expert Comment

by:Roshan Davis
ID: 7187540
>>.....::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
ID: 7187542
--------------------
.....::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
        pDC->SetBkMode(TRANSPARENT);
        return HBRUSH(GetStockObject(HOLLOW_BRUSH));
}
--------------------
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7187561
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
ID: 7187652
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
ID: 7187664
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
ID: 7187666
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
ID: 7187679
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
ID: 7187680
Sorry, I meant to write:

HBRUSH CMyDialog::OnCtlColor( ....
0
 
LVL 23

Expert Comment

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

Author Comment

by:jaeb
ID: 7187717
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
ID: 7187732
To roshmon :

At first, I thought like you.

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

Expert Comment

by:fl0yd
ID: 7187734
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
ID: 7187760
Not drawing the Frame self, it just putting Bitmap control from the resource...
Its a tricky way...
0
 

Author Comment

by:jaeb
ID: 7187775
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
ID: 7188186
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
ID: 7188418
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
ID: 7188580
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
ID: 7188593
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
ID: 7188688
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 49
Add content to output file 4 67
scoreUp challenge 14 64
Detect file exist or not 3 181
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…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 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