|
dezhou wrote: how to get the the picture...
What picture?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi,
I created a dialog based application. The contains customized treeview control. I am displaying a popup menu by right clicking on the menu item.
I want to check / uncheck the menu item. I used
CheckMenuItem() method. But it is not working .
Anybody know the reason?
All kinds of suggestions are welcome.
|
|
|
|
|
Seehere[^] for the reason and how to resolve it.
-Saurabh
|
|
|
|
|
thanks for the reply
In the given link , they are dealing with COMMAND UI event handler.
I did the Check / uncheck operations in COMMAND event handler only.
any other solution?
|
|
|
|
|
Member 4063274 wrote: I did the Check / uncheck operations in COMMAND event handler only.
any other solution?
You should use CCmdUI object and it's method called SetCheck to set a check mark for a menu item instead of calling the API.
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
I tried that method also. but no use.
After calling SetCheck() any refreshment function need to be called?
|
|
|
|
|
Member 4063274 wrote: After calling SetCheck() any refreshment function need to be called?
Is the update cmd ui being called, put a breakpoint?
Try calling CheckMenuItem() before calling TrackPopupMenu .
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
whether we need to call TrackPopupMenu() method in COMMAND UI event handler?
|
|
|
|
|
Member 4063274 wrote: whether we need to call TrackPopupMenu() method in COMMAND UI event handler?
No, don't call TrackPopupMenu from the UI handler! Forget about command UI handler for now and call CheckMenuItem just before you display the popup menu i.e. just before TrackPopupMenu!
|
|
|
|
|
CheckMenuItem() is working in RButtonDown() function call.
But i want to toggle the state in COMMAND event handler(by clicking).
|
|
|
|
|
Member 4063274 wrote: But i want to toggle the state in COMMAND event handler(by clicking).
Maintain a flag for this purpose.
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Read the link I sent you carefully.
You have to add a handler for ON_WM_INITMENUPOPUP and the add the following code in the handler. Only then command UI events will be called for a dialog box.
void CTestDlg::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
{
ASSERT(pPopupMenu != NULL);
CCmdUI state;
state.m_pMenu = pPopupMenu;
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pParentMenu == NULL);
HMENU hParentMenu;
if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
state.m_pParentMenu = pPopupMenu;
else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
{
CWnd* pParent = this;
if (pParent != NULL &&
(hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
{
int nIndexMax = ::GetMenuItemCount(hParentMenu);
for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
{
if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
{
state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
break;
}
}
}
}
state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
state.m_nIndex++)
{
state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
if (state.m_nID == 0)
continue;
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pMenu != NULL);
if (state.m_nID == (UINT)-1)
{
state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
if (state.m_pSubMenu == NULL ||
(state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
state.m_nID == (UINT)-1)
{
continue;
}
state.DoUpdate(this, TRUE);
}
else
{
state.m_pSubMenu = NULL;
state.DoUpdate(this, FALSE);
}
UINT nCount = pPopupMenu->GetMenuItemCount();
if (nCount < state.m_nIndexMax)
{
state.m_nIndex -= (state.m_nIndexMax - nCount);
while (state.m_nIndex < nCount &&
pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
{
state.m_nIndex++;
}
}
state.m_nIndexMax = nCount;
}
}
-Saurabh
|
|
|
|
|
i put a break point InitPopupMenu() method.
But it is not at all firing
|
|
|
|
|
Did you add the ON_WM_INITMENUPOPUP entry to the message map like this :
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
ON_WM_INITMENUPOPUP()
END_MESSAGE_MAP()
|
|
|
|
|
ya. It is added in the message map of the dialog class.
But the pop menu will get displayed by right click
on the tree view control not on the dialog.
|
|
|
|
|
Okay I just tried a sample in VS 2008 and this method works.
1. Create an dialog application.
2. Added a tree control
3. Added a menu with 2 items.
4. Added handler for NM_RCLICK for tree control.
5. Added Command and CommandUI event handlers for 3 items in the menu.
Now when an item is selected in the menu there is no check box.
6. Added ON_WM_INITMENUPOPUP handler for the Dialog class.
7. Added the code I posted in previous message.
Now when an item is selected in the menu and the menu us shown again next time there is check against it.
Let's say there is a variable int x in the dialog and it x=1 then it mean first item is selected and if x=2 then second item is selected. The following is the code for command and commandui handlers.
void CTestDlg::OnButton1()
{
x = 0;
}
void CTestDlg::OnUpdateButton1(CCmdUI *pCmdUI)
{
if(x == 0)
{
pCmdUI->SetCheck(1);
}
else
{
pCmdUI->SetCheck(0);
}
}
void CTestDlg::OnButton2()
{
x = 1;
}
void CTestDlg::OnUpdateButton2(CCmdUI *pCmdUI)
{
if(x == 1)
{
pCmdUI->SetCheck(1);
}
else
{
pCmdUI->SetCheck(0);
}
}
|
|
|
|
|
Hi,
In your example where are you using TrackPopupMenu() to display the pop up menu
|
|
|
|
|
In the handler for NM_RCLICK for treeview.
I am using the following code.
CPoint p(GetMessagePos());
CMenu _menu;
_menu.LoadMenu(IDR_MENU1);
CMenu* pPopup = _menu.GetSubMenu(0);
pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, p.x, p.y, this);
-Saurabh
|
|
|
|
|
now i can able to check and uncheck only for the first time.
Following is the code of COMMAND event handler which do that,
<br />
<br />
UINT state = submenu->GetMenuState(ID_TEST_MAINSTREAM, MF_BYCOMMAND);<br />
<br />
if (state & MF_CHECKED)<br />
{<br />
nRet = submenu->CheckMenuItem(2,MF_BYPOSITION |MF_UNCHECKED); <br />
}<br />
else<br />
{<br />
nRet = submenu->CheckMenuItem(2, MF_BYPOSITION|MF_CHECKED);<br />
}<br />
<br />
UINT state2 = submenu->GetMenuState(2, MF_BYPOSITION);<br />
<br />
In first click, the menu item state is changed.
when i check the value of state2 variable, it is 0 .
when I click the same menu item next time, GetMenuState() returns 8.
why the checking state of the menu item is not updating ?
|
|
|
|
|
Member 4063274 wrote: I used
CheckMenuItem() method. But it is not working .
What is it returning?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
return vaule is the previous state of the menu item
|
|
|
|
|
I want to connect a SQL Server DB through C++/VC++ coding.
Any help links / sample code / regarding stuff then pls mail to sudarshanmca@gmail.com.
Thanks in advance.
Regards
Regards
SG
|
|
|
|
|
Already been here [^]?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Are you using MFC?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|