How to add controls to CWnd??

I have this Cwnd dialog(this is not a CDialog). Problem with this is that it doesnt open in the resource editor so i cant the drag drop the controls on it. I want to add controls (picture /text ) etc to this. Please tell me how to make and add controls to this through code. My vc++ is really bad so please paste code generously.
It would really help if you could describe the algo to make a simple static control and place it in the Cwnd at a desired coordinate.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Add member

CStatic m_Static;

to your window class. Create it using the following code:

myStatic.m_Static(_T("my static"), WS_CHILD|WS_VISIBLE,
   CRect(10,10,150,50), this);

The good place to create child controls is OnCreate function.
swapnil001Author Commented:
thanks Alex, i guess the code above was missing the Create function, but i seemed to have got that much right. I put that in my create function and got the "my static" text, WOW!!
Is there some way that I can associate a picture with this instead of the text. Also the rectangle seems to have hid my background in the Cwnd, can I make it transparent. How do I trap a click on this control and do something about it. What about changing the fonts of the text "my text".
I m upping 50 points on this.
1. Associate a picture
Use CStatic classes style SS_BITMAP for displaying bitmap. With reference to above exaqmple by Alex, the style would become WS_CHILD|WS_VISIBLE|SS_BITMAP. Then use CStatic::SetBitmap method

2. How to make it transparent
Use CDC::SetBkMode method. Also see CWnd::OnCtlColor

3. Changing font
Use CDC::SelectStockObject method. This allows you to use fonts

I hope this helps
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

3. See CWnd::OnCtlColor function.
swapnil001Author Commented:
Actually my problem is that the Crect(that alex suggested) which I used to put the static text control is grey in color. This grey rectanlge is what i want to make transparent. My Cwnd behind is already transparent using setBkMode. Also can you shed more light on how to trap an onclick event on this control.
Hi Swapnil,
As i said check CWnd::OnCtlColor. Its available at folowing link -
There is an example that depicts making a child control transparent on this link.

In this same method override, you can also set the font using CDC::SelectStockObject method.

You simply need to over ride this method for the parent window that contains your static control as child.

For Click event on child windows refer following links -

In your case, You will need to use the link 2 given above
I hope this helps


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
swapnil001Author Commented:
thank you Alex, Santino you have been big help.
Thanks swapnil :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

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.