![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2006
Posts: 7
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Jun 2006
Location: England London
Posts: 72
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2006
Posts: 7
Rep Power: 0
![]() |
'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 |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Jun 2006
Location: England London
Posts: 72
Rep Power: 3
![]() |
What exactly is the assert error, and where does it strike?
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Mar 2006
Posts: 7
Rep Power: 0
![]() |
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 ![]() |
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
material here
retains its formatting
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#7 |
|
Programmer
Join Date: Jun 2006
Location: England London
Posts: 72
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Mar 2006
Posts: 7
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#9 |
|
Programmer
Join Date: Jun 2006
Location: England London
Posts: 72
Rep Power: 3
![]() |
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); |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Mar 2006
Posts: 7
Rep Power: 0
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| editbox keydown detection | Kilo | C++ | 10 | Jul 6th, 2006 12:39 PM |