![]() |
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 |
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. |
'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 |
What exactly is the assert error, and where does it strike?
|
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: |
:
material here |
Quote:
You could just keep commenting out functionality until your program works to home-in on the problem. It will be something very simple. |
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 |
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; |
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