|
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
|
|
|
|
|
Did you see database section on the codeproject?
|
|
|
|
|
i would like to refresh the registry without closing and reopening explorer.exe because i want to make a single entry in the registry and to refresh the shell to activate the change i have made... so what is the option to do that in win32... or any idea will be nice...
|
|
|
|
|
Use the SendMessageTimeout API call with HWND_BROADCAST and WM_SETTINGCHANGE.
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
|
|
|
|
|
is it possible to enumerate the taskbar icons(system tray) using win32 and there will be always a way to do that but which shell options to use or if somebody can link me to such topics that will nice... so i want to remove a particular taskbar icon using my own program...
|
|
|
|
|
Jach Mullan wrote: enumerate the taskbar icons(system tray) using win32 and there will be always a way to do that but which shell options to use or if somebody can link me to such topics that will nice
There is a tool in codeproject written by Nishant Sivakumar which re-orders the tray icons, that will be some help to you!
Here is the link -> http://www.codeproject.com/KB/applications/ShellTrayInfo.aspx[^]
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
modified on Tuesday, April 1, 2008 4:05 AM
|
|
|
|
|
Hello all,
Is it possible to load a swf file in resource and can i use it from resource/
If so then how?
Thanks in advance.
Manish Patel.
B.E. - Information Technology.
|
|
|
|
|
Yes it's possible.
The FindResource()/LoadResource()/LockResource()/etc. APIs will let you work with the resource.
How you use the resource depends on what you want to do with it.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for your reply.
I want to load swf in shockwaveflash Activex and it only accept path of the swf. So now how can i load perticular swf to shockwaveflash activex?
Any hint?
Thanks in advance
Manish Patel.
B.E. - Information Technology.
|
|
|
|
|
I believe the only thing you can do in that case is save it to a temporary file and play it
from there.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I wan to disable/ remove those standard buttons from my property sheet.
I used the followin snippet in ONINITDIALOG():
CWnd *pWnd = GetDlgItem( IDCANCEL );
pWnd->gtShowWindow( FALSE );
(&)
CWnd* pApplyButton = GetDlgItem (IDOK);
ASSERT (pokButton);
pokButton->ShowWindow (SW_HIDE);
But i could get the result..
wats the rite thing missing behind..
Thanks in advance..
Gita
|
|
|
|
|
Hi,
How to cal a PropertySheet inside a PropertySheet..
Thanks..
Gita
|
|
|
|