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

Incorrect arguments being passed to ON_COMMAND handler

Status
Not open for further replies.

IoMatua

Programmer
Mar 27, 2003
17
NZ
Hi. I apologize in advance for the lengthy post, but I didn't want to leave anything out.

I'm having a problem with executing context menu commands. In my list view, I've managed to display the context menu when a list item is right-clicked on, however, when I try to execute any of the menu commands, nothing happens.

I started up the debugger and had a look at the stack trace. It seems that the message handler that I specified using the ON_COMMAND macro (which I named `OnPopupCommand'), is being passed an incorrect menu item ID value, but the functions that were called before that had been the correct menu item ID value. My knowledge of the debugger and its capabilities is limited, so I am now at a dead end. Here are the last few lines of the the stack trace:

Code:
CVIW_List::OnPopupCommand(unsigned int 1244532) line 317
_AfxDispatchCmdMsg(CCmdTarget * 0x00302220 {CVIW_List hWnd=0x00050460}, unsigned int 32775, int 0, void (void)* 0x00401212 CVIW_List::OnPopupCommand(unsigned int), void * 0x00000000, unsigned int 12, AFX_CMDHANDLERINFO * 0x00000000) line 88
CCmdTarget::OnCmdMsg(unsigned int 32775, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 302 + 39 bytes
CView::OnCmdMsg(unsigned int 32775, int 0, void * 0x00000000, AFX_CMDHANDLERINFO * 0x00000000) line 159 + 24 bytes

32775 is the value of the menu item ID `ID_BDMITM2', but somehow, OnPopupCommand is being passed some other value. Here's how I defined the message handler in my CVIW_List class (CListView):

Code:
ON_COMMAND(ID_BDMITM2, OnPopupCommand)

In the same class, I also have a handler for double click events, where I call OnPopupCommand explicitly ...

Code:
void CVIW_List::OnItemDoubleClick(NMHDR* pNMHDR, LRESULT* pResult) 
{
	... // Get POSITION of affected list item.

	if(pos)
	{
		int nIndex = myListCtrl.GetNextSelectedItem(pos);

		switch(m_nSelection)	
		{
		case IID_BENEDB_1:
			CVIW_List::OnPopupCommand(ID_BDMITM2);
			break;
		}
	}
	... // Done.
}[code]

... and everything works fine. 

This problem has become increasingly frustrating, so any suggestions or comments would be greatly appreciated. Thanks in advance.
 
1. In my opinion your WM_COMMAND is sent to your ListView, not to your window which process WM_COMMAND.
2. From ListView you will be able to handle only WM_NOTIFY messages.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
IonFilipski, could you further elaborate on your reply if possible? My understanding was that views could be treated the same as windows, so in my case, I thought that I would be able to use the list view to process WM_COMMAND messages from that view's list conrtol.

I've managed to make some progress though. Instead of processing all the menu commands from a single handler that takes a menu ID (OnPopupCommand), I've made seperate handler functions for all possible menu commands in my list view class. Everything works fine now, but I would much prefer to process the menu commands from a single handler function.
 
>> but I would much prefer to process the menu commands from a single handler function.

Override CWnd::WindowProc()

-pete
 
hello


How can I call a Menu-Point
for example

File Report
-> Open

in my program?
the user should not click on the Menu-Point Open
I want to call the Menu-Point in a Method of my App.cpp
??

how can I realize this?

thanks for help

Reci

ManagerRichie@gmx.de
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top