New to Forms/MFC. Unsure where to place the code.

This is a discussion on New to Forms/MFC. Unsure where to place the code. within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I am trying to create a standard Windows Form which comprises of the following: Button1 Button2 TextBox1 TextBox2 When ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Location
    U.K.
    Posts
    148

    New to Forms/MFC. Unsure where to place the code.

    Hi,

    I am trying to create a standard Windows Form which comprises of the following:

    Button1
    Button2
    TextBox1
    TextBox2

    When the user clicks the Option1 button, I am trying to display some text held in a CString variable.

    Using Visual Studio 2005, I have created the procedures for the buttons and given each TextBox one Member Variable each.

    I think however I am placing some of the code in the wrong location, as when I click on Button1, the text I want displayed in the first TextBox actually becomes the label of the Button it's self.

    Code:
    void CSDI2Prac4Dlg::OnBnClickedButton1()
    {
    
    	CString InText;
    	CString OutText;
    	CString ExtText;
    
    		
    	InText = "Some text";
    	OutText = "";
    	ExtText = " Extended";
    	OutText.GetBufferSetLength(2000);
    
    	opt1.SetWindowText ( InText );
    	opt2.SetWindowText ( OutText );
    
    	InText = InText + ExtText;
    
    	//m_EDIT3.SetWindowText ( InText );
    	//OnOK();
    
    }
    
    void CSDI2Prac4Dlg::OnBnClickedButton2()
    {
    
    }
    
    void CSDI2Prac4Dlg::OnEnChangeEdit1()
    {
    
    }
    
    void CSDI2Prac4Dlg::OnEnChangeEdit2()
    {
    
    }
    I am unsure how to have the "Some text" string appear in the first textbox, when the user presses Button1.

    Any advice is most appreciated.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    mostly there....


    Code:
    opt1.SetWindowText ( InText );
    
     should be 
    
    m_Edit1.SetWindowText ( InText );
    
    or use a pointer and the controls resource ID
    
    CEdit  *pEdit=NULL;
    
    pEdit=(CEdot*)GetDlgItem(IDC_EDIT1);
    if(pEdit && pEdit->GetSafeHwnd())
    {
           pEdit->SetWindowText(InText):
    }
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Explain this C code in english
    By soadlink in forum C Programming
    Replies: 16
    Last Post: 08-31-2006, 12:48 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 03:28 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Stuck Between a Rock and a Hard place
    By kwigibo in forum C++ Programming
    Replies: 2
    Last Post: 05-14-2002, 05:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21