Dynamically creating controls

I was wondering how I can dynamically create a given control in my MFC app. I 
am using Visual C++ .NET 2003 and I would like the control created to be put 
into some sort of a resizable array such as a vector.  I have looked around 
the internet and I have yet to see any articles regarding this topic.  Does 
anybody have any ideas as far as how to dynamically create controls in MFC?

Sincerely,

James Simpson
0
12/20/2004 4:29:01 AM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
355 Views

Similar Articles

[PageSpeed] 25

It really depends on the control as to the where it is handled. I had to use 
OnNotify() to interpet tab Clicks.
This example just shows how to dynamically add a scroll bar to a view.

Add the following to the View.h file:
private:
  CScrollbar VertScrollbar;

Add the following to OnCreate()
(The Controls can be create and deleted elsewhere. I did it in OnCreate is 
because they are there through life of program)
VERIFY(m_sbHorzZoom.Create(
      SBS_HORZ | SBS_BOTTOMALIGN | WS_CHILD | WS_BORDER, Rect, this, 
ID_CVIEWWAV_SB_HORZ_ZOOM));
 m_sbHorzZoom.SetScrollRange(0, 32767);
 m_sbHorzZoom.ShowScrollBar();
 m_sbHorzZoom.EnableScrollBar();


Add #define ID_CVIEWWAV_SB_HORZ_ZOOM WMAPP + 1 to the stdfax.h file

Add the following to OnSize().
(When the window moves, the control has to move to, so this is where it 
happens)
 m_sbVertZoom.MoveWindow(
  Rect.right - SCROLLBAR_WIDTH,
  Rect.top + TABCTRL_HEIGHT,
  SCROLLBAR_WIDTH,
  Rect.Height() - TABCTRL_HEIGHT - (2*SCROLLBAR_WIDTH),
  TRUE
 );

Then, you would add the Vert and Horz Scrollbar Handlers.
OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)

Well, that should get you started.  Just Create it, Move it and Handle it.

Good Luck,
-- 
Christopher J. Holland [!MVP]
http://www.mvps.org/vcfaq/
http://www.codeguru.com
http://www.codeproject.com
http://www.naughter.com/
http://support.microsoft.com/default.aspx
http://msdn.microsoft.com/howto/
http://msdn.microsoft.com/library/
www.flounder.com/mvp_tips.htm

"James Simpson" <JamesSimpson@discussions.microsoft.com> wrote in message 
news:119D6396-B818-4882-89F5-686FFB6FF232@microsoft.com...
>I was wondering how I can dynamically create a given control in my MFC app. 
>I
> am using Visual C++ .NET 2003 and I would like the control created to be 
> put
> into some sort of a resizable array such as a vector.  I have looked 
> around
> the internet and I have yet to see any articles regarding this topic. 
> Does
> anybody have any ideas as far as how to dynamically create controls in 
> MFC?
>
> Sincerely,
>
> James Simpson 


0
msnews (126)
12/20/2004 8:46:31 AM
Reply:

Similar Artilces:

Problem with transform XSL that incude asp.net controls
I have an xsl file that transforms an XML document and outputs it to my web page. The xsl file is also creating LinkButtons and they appear on the page. However, I cannot get the linkbutton click event to fire for these controls. My page load event looks like the following: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim sbrAssemblies As New StringBuilder sbrAssemblies.Append("<?xml version='1.0' encoding='utf-8'?>") sbrAssemblies.Append("<assemblies>") Dim dtAs...

Can't create hyperlink
Using Office 2000, publisher, my hyperlink option in "insert" is faded. Button on left column also is faded. no option to hyperlink. Can anyone help me with this? revmel <revmel@discussions.microsoft.com> was very recently heard to utter: > Using Office 2000, publisher, my hyperlink option in "insert" is > faded. Button on left column also is faded. no option to hyperlink. You have to convert your publication to a web publication before the option to insert a hyperlink becomes available. -- Ed Bennett - MVP Microsoft Publisher ...

Unable to create a view with attributes from more objects
I have experienced an error trying to create a custom view or a saved filtered view using attributes from more than 1 object (in my case I need to have attributes from 3 objects). It is of course possible to creat this kind of view, but when I try to show the view I get a CRM popus error message. Any experiences with this phenomenae? Thanks Robert Robert, We've seen errors when selecting a money field from a related entity if the currency is not also included as an attribute to be included in the view you're creating. Were you, by chance, trying to include a money field? Mi...

Creating new attribute with Lookup as data type
I need to create a new attribute with Lookup as data type in the Account entity just like system Parent Account (parentaccountid) attribute in account entity, it would be great if I can just uplicate this system attribute. Since the new attribute (Dealer of Record) will be pointing to the same entity as parentaccountid, what is the best way go about doing this? Thanks. To achieve this you will have to create a new entity which will contain attributes you require and then you will have to set a many to one relationship between Account and your entity. After creating the entity y...

Past in Outlook creates wastebasket erro
Greetings, Sometimes when I copy and paste something into my Outlook e-mail, I get an icon that looks like a wastebasket with an error pointing upwards with an orange circle that contains an envelope with an exclamation point on it. Does anyone know what this means and how I can prevent it from happening? Thanks! coolblueshot@gmail.com <coolblueshot@gmail.com> wrote: > Sometimes when I copy and paste something into my Outlook e-mail, I > get an icon that looks like a wastebasket with an error pointing > upwards with an orange circle that contains an envelope with an > ex...

Programatically create and display new records on bound form
I have a form/subform bound to 2 tables in a 1-to-many relationship. On the main form, the user is prompted to enter (among other things) the start and end dates for a course, as well as the day of the week that the individual sessions take place. Using this information, I would like to generate a record for every date within the date range that falls on the specified day of the week and display the new records in the subform. Being a novice VBA programmer, most of this is a problem to work out (e.g. calculating the dates), but the main one is how to actually create the records. Thanks in ...

Lebans Tooltip Control : Listbox font size
I am using the Lebans '97 tooltip control for adding some richer functionality to a form on my Access database. However, I appear to have a problem. My endusers tend not have particuarly good eyesight and so I have increased the default size of the list items in the listbox for which I want the Tooltips to appear. This causes the tooltip code lose its relative row position and so its displays tooltip text for another row. The longer the list - the larger the error in the no. rows the text is offset.... apart from reverting to the default font size - is there a fix for this? Thank y...

How can I create a combination stacked & cluster column chart?
I am trying to create a clustered column chart. However unlike a standard clustered column chart I want one (and only one) of the columns to be a stacked column made up of two data sources. The other two columns would be standard columns made up from just one data source. Is this possible? You can get this effect through staggering of the data, as described in the links on this page: http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services - Tutorials and Custom Solutions - http://PeltierTech.com/ 2006 Excel...

Trying to create an RSS feed, but XML page doesn't format in IE
I'm trying to learn how to create an RSS feed to distribute podcasts. After encountering a problem, for testing purposes, I cut the entire source code from http://www.democracynow.org/podcast.xml into a text file. Here's the rub, underlying the problem I was experiencing with my earlier attempt: When http://www.democracynow.org/podcast.xml is displayed in the browser by branching to it , it displays a nice, formatted display that is the familiar 'feedy' looking page. When 'same' code pasted into an empty text file is opened in IE, it displays...

create eventhandler
Hi, I have a windows applicaiton with a datagridview on a form. In my code I can call the ClearSelection method of the datagridview to remove the selection. How can I create an event that is fired whenever this method is done so I can do additional actions? rg, Eric There is no event you have to trust that it is done, like there is no event which fires when you have done this. dim a = 1+1 Be aware that this one above like yours go so fast, that you won't see it. The painting on screen can take some more time. "Eric" <Eric@discussions.micr...

Creating ToolBar at runtime
hai I am Working in VC++ and I need to create Toolbars at Run Time but I have no Idea how to Start and where to look into could any one help me -praveen When you create a doc/view application using the wizard, it creates the code which creates a toolbar at run time. I am not sure if thats what you are asking. If you mean that you need to provide the bitmaps and button info at run time, you can do that as well. Take a look at CToolBar class. It has bunch of methods including setting all properties at run time, including image lists, button info etc. -- Ajay Kalra [MVP - VC++] ajaykalra...

How to make tooltips on non-Controls ?
Would it be possible to use the existing Tooltip functionality on non-Control objects? Say I have several boxes drawn across the background for a Panel, and if the user hovers the mouse over one of the shapes a certain tooltip specific to that shape shows up, and likewise for each shape. If I cannot use Tooltip this way, any suggestions on how I can accomplish this task? I can find the right shape with mouse coord hit testing in Mouse Hover but I somehow need to incorporate a timer in there which resets every time the mouse moves - this sounds like something that would be...

How Do I Create This In Excel?
How Do I Create This In Excel? A "speedometer" type chart that has a goal, and current status. Such as tracking days between injuries and a goal of the longest period between injuries. Is there a template? -- jmendio Use a bullet graph instead. These were developed by Stephen Few and described in a couple of his books (Information Dashboard Design and Show Me the Numbers). Charley Kyd discusses them and shows how to build them in Excel: http://www.exceluser.com/explore/bullet.htm - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions Peltier Technical...

2007 Create Style Set
Hi, I am having difficulty figuring out how to create a new style set in 2007. I have migrated multiple styles from 2003 to 2007 and I believe what I need to do is create a custom style set to use them in the style gallery. I can't seem to find enough instructions to get started. Do I need to create a special template first? They are currently in normal.dot and normal.dotm. I also wanted to have them display in the Style Pane (or dialog box) without having any other styles show up. I also don't want to see any minor style changes show up (e.g., if I apply italics to ...

Controlling HTML email
I start an HTML email typing in Arial with a left margin close to the left edge of the window. Then I go to a Word doc and copy and paste a section of the doc into the HTML email. The text comes in like in the Word doc with Times New Roman and Body Text 3 left indented to the right. I then want to go back to the Arial text and with the non indented margin. How do I do that? SteveK "SteveK" <sk-reeemovethis@dolby-reeemovethis.com> wrote in message news:OOKZl35DFHA.1836@tk2msftngp13.phx.gbl... >I start an HTML email typing in Arial with a left margin close to the >...

MFC List Control Column Icon help
Hi, I am trying to get a icon into my list control. I have but it als includes an icon beside every item in the list control. I just want the heade to h ave it. Below is the code. Could you tell me how to remove the ico from b eing beside each item in the list control, and just in the colum header at the top? Thx SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon CImageList *ImgHeaders = new CImageList; ImgHeaders->Create(16, 16, ILC_MASK, 1, 1); ImgHeaders->Add(AfxGetApp()->LoadIcon(IDI_UP)); ImgHeaders->Add(AfxGetApp()->LoadIcon...

Dynamic Charts
I have an array of DEM (Digital Elevation Map) data. Rows are Latitudes, Columns Longitudes. I have created a graph (Area) that plots the elevation across Longitudes (Column) for a given range of Latitude (Lines). Nice graph! I would like the plot to update automatically when I glide the cursor down the first column (Latitude), i.e. when I move the cursor down the range. Cursor movement would be by KBoard not mouse. Thanks, Pierre Pierre - I did this as a dynamic chart, with a worksheet event procedure to update the ranges when the activecell changed. I assumed the data was in a rectangu...

how to create a "link" in word 2007 without using "hyperlink"?
can any one advice, how to create a "link" in word 2007 without using "hyperlink" and "object add" options?. For example : Let consider there are 3 forms(form1,form2 and form3).I want to embedded "form 2" and "form 3" inside the "form1" document, in which by clicking on form2 or form3 those forms should open up. Plz reply to this question as far as possible.Looking forward to hear from u. Thanks and regards Rakhi Click on the Insert Tab and then on Object and then go to the Create from File tab and browse to the f...

Dynamic Excel Worksheet on our Portal for Non-CRM Users to View
I wish to share certain information out of CRM with users who are not CRM users. I know I can create a spreadsheet and post the spreadsheet, but then we have to manually update the spreadsheet on a regular basis for this to have any value. The concept I came up with was to create a dynamic worksheet in Excel, format the view the way I want it, and upload it to the portal. That works great for anyone who is a CRM user, but doesn't work at all for those who are not CRM users. I'm not sure if I have a CRM issue or an Excel issue. How can I create a worksheet that displays the ...

How can I create a soccer chart with automatic updates in Excel
I would like to know how to create a soccer chart in Excel that updates automaically when I enter results, if it's not a difficult task. ...

Looking for a charting control
Hi all, I am looking for a professional quality charting control. Current requirements are Bar charts and Pie Charts, but this might change in the near feature to include more complex data types using Line charts (smooth and normal), area charts (stacked), point or radar charts. I haven't been able to find a good one yet. I found this put the documentation is not adequite. http://www.nevron.com/Charting.aspx?nav=ChartNav&content=Chart Any suggestions? AliR. I've used a system called ProEssentials5. I built a thin C++ wrapper around their types and I've done a number of g...

creating custom buttons
hi there I am trying to create a custom button which acts like scanning in item. I would like to use the custom button add set items to transaction. -- Cheers Topi You can use the following: Style: Internal Command Command: PerformAddItem 0, ILC, 1, 0, 0, 0, 0 The format of the command has to be exactly as above, all you have to do is substitute the ILC for whatever ItemLookupCode and the 1 for the Quantity. The other values are as follows. 1st value = ItemID 2nd value = ILC 3rd value = Quantity to add 4th value = Override Price 0 = False, 1 = True 5th value = Price 6th value = Overri...

controlling chart location
I have a process for making some charts, which I then place into another sheet using 'activechart.location 2, sheetname'. Is there a way to control where on the new sheet this ends up? If I send several charts this way, they end up in the same location, so that I have to drag them over to see them all. Here is the charting portion of my code: ActiveSheet.Shapes.AddChart(xlLine, 250, 15, 400, 200).Select With ActiveChart .SetSourceData Source:=primeTLAhistorng .SeriesCollection(1).Name = Cells(2, 26) ...

Drag'n'Drop from an ActixeX control.
My app, has a form view with a bunch of controls on it, one of which is a CListCtrl. I also have a custom ActiveX control on it, which is just a simple dialog with some control on it, one of which is also a CListCtrl. Now I want to Drag'n'Drop items from one to the other (List ctrl on ActiveX ctrl -> List ctrl on form view is my main priority and first concern). How on earth would I go about this? I can see the following problems:- Passing an NM_LISTVIEW object from the ActiveX control to the client app. What VTS_*** values should I use etc? Then the list control in the Act...

How can I create a task that calls for effort per day
I have a task with a team of 6 people. each has to devote 30 minutes of effort per day to review project materials ofver a 3 week period. How do I set this up? I'd expect to see a string of 30 minute events over the period in the Gantt view. TIA Strider -- Here's one way to handle this: 1. In the Gantt Chart view, enter the task name and then set the Duration to 15d (the 3-week window you mention). 2. Click Window - Split to apply the Task Entry view. 3. In the bottom pane (Task Form), click the Task Type pick list, choose the Fixed Duration item, and then...