Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   VC++ MFC,insert editbox with a dialogbar (http://www.programmingforums.org/showthread.php?t=12706)

vangelis Mar 1st, 2007 4:52 PM

VC++ MFC,insert editbox with a dialogbar
 
hello
I have a SDI project and I want to put a DialogBar in the main window and after that to insert in its clss an editbox and a button to use the associated variabile from the editbox;it compiles fine but when i try to run the program it gives me an 'assert' error.I've created the dialogbar in the OnCreate() function of the CMainFrame class,in the following way:

if (!m_wndDlgBar.Create(this, IDR_MAINFRAME,
CBRS_ALIGN_TOP, AFX_IDW_DIALOGBAR))
{
TRACE0("Failed to create dialogbar\n");
return -1; // fail to create
}

where m_wndDlgBar is of type CDialogBar. The problem is that the associated variabile of the editbox can't be read because it never changes,it's always 0.So please give me a method to 'refresh' that variabile to it's real value.
tanx

Duck Mar 1st, 2007 6:37 PM

What do you mean - 'the associated variable of the edit box'?

Do you mean a CString variable, and if so, are you including the CString variable into the DoDataExchange function in a DDX_Text call ?

DoDataExchange can be manually invoked by calling UpdataData().

EDIT - Doesn't have to be a CString variable.

vangelis Mar 2nd, 2007 6:10 AM

'the associated variable of the edit box' I mean a member variable for the editbox.I called it 'm_text' and is of type CString.The DoDataExchange function looks like this:

void CAdresa:: DoDataExchange(CDataExchange* pDX)
{
CDialog:: DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAdresa)
DDX_Text(pDX, IDC_EDIT1, m_text);
//}}AFX_DATA_MAP
}
CAdresa is the class i've created for that DialogBar that contains the editbox and the button. UpdateData() function is actually the problem,cause when I manually invoke it, it gives me an assert error.I need a function like this but for a modeless DialogBoxes.Thanks

Duck Mar 2nd, 2007 8:54 AM

What exactly is the assert error, and where does it strike?

vangelis Mar 2nd, 2007 11:44 AM

well,the assert error strikes in my case when i try to update the member variabile from the editbox,which usually works in the modal dialogboxes,but i'm using a modeless dialogbox.Here is the function that causes that error (this function will be invoked by the function for the push button event):

CString CAdresa::getText()
{
CString str;
this->UpdateData(); // >> this causes the assert error
str=m_text; //m_text is the editbox member variable
return str;
}
I don't know why the m_text variabile is always 0 and never gets the string I input in the editbox:confused:

DaWei Mar 2nd, 2007 12:00 PM

:

  material here
      retains its formatting


Duck Mar 2nd, 2007 8:04 PM

Quote:

Originally Posted by Duck (Post 124668)
What exactly is the assert error, and where does it strike?

What I mean is what is the assert msg. When you run your program in debug mode and the program kicks up an assert error, you normally get a msg box come up giving you the assert details, then you can press Abort/Retry/Cancel, if you press Retry the program will break at the assert that caused the error. Then you can see whats wrong.

You could just keep commenting out functionality until your program works to home-in on the problem. It will be something very simple.

vangelis Mar 4th, 2007 8:33 AM

ok,this is what I get in the debugger:

BOOL CWnd::UpdateData(BOOL bSaveAndValidate)
{
ASSERT(::IsWindow(m_hWnd)); // calling UpdateData before DoModal?
............}
the UpdateData function use I have shown in my last post,but I never call DoModal function because I don't need it for a modeless dialogbar.I only need a function like UpdateData for modeless dialogbars,for getting my data member variable.
So,if I don't call the UpdateData function ,I don't get any error,the program runs well when the button is pressed,but the text typed in the editbox is never 'read'. I hope you got my idea,but I'll explain more if it's needed
tanx

Duck Mar 4th, 2007 2:54 PM

UpdateData doesn't work because the window handle isn't valid, in other words the window (dialogbar) isn't created. UpdateData can be used for Modal and Modaless dlgs.

I think you should really be allocating your CDlgBar with new, instead of having a CDlgBar member variable (try it). But otherwise I'm not sure without seeing the code.

:

        m_pwndDlgBar = new CDlgBar;

        if(!m_pwndDlgBar->Create( this, ID_MENU_DIALOG_BAR,
                CBRS_RIGHT|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_GRIPPER,
                ID_MENU_DIALOG_BAR))
        {
                TRACE("Failed to create DlgBar\n");
                return false;
        }
       
        m_pwndDlgBar->EnableDocking(CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT);
        EnableDocking(CBRS_ALIGN_LEFT|CBRS_ALIGN_RIGHT);
        DockControlBar(m_pwndDlgBar);


vangelis Mar 5th, 2007 10:09 AM

I tried your solution but it still doesn't work:( The dialogbar and other components are automatically generated by the MFC wizard,so I don't think is any problem with it. To have a clue about my problem,you should create a new SDI project using MFC wizard,and check the option 'Internet Explorer ReBars'; that will cause to have a new dialogbar resource placed on the main window, you may put an editbox to type some text in it,and a button that brings a message box with the text typed in the editbox. This is the simple thing that cause me troubles.
note that i'm using Visual c++ 6.0


All times are GMT -5. The time now is 1:59 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC