Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnUpdate and other Events

Status
Not open for further replies.

minifiredragon

Programmer
Jun 29, 2003
68
US
Ok, I am now beginning to feel like a ninny.

I thought that when a dialog box closes (with Ok or Cancel) it passes an UpdateData to the next window. When I put an OnUpdate and code in there, it doesn't do anyhting. Here is what I am doing.

I have a CFormView Window starting with the appilcation (I am using an SDI w/database support). I finally got it set up so that when you push a certain key a dialog box opens up and asks you to input data via an edit box. Then you push OK (or Cancel) if you change your mind.

Now I added a static box to see if I have properly learned how to access data from a dialog box. But it never updates itself. I know it gets the data, but it never refreshes.

I used OnUpdate, and WM_SETFOCUS to update the static box when the dialog box is closed. But know.

How do I know it works?? I had this bit of code in there:

if ( m_dInsertDlg.DoModal () == IDOK )
m_sCard = m_dInsert.m_sCardNum;

and everytime I compiled the application the darn Card Number Dialog box opened up 1st, I entered my numbers and pushed ok, and it DID update the static box. But when I pushed the key to enter a card number, entered the number, and pushed OK, it never changed the static box.

I have even tried removing just the:

if ( m_dInsertDlg.DoModal () == IDOK )

It doesn't pop up the box, but it still doesn't update the static text.

So much for thinking I was actually getting somewhere in my knowledge.

In the past, I put my code in the main() section and it looped through that, right now, I have no clue where to put my code so it works like it should.
 
Woohoo, I figured it out. :)

I kept adding to my code in the on PreTranslateMessage code to look like this:

BOOL CICServerView::preTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_KEYDOWN && pMsg->wParam == 'I')
{

//Initialize InsertDlg window
CInsertDlg dlgInsertDlg;

//OPen Window
dlgInsertDlg.DoModal();
m_sCard = dlgInsertDlg.m_sCardNum;
UpdateData(FALSE);
return TRUE;
}

return CFormView::preTranslateMessage(pMsg) ;
}

And it updated like I wanted it too. Is this the proper place to put it thought??
 
>> Is this the proper place to put it thought??

Depends on your definition of "proper". That's certainly not how i would do it but i've been developing with MFC for.... ummm since it started, so i know my way around it pretty well.

Some people would say, "if it works... it's all good". ;-)

-pete
 
May I ask who you would go about it?

<points at stack of notes> That is from you already. :)
 
Well it would go back to the starting point really. See I would have created a command on the application menu somewhere for whatever your doing with that dialog etc. Once you have a menu command you simply create a command handler for it. The command would potentially have a toolbar button as well and it seems a requirement is for the command to be invoked by keypress as well so I would create an Accelerator Key for the command. This of course means you never overrode PreTranslateMessage() to start with.

So the upshot is there would be something like:
Code:
void CICServerView::OnCardInsert()
{
   //Initialize InsertDlg window
   CInsertDlg dlgInsertDlg;

   //OPen Window
	if( IDOK == dlgInsertDlg.DoModal()){
		m_sCard = dlgInsertDlg.m_sCardNum;
		UpdateData(FALSE);
	}
}

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top