?
Solved

How to add controls to CWnd??

Posted on 2004-12-01
8
Medium Priority
?
349 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:swapnil001
  • 3
  • 3
  • 2
8 Comments
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 150 total points
ID: 12718968
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.
0
 

Author Comment

by:swapnil001
ID: 12719490
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.
0
 
LVL 3

Expert Comment

by:Santino_k
ID: 12723227
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:AlexFM
ID: 12723658
3. See CWnd::OnCtlColor function.
0
 

Author Comment

by:swapnil001
ID: 12729276
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.
0
 
LVL 3

Accepted Solution

by:
Santino_k earned 450 total points
ID: 12733056
Hi Swapnil,
As i said check CWnd::OnCtlColor. Its available at folowing link -
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cwnd.3a3a.onctlcolor.asp
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 -
1. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_child_window_notification_message_handlers.asp
2. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_MFC_Generic_Control_Handler.asp

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

0
 

Author Comment

by:swapnil001
ID: 12768104
thank you Alex, Santino you have been big help.
0
 
LVL 3

Expert Comment

by:Santino_k
ID: 12783464
Thanks swapnil :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

807 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