How to add controls to window in code (.cpp)

I'm a newbie trying to add some controls to a window in a .cpp file. 

More specifically, I created a .NET 2003 C++ MFC Application, called it TestGUI

In the function BOOL CTestGUIDlg::OnInitDialog(), I adde

	CSliderCtrl *pSlider = new CSliderCtrl()
	pSlider->Create(TBS_VERT, CRect(10,20,40,60), this, 2000)

This compiles and runs, but the slider does not show up .  What is wrong

Thanks alot!
0
anonymous (74722)
4/30/2004 11:46:04 PM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
690 Views

Similar Articles

[PageSpeed] 8

Hi Vufgar -

Do this

	CSliderCtrl *pSlider = new CSliderCtrl()
	pSlider->Create(WS_CHILD|WS_VISIBLE|TBS_VERT, CRect(10,20,40,60), this, 2000)

 - Yaso


0
anonymous (74722)
5/1/2004 1:11:01 AM
Oh yeah, I forgot to tell you.  Consider creating a member variable of your CTestGUIDlg called m_pSlider (put it in the public: section of your CTestGUIDlg definition in the CTestGUIDlg.h file) and use it instead of the way you did it.  The way you did it, pSlider will be destroyed when OnInitDialog() finishes

 - Yasoo
0
anonymous (74722)
5/1/2004 1:16:02 AM
You need to make sure its visible. You can use the style WS_VISIBLE or call
ShowWindow to do it dynamically.

--
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com


"vufgar" <anonymous@discussions.microsoft.com> wrote in message
news:F97BD923-1B0D-4BB9-95FC-2FA1806DCB52@microsoft.com...
> I'm a newbie trying to add some controls to a window in a .cpp file.
>
> More specifically, I created a .NET 2003 C++ MFC Application, called it
TestGUI.
>
> In the function BOOL CTestGUIDlg::OnInitDialog(), I added
>
> CSliderCtrl *pSlider = new CSliderCtrl();
> pSlider->Create(TBS_VERT, CRect(10,20,40,60), this, 2000);
>
> This compiles and runs, but the slider does not show up .  What is wrong?
>
> Thanks alot!


0
ajaykalra (6842)
5/1/2004 3:09:59 AM
First, why do you want to do this? (There are lots of valid answers, but many more wrong
ones). Depending on the answer, it may be that you simply missed CFormView, which is a way
of creating a collection of controls in a view. If you know the exact types (and maybe
even the exact number) of controls, it is pretty straightforward to create controls
dynamically:

First, add to your view class the appropriate variables:
	CEdit c_MyEdit;
	CScrollBar c_Colors[3]; // one each for R, G, B

then when you need to create them, just do
	c_MyEdit.Create(...parameters here...);
                   for(i = 0; i < 3; i++)
	    c_Colors[i].Create(...parameters here...);

The real problem is determining some of the parameters, such as the height and/or width of
the control. For some it isn't too hard; you can ask the system how wide the normal
control is (for example, a scrollbar might be ::GetSystemMetrics(CX_THUMB) or some similar
value wide). But remember that it is virutally ALWAYS a mistake to put any constant in for
a width or height. The actual size will depend upon the fonts used, the screen resolution,
the default system font select by the current user, etc., so if two users could log in on
the same machine the parameters would be different for each user!

My own preference is to use GetTextExtent to figure out these parameters, and even then my
preferred method is to create an invisible control on a CFormView and use its dimensions,
possibly extending the width to GetTextExtent + 2 * ::GetSystemMetrics(CX_BORDER) but
retaining the height.

Similarly, you cannot use fixed values for the coordinates of the starting and ending. On
some machines, this may result in all your controls bunched up in the upper left quadrant
of your dialog, but on another machine controls in the bottom right quadrant might even be
completely off the dialog.

One of the reasons we prefer to use CFormView (or dialog-based apps) is so we don't have
to worry about this level of detail.

So explain more about what you need; there are lots of different ways, most of them bad
(and a method that makes perfect sense in one context might actually be the Worst Possible
Way in another context)
					joe

On Fri, 30 Apr 2004 16:46:04 -0700, vufgar <anonymous@discussions.microsoft.com> wrote:

>I'm a newbie trying to add some controls to a window in a .cpp file.  
>
>More specifically, I created a .NET 2003 C++ MFC Application, called it TestGUI.
>
>In the function BOOL CTestGUIDlg::OnInitDialog(), I added
>
>	CSliderCtrl *pSlider = new CSliderCtrl();
>	pSlider->Create(TBS_VERT, CRect(10,20,40,60), this, 2000);
>
>This compiles and runs, but the slider does not show up .  What is wrong?
>
>Thanks alot!

Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
5/2/2004 10:54:41 PM
Reply:

Similar Artilces:

E-commerce add in?
I have a customer who is looking to implement RMS as well they are going to put some items in on there website. Is there a good/reccomended shopping cart site that would allow them to integrate the store and virtual store together. I have never done anything on the web side of things so I am looking for some info. Thanks. Zack Anderson ...

Sync of Stored Procedure code
Hello, [SQL2008] There are two SQLServer dev boxes that our SQL developers use - ServerA, ServerB. As of now, they are not using any Source Safe mechanism. Thus whenever developers change any stored procedure in ServerA, ServerB also needs to have the copy of that - not the other way around. This is going to be a continous process - either daily or weekly. As of now, the developers of ServerA sends a consolidated list of changed stored procedures and developers in ServerB manually extracts the script and updates ServerB. Is there any way I can automate this? I can use SSIS...

CheckBox code
Hello to everybody, I have a sheet for showing a certificate of marks. Sometimes Ithe sum of the marks need to be shown when printing the certificate, and sometime I n don't need to see the sum. I have a checkBox named chekcbox1 on the sheet. What I need is a VBA code so that when the box is checked to hide the contents of the range C34:E34 which containes the sum of the marks. PS. by "hiding" I mean "not to be seen. (maybe changing their color to white!!) Can anyone help in writing the code for me? hi Private Sub CheckBox1_Click() If CheckBox1.Value = True Then ...

How do I add <next record> field in a mail merge?
(1) Please use the large white space to ask your question. (2) What is it you're trying to do? -- JoAnn Paules MVP Microsoft [Publisher] "Phil" <Phil@discussions.microsoft.com> wrote in message news:CD0EDAB2-9926-4F49-AE99-259BD4731F08@microsoft.com... > Publisher does not support Next Record or other mail merge fields like this. You can use the Catalog Merge in Publisher 2003, or you can get Publisher to tile multiple records on one page (e.g. for business cards) by setting the page size to less than half the paper size in either direction. -- Ed Benn...

