CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    3

    Need help getting text from edit box into client area

    I'm building an HTML Editor (MFC Appwizard) and I've created a dialog to
    insert hyperlinks.The dialog contains 2 edit boxes IDC_HYP_EDIT
    (m_hyp/member variable) andIDC_TEXT_EDIT (m_text/member variable)
    The idea here is you type the URL into the first edit box and the text
    you want displayed into the second edit box,you then push the insert button (IDOK) and this inserts the link into the HTML code. The problem is that I
    can't seem to figure out how to insert the text from the edit boxes into the
    client area (MDI Child Window)this is the code that I am using:

    void CGoldenFlashHTMLEditorView::OnOpenHyplink()
    {
    CHypLinkDialog HLdlg;

    if (HLdlg.DoModal() ==IDOK)

    {

    CString m_hyp;
    CString m_text;





    GetEditCtrl().ReplaceSel("<A HREF=");
    GetEditCtrl().ReplaceSel(m_hyp);
    GetEditCtrl().ReplaceSel(">");
    GetEditCtrl().ReplaceSel(m_text);
    GetEditCtrl().ReplaceSel("</A>");

    }
    }


    Any body know what is wrong or missing? There are no build errors it just inserts everything except the text from the edit boxes.


  2. #2
    Join Date
    Apr 1999
    Posts
    3

    Re: Need help getting text from edit box into client area

    You want to have 2 CStrings in your CHypLinkDialog class.
    CString m_hyp;
    CString m_text;

    You can do that in the class wizard and adding member variables for
    each of the 2 edit controls.

    Then again in your CHypLinkDialog dialog class
    create 2 public functions:

    CString GetHyperLink()
    CString GetLinkText()

    Those 2 functions should simply return m_hyp and m_text respectively.

    Also in CHypLinkDialog you'll need to override OnOk and do
    an UpdateData(TRUE)

    Now you can do this:

    CHypLinkDialog HLdlg;

    if (HLdlg.DoModal() ==IDOK)

    {

    CString m_hyp = HLdlg.GetHyperlink();
    CString m_text = HLdlg.GetLinkText();



  3. #3
    Join Date
    Apr 1999
    Location
    WA, USA
    Posts
    15

    Re: Need help getting text from edit box into client area

    Clearly if you see when the following line of code is executed, the dialog is already destroyed, so m_text and m_hyp are not valid.-->

    if (HLdlg.DoModal() ==IDOK)



    ///////////
    // you may have to do the following

    //in CGoldenFlashHTMLEditorView class, define following member variables.

    public:
    CString m_text;
    CString m_hyp;


    //in the dialog class, add following function.
    //include view's header in dialogs cpp in the end.
    ....
    #include "GoldenFlashHTMLEditorView.h"

    //in the onok() function() do the following
    ..
    void CHdlg::OnOK()
    {
    CGoldenFlashHTMLEditorView* pView = ( CGoldenFlashHTMLEditorView* )GetParent();
    UpdateData(TRUE);
    pView->m_text = m_text;
    pView->m_hyp = m_hyp;

    return CDialog::OnOk();
    }


    //// that should solve your problem....



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured