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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

menu element check/uncheck

Status
Not open for further replies.

DeCoDeR

Programmer
Jun 4, 2002
37
0
0
US
hi ,
i have a menu and i want to check/uncheck one the elements of this menu
below code is not working, anyone has ideas ?
---------
void CSayiDlg::OnUpdateRaceTime(CCmdUI* pCmdUI)
{
iCheckTime = ++iCheckTime % 2;
pCmdUI->Enable (iCheckTime);
}


Read between the lines
 
pCmdUI->Enable(TRUE);
pCmdUI->SetCheck(1);

Try This!! Tell me if this works

You need to use the SetCheck(TRUE OR FALS) function to set the check
 
pCmdUI->SetCheck(1); //Check menu item
pCmdUI->SetCheck(0); //Uncheck menu item
 
unfortunately that doesnot work.
here is the latest source that doesnt work
--------
void CSayiDlg::OnUpdateRaceTime(CCmdUI* pCmdUI)
{

bCheckTime = !bCheckTime;
pCmdUI->Enable (TRUE);
pCmdUI->SetCheck (bCheckTime);
}




Read between the lines
 
Yeah that's not going to work in the OnUpdatexxx handler because it runs in the idle time code so your flipping it back and forth all the time. You need to flip your bool in the click event and just set the check in the update, something like this:
Code:
void CSdiRndView::OnUpdateViewTest(CCmdUI *pCmdUI)
{
	pCmdUI->SetCheck( _bTest);
}

void CSdiRndView::OnViewTest()
{
	// TODO: Add your command handler code here
	_bTest = !_bTest;
}

-pete
 
still its not working ;(
-------
i put a messagebox to see if boolean variable is working and yes its working.
but still i dont see a check.
-------
void CMenudeneDlg::OnDeneme1()
{
bChecked = !bChecked;
if(bChecked)
MessageBox("bChecked = TRUE","bChecked");
else
MessageBox("bChecked = FALSE","bChecked");
}

void CMenudeneDlg::OnUpdateDeneme1(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck (bChecked);
}


Read between the lines
 
The code i posted has been tested and works in a MFC SDI application. If yours is not working then the problem exists is some place other than the code you are posting.

-pete
 
Oh.. i see your working in a dialog based application. The UpdateUI handlers are not called in a dialog applciation. You have to add some code to replace the missing MFC Document/View framework code that is not present in a dialog.

There are Technical Articles on MSDN that discuss several techniques for adding that support to a dialog.

msdn.microsoft.com

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top