dpm 2010 hyper-v problem (Can't add hyper-v to protection group)
I have installed the RC for dpm 2010 and it is working great with the exception of 1 major problem. I cannot get a hyper-v machine added to any protection group. when I try to add it I get the following error message: One or more prerequisites for protecting this data source is missing: kb: 948465 (windows 2008 service pack 2 - which is installed) kb: 971394 - which is installed I could list the prerequisites, however I know that is not the problem. I have verified all prerequisites exist on the host machine. The only other knowledge base article I can find recommends ...

Strange problem when deserializing! (code include, long!)
Hi, I implemented a composite pattern which should be serializable to xml. After spending some time in the newsgroups, i finally managed serializing, even with utf-8 instead of utf-16, which causes ie problems. But when deserializing the xml into the object structure, the following exception is beeing thrown: There is an error in XML document (3, 701). Does anybody know how to bypass/solve this problem? Code below (forget about toXml - I tried to generate the Xml-structure on my own, but deserializing didn't work either) Thanks in advance. Thomas the Composite Pattern ist implemente...

Upgrade from Windows 95
I would like to upgrade an old pc from Windows 95 so that my 80 yr old mother can play games on it. Buying games for windows 95 compatability seems difficult, so thought the best thing to do is upgrade to a later version of windows. Can you advise me how to proceed? 1. Not an Office issue. 2. If it has Windows 95 you may find that the best you can do is upgrade to Windows 98, which may prove to be as challenging to purchase. If you look at the prices of computers now, you'll find that it won't cost an arm and a leg to buy a basic new computer. Maybe less than trying t...

The Distribution List Form
Is it possible to add some column headers to a Distribution List Form (now contains only the Full Name and the Email Address (or Email 1?). If I can add fields with the Field Chooser, it becomes much easier to use. Can it be done, short of VBA which, like the jitterbug, seems to just plumb evade me? Oops; sorry; Outlook 2003, using Exchange Server, on XP. "Jack" wrote: > Is it possible to add some column headers to a Distribution List Form (now > contains only the Full Name and the Email Address (or Email 1?). > > If I can add fields with the Field ...

Windows Update 12-07-09
FIXWindows update fails to install this is what i get-----Error Code: 0x64C Tried to FIX it myself by downloadingn the FIX tool but no avail can someone helpme -- kikocal www.futuretekonline.com It would be nice if you continued your original thread rather than start a new thread. If you are a newbee, I can understand the mistake. "kikocal" wrote: > FIXWindows update fails to install this is what i get-----Error Code: 0x64C > Tried to FIX it myself by downloadingn the FIX tool but no avail can someone > helpme > > -- > kikocal > w...

Double clik item on list box to auto populate other controls
Hi everyone I am working on a form that has a list box control of items, the functionality that I need to add is that when the user double cliks on one item of the list box the other controls that I have on my form should autopopulate. This listbox has InquiryId's which are the primary key of my table inquiries. I am fairly new coding but so far this is what I've tried: P.S.: "ViewInquiries" is the name of my listbox on the form, and the "AccessNSUnionInquiries" that I am using on the Select Stament is a query. Private Sub ViewInquiries_DblClick(Cancel As In...

Flashing control
I want to build a command button on the form that flashes when clicked. How could i do it ? -- Message posted via http://www.accessmonster.com ...

Add System Date to Chart
Hi All, Is there any way of display the system date, either within the title of the chart, or anywhere else? Cheers. Bill. Hi, You could link the chart title to a cell which contains the system data. Once you have added the chart title to link it to a cell enter the full cell address in the formula bar. =Sheet1!$A$1 http://www.andypope.info/tips/tip001.htm Cheers Andy -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info "Bill" <bill@bill.com> wrote in message news:%23onkuRxFIHA.4584@TK2MSFTNGP03.phx.gbl... > Hi All, > > Is there any way of displa...

Add gridlines (NOT print or display) for Excel 2007
I know how to add gridlines for Excel 2003. However, someone in their infinite wisdom (yeah?!) decided to make Office 2007 products difficult to use, hard to find icons, unable to set up personal toolbars with favorite icons, etc. I can't find how to ADD gridlines. Through a search of Help, they show you how to display/hide/print/not print, etc. but NOT how to add them. I copied part of a spreadsheet from a 2003 Excel file. BUT, when I add new rows, none of the new rows have gridlines. I can't find how to add thjem. Hi Press the Round Office button>Excel Options>Adv...

Windows Media Player Protection Issue ??
Hello; I'm new to this, so please bear with me. 1) Over a year ago, I copied 4 of my own CDs to my laptop as audio files *. wma 2) Everything worked fine with Windows Media Player 3) Last week I updated to Windows Media Player 11 4) Now to Play any of the audio files: ...a. internet connection is required! ...b. MS Windows Media Technologies message appears: "To play the file on this computer, you must download a license (a process known as "license migration"! ...c. click "Download License" ...d. by clicking, two messages appear: ......1st ms...

to create a T like 3 splitter window
I tried to create a T like 3 splitter window, 2 child windows on top, one at bottom, with the following codes, but got exception, what's wrong with that? m_wndSplitter.CreateStatic(this, 2, 1); //In which windows to put the view. m_wndSplitter.CreateView(1, 0, RUNTIME_CLASS(CUsbRevealerView), CSize(100, 100), pContext); m_wndSplitterNext.CreateStatic(&m_wndSplitter, 1, 2, WS_CHILD | WS_VISIBLE | WS_BORDER, m_wndSplitter.IdFromRowCol(1, 0)); m_wndSplitterNext.CreateView(0,0,RUNTIME_CLASS(CUsbRevealerView),CSize(100, 100),pContext); m_wndSplitterNext.CreateView(0,1,RUNTIME_CLA...

forms control in a class
Hi all, I have a vb.net class with this in it: Public Sub SetValues(ByVal obj As Object) DirectCast(obj, ComboBox).Items.Add("Value1") DirectCast(obj, ComboBox).Items.Add("Value2") End Sub Problem: ComboBox is unrecognized becuase this is a class library, not a form. So I add: Imports System.Windows.Forms and I get an error - Warning 1 Namespace or type specified in the Imports 'System.Windows.Forms' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least o...

DPM 2010 and Symantec Storage Foundation for Windows
Hello! Does anyone know if DPM 2010 supports hyper-v VM's which is stored (both ..vhd and machine information) on Symantec Storage Foundation for Windows (Veritas Volume Manager) ? This is not supported by DPM 2007. Hi Magnar, Thanks for the feedback. We are looking into this issue and will provide an update on whether this scenario is supported in DPM 2010. -- Gaurav Gupta | Program Manager | DPM This posting is provided “AS IS” with no warranties, and confers no rights "Magnar" <Magnar@discussions.microsoft.com> wrote in message news:1BF4DE87-66EB-...

"Find" window not opening in word 2007
I have an issue with the "find" window not opening. It seems to be only affecting one computer on xp. As the find function works on that document if I edit on another PC. I have already tried deleting the normal.dotm file. It worked once then back to same issue. When I select ctrl + f or actually click on the find button on the home tab, word seems to gray out as if the find window is open somewhere, but I can find it. This is completely frustrating. Any help would be greatly appreciated. If you start Word in Safe mode, then does it work? To start in Safe mode, hold C...

Marketing Add Ons
Are there any good marketing add ons out yet? We're checking out Britemoon and IBIS Nurture Marketing... What are you trying to do? >-----Original Message----- >Are there any good marketing add ons out yet? > > >. > ...

MS Forms 2.0 Image Control Fails
A Forms 2.0 Image control bitmap that appears in the MFC dialog editor does not display when the application runs. This application was moved from VS 6 to VS 2003. The property settings and ID are the same in the VS 2003 version and the VS 6 version. The VS 6 version works fine. I also have a new dialog in VS2003 in which the control works correctly. All settings in this dialog have been checked against the non-working dialog. The control has been removed and reinserted in the non-working dialog. Why would it appear in the dialog editor and not when run? The control is fm20.dl...

Outlook Mail pre-view window bigger..Calendar disappeared..Help
I'm new to Microsoft outlook and like it very much! On my outlook mail home screen I had four columns.. column 3 had a mail preview window and column 4 had a small one-month calendar. I thought I was hitting a right arrow on the calendar to change my calendar from August to September but instead my calendar disappeared and my mail preview window got bigger to use the space vacated by my calendar. Yikes! How do I get the calendar back? Outlook 2007? The right pane is called the To-Do Bar. To make it bigger again simply press the "<<" sign at the top of it. Other wa...

Custom class exists to add, update, delete and select nodes in record style XML file???
I am considering writing a Class that Selects, Adds, Updates and Deletes Nodes in an XML File but do not what to reinvent the wheel. (See XML file below) That data format would emulate records in a Database Table with a Primary Key for each Record (see xml sample below) and a flat file structure. I would use a class to manipulate this type of data structure extensivly if I had one. Does anyone know of such an animal? Thanks In Advance Earl <?xml version="1.0"?> <ROOT NextPk="3"> <RECORD PkNum="1"> <NAME>Mark</NAME> <...

Modeless dialog + crystal report viewer control
when i add a crystal report 9.0 viewer control (Active X control) into the dialog. And then use "CreateIndierect()" to create the modeless dialog. The viewer cannot dislplay successfully. The screen only display the blank dialog. However, I can display the active X control of the viewer if I use DoModal() to create the dialog. So, how can I also display the viewer together with the dialog?? Thx ...

Popup menus and windows move behind app window in XP
All first-level popup windows, whether they be right-click menus, "What's this" context popups, drop-down selection boxes, are disappearing behind the application window or dialog box being displayed a second or two after being displayed. This behavior is limited to Windows XP and never happens when out product is used with Windows 2000. Sometimes the windows do not disappear. When they do, it is only the portion of the window that overlays our application window or a dialog being displaying. It is as if the application window or dialog is being redrawn and the order o...

automatically add sender to contacts from a message, and associate with category
I want to be able to automatically save the contact details from an email message in my inbox of outlook 2007, and associate the contact entry with specific categories. I envisage this being a macro that I just click on once I either have the message selected or actually open; i click the macro button and outlook automatically puts the sender (via 'add to outlook contacts' or equivalent) into the contacts list and applies a category. Maybe more than one macro each for a different category. Maybe it would work with more than one selected email message item. If someone could write th...