Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 1st, 2007, 4:52 PM   #1
vangelis
Newbie
 
vangelis's Avatar
 
Join Date: Mar 2006
Posts: 7
Rep Power: 0 vangelis is on a distinguished road
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
vangelis is offline   Reply With Quote
Old Mar 1st, 2007, 6:37 PM   #2
Duck
Programmer
 
Join Date: Jun 2006
Location: England London
Posts: 72
Rep Power: 3 Duck is on a distinguished road
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.
Duck is offline   Reply With Quote
Old Mar 2nd, 2007, 6:10 AM   #3
vangelis
Newbie
 
vangelis's Avatar
 
Join Date: Mar 2006
Posts: 7
Rep Power: 0 vangelis is on a distinguished road
'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
vangelis is offline   Reply With Quote
Old Mar 2nd, 2007, 8:54 AM   #4
Duck
Programmer
 
Join Date: Jun 2006
Location: England London
Posts: 72
Rep Power: 3 Duck is on a distinguished road
What exactly is the assert error, and where does it strike?
Duck is offline   Reply With Quote
Old Mar 2nd, 2007, 11:44 AM   #5
vangelis
Newbie
 
vangelis's Avatar
 
Join Date: Mar 2006
Posts: 7
Rep Power: 0 vangelis is on a distinguished road
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
vangelis is offline   Reply With Quote
Old Mar 2nd, 2007, 12:00 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
   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
DaWei is offline   Reply With Quote
Old Mar 2nd, 2007, 8:04 PM   #7
Duck
Programmer
 
Join Date: Jun 2006
Location: England London
Posts: 72
Rep Power: 3 Duck is on a distinguished road
Quote:
Originally Posted by Duck View Post
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.
Duck is offline   Reply With Quote
Old Mar 4th, 2007, 8:33 AM   #8
vangelis
Newbie
 
vangelis's Avatar
 
Join Date: Mar 2006
Posts: 7
Rep Power: 0 vangelis is on a distinguished road
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
vangelis is offline   Reply With Quote
Old Mar 4th, 2007, 2:54 PM   #9
Duck
Programmer
 
Join Date: Jun 2006
Location: England London
Posts: 72
Rep Power: 3 Duck is on a distinguished road
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);
Duck is offline   Reply With Quote
Old Mar 5th, 2007, 10:09 AM   #10
vangelis
Newbie
 
vangelis's Avatar
 
Join Date: Mar 2006
Posts: 7
Rep Power: 0 vangelis is on a distinguished road
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
vangelis is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
editbox keydown detection Kilo C++ 10 Jul 6th, 2006 1:39 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:22 PM.

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