473,569 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems adding member variables to controls

13 New Member
I've just started working through Sams publishing's "Teach yourself Visual C++ 4 in 21 days", using VC++ version 4.0 on a windows xp machine. My problem occurs when I attempt to add member variables to controls that I have added to a dialog box through the Class Wizard, Member Variables tab. I can only see the Control IDs of the two Push Button Controls that are initially created by the MFC App Wizard - Ok and Cancel, despite having deleted these two controls and added three new Push Button Controls, two Check Box Controls and an Edit Box Control. Is there something that I have to do to refresh the list of Control IDs in the Member Variables tab, as currently I cannot assign variables to any controls?
Thank you very much,
radders
Jan 10 '07 #1
11 8569
willakawill
1,646 Top Contributor
I've just started working through Sams publishing's "Teach yourself Visual C++ 4 in 21 days", using VC++ version 4.0 on a windows xp machine. My problem occurs when I attempt to add member variables to controls that I have added to a dialog box through the Class Wizard, Member Variables tab. I can only see the Control IDs of the two Push Button Controls that are initially created by the MFC App Wizard - Ok and Cancel, despite having deleted these two controls and added three new Push Button Controls, two Check Box Controls and an Edit Box Control. Is there something that I have to do to refresh the list of Control IDs in the Member Variables tab, as currently I cannot assign variables to any controls?
Thank you very much,
radders
Hi are you adding control variables via the dialog box from right clicking your dialog box class in the class view pane?
Jan 10 '07 #2
radders
13 New Member
Hi are you adding control variables via the dialog box from right clicking your dialog box class in the class view pane?
Hi willakawill
No, I hadn't been adding the control variables that way.The way it was described in the manual was to add a new variable to the Control ID of the control with which I am trying to use it, through the Class Wizard

I have now added a variable named: m_TestEdit of type: CString to my dialogue box class, but it still doesn't show up in the Member Variables tab of the Class Wizard, so how do I go about attaching the newly added variable (m_TestEdit) to the edit box I created with ID: IDC_TEST_EDIT so that I can control what is read from/written to the edit box with the variable m_TestEdit?

Thanks, Radders
Jan 10 '07 #3
willakawill
1,646 Top Contributor
Hi willakawill
No, I hadn't been adding the control variables that way.The way it was described in the manual was to add a new variable to the Control ID of the control with which I am trying to use it, through the Class Wizard

I have now added a variable named: m_TestEdit of type: CString to my dialogue box class, but it still doesn't show up in the Member Variables tab of the Class Wizard, so how do I go about attaching the newly added variable (m_TestEdit) to the edit box I created with ID: IDC_TEST_EDIT so that I can control what is read from/written to the edit box with the variable m_TestEdit?

Thanks, Radders
Did you add it as a control variable?
Jan 10 '07 #4
radders
13 New Member
I right clicked on the class name and chose: Add Variable. This produced a window where I had to specify Variable Type and Variable Declaration, which I set as CString and m_TestEdit respectively. Could you please explain to me how I would specify this variable as a control variable?
Thanks, Radders
Jan 10 '07 #5
willakawill
1,646 Top Contributor
I right clicked on the class name and chose: Add Variable. This produced a window where I had to specify Variable Type and Variable Declaration, which I set as CString and m_TestEdit respectively. Could you please explain to me how I would specify this variable as a control variable?
Thanks, Radders
Oops. Just read your first post again. You are using version 4. OK have a look in your dialog cpp for this function and write in your variables here along with the names of your controls.

Expand|Select|Wrap|Line Numbers
  1. void CmymfcDlg::DoDataExchange(CDataExchange* pDX)
  2. {
  3.     CDialog::DoDataExchange(pDX);
  4.     DDX_Control(pDX, lblMessage, c_Message);
  5.     DDX_Control(pDX, txtLeftItem, c_LeftItem);
  6.     DDX_Control(pDX, txtRightItem, c_RightItem);
  7.     DDX_Control(pDX, txtStartSection, c_StartSection);
  8.     DDX_Control(pDX, txtEndSection, c_EndSection);
  9.     DDX_Control(pDX, txtDenominator, c_Denominator);
  10.     DDX_Control(pDX, txtDirectoryOut, c_DirectoryOut);
  11.     DDX_Control(pDX, txtDirectoryIn, c_DirectoryIn);
  12.     DDX_Control(pDX, txtMinCoef, c_MinCoef);
  13.     DDX_Control(pDX, lblTestRig, c_Testrig);
  14. }
Jan 10 '07 #6
radders
13 New Member
Oops. Just read your first post again. You are using version 4. OK have a look in your dialog cpp for this function and write in your variables here along with the names of your controls.

Expand|Select|Wrap|Line Numbers
  1. void CmymfcDlg::DoDataExchange(CDataExchange* pDX)
  2. {
  3.     CDialog::DoDataExchange(pDX);
  4.     DDX_Control(pDX, lblMessage, c_Message);
  5.     DDX_Control(pDX, txtLeftItem, c_LeftItem);
  6.     DDX_Control(pDX, txtRightItem, c_RightItem);
  7.     DDX_Control(pDX, txtStartSection, c_StartSection);
  8.     DDX_Control(pDX, txtEndSection, c_EndSection);
  9.     DDX_Control(pDX, txtDenominator, c_Denominator);
  10.     DDX_Control(pDX, txtDirectoryOut, c_DirectoryOut);
  11.     DDX_Control(pDX, txtDirectoryIn, c_DirectoryIn);
  12.     DDX_Control(pDX, txtMinCoef, c_MinCoef);
  13.     DDX_Control(pDX, lblTestRig, c_Testrig);
  14. }
Hi again willakawill!
That has helped a huge amount as I have now registered the necessary variables to the controls. I've also defined the variables by right-clicking on the class name and adding the variables, one as CString and two as BOOL. However when I try to build the programme I get the following error messages:

...error 2664: 'DDX Control' : Cannot convert parameter 3 from 'class CString' to class 'CWnd &' (new behavior; please see help)
Could you please point out to me where I'm going wrong? Thanks, Radders
Jan 10 '07 #7
radders
13 New Member
Hi again willakawill!
That has helped a huge amount as I have now registered the necessary variables to the controls. I've also defined the variables by right-clicking on the class name and adding the variables, one as CString and two as BOOL. However when I try to build the programme I get the following error messages:

...error 2664: 'DDX Control' : Cannot convert parameter 3 from 'class CString' to class 'CWnd &' (new behavior; please see help)
Could you please point out to me where I'm going wrong? Thanks, Radders
I ran out of time to edit this, so had to post again. I've found that the cause of my problem was I had to insert "(CWnd&)" before the variable name for the DDX_Controls to parse. Insertion of this has solved the problem, but I don't quite understand how it works - could someone please explain to me why it will only work with (CWnd&) in front of the name - I realise that the variables are of a different type otherwise, but why does that give an error message?
TIA, Radders
Jan 10 '07 #8
radders
13 New Member
Hi again willakawill!
However when I try to build the programme I get the following error messages:

...error 2664: 'DDX Control' : Cannot convert parameter 3 from 'class CString' to class 'CWnd &' (new behavior; please see help)
Could you please point out to me where I'm going wrong? Thanks, Radders
Having now found more time to continue writing this programme I find that the variables initially defined do not function as they should do - ie the code written using them does nothing, but the programme builds. I presume this is caused by my 'bodge' of (CWnd&) to remove the parsing error described above. I guess that this in fact converts them from type BOOL/CString to CWnd& and hence they do not function as I had hoped they would. This bodge also prevents the ClassWizard from working as it then gives a parsing error for the lines where the DDX Controls are defined.
So, how do I get the programme to build, without changing the variable type?
Thanks, Radders
Jan 12 '07 #9
willakawill
1,646 Top Contributor
Having now found more time to continue writing this programme I find that the variables initially defined do not function as they should do - ie the code written using them does nothing, but the programme builds. I presume this is caused by my 'bodge' of (CWnd&) to remove the parsing error described above. I guess that this in fact converts them from type BOOL/CString to CWnd& and hence they do not function as I had hoped they would. This bodge also prevents the ClassWizard from working as it then gives a parsing error for the lines where the DDX Controls are defined.
So, how do I get the programme to build, without changing the variable type?
Thanks, Radders
These are not string variables. They are control variables so your declaration of them in your class.h file should be CEdit not string. You can then write the ddx code as I showed without the extra stuff. Then you can use them this way.

Expand|Select|Wrap|Line Numbers
  1. CString stTemp;
  2. long InputValue;
  3. char message[20];
  4.  
  5. m_MyEditBox.GetWindowTextA(stTemp);
  6. InputValue = atol(stTemp);
  7. sprintf_s(message, 20, "Hello World");
  8. mMyEditBox.SetWindowTextA(message);
  9. // and so on...
Jan 12 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
3488
by: William Payne | last post by:
Hello, I was under the impression that if I made a class Foo and if I didn't specify a copy constructor I would get one anyway that simply assigns the member variables (and that won't work for dynamically allocated member variables). Anyway, I have a program that segfaults without a copy constructor but if I add an empty one, the segfault is...
5
5912
by: surrealtrauma | last post by:
the requirement is : Create a class called Rational (rational.h) for performing arithmetic with fractions. Write a program to test your class. Use Integer variables to represent the private data of the class – the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it is declared....
0
1915
by: Chris Millar | last post by:
I have a user control that i wish to extend to change the date when the user selects the numeric up down button. The code explains itself, hope someone can help. any ideas appreaciated.. Chris. code :
2
3163
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the problems that I have encountered to date and the solutions (if any) that I found....
2
2572
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a good while and I'm getting really frustrated now! My problem is this - my custom controls periodically disappear from my
3
4894
by: dpomt | last post by:
I am facing some issues with the webforms DefaultButton functionality: #1 One text box ==> hitting enter works in IE but not in Firefox (1.5) #2 One text box and req. field validator ==> problem in IE #3 two text boxes ==> not even a postbak in Firefox. The three problems I have could be simply reproduced creating a new webform and...
60
5003
by: Dave | last post by:
I'm never quite sure whether to use "this." or not when referring to fields or properties in the same class. It obviously works just fine without it but sometimes I wonder if using this. consistently may make the code easier to understand for someone else, etc. Using "this." makes it immediately clear, for example, that the variable being...
114
7786
by: Jonathan Wood | last post by:
I was just wondering what naming convention most of you use for class variables. Underscore, "m_" prefix, camel case, capitalized, etc? Has one style emerged as the most popular? Thanks for any comments. --
2
4375
by: David | last post by:
Dear All I'm trying to use a multi-select listbox as criteria to either add new record or edit the current record of the destiantation table with each row selected in the box. This works fine for adding a new record but once records exist in the destination table, the routine seems to overwrite the first highlighted record in the...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.