I am creating a breakout game using MFC, and now I am programming a level creator. For the user to choose which block is desired to create, I'm using a SplitButton. I have created the menu resource to pair with my SplitButton, but I want each one of the options in the menu to do something. Reading the documentation about how to assign a afx_msg void OnOptionSelected()
to an event using BEGIN_MESSAGE_MAP
I found this:
//Microsoft Documentation Code
BEGIN_MESSAGE_MAP(CMyDoc, CDocument)
ON_COMMAND(ID_MYCMD, &CMyDoc::OnMyCommand)
END_MESSAGE_MAP()
And I did the same with my code, creating an afx_msg
for each of my menu options in my menu resource
//My code in CCreateWindow.h (Inside DECLARE_MESSAGE_MAP())
afx_msg void OnToughBlockChosen();
afx_msg void OnSturdyBlockChosen();
afx_msg void OnWeakBlockChosen();
afx_msg void OnSpecialBlockChosen();
afx_msg void OnIndestructibleBlockChosen();
And thus their assignation
//My code in CCreateWindow.cpp (Inside BEGIN_MESSAGE_MAP)
ON_COMMAND(ID_CHOOSEBLOCKTYPE_TOUGHBLOCK, &CCreateWindow::OnToughBlockChosen())
ON_COMMAND(ID_CHOOSEBLOCKTYPE_STURDYBLOCK, &CCreateWindow::OnSturdyBlockChosen())
ON_COMMAND(ID_CHOOSEBLOCKTYPE_WEAKBLOCK, &CCreateWindow::OnWeakBlockChosen())
ON_COMMAND(ID_CHOOSEBLOCKTYPE_SPECIALBLOCK, &CCreateWindow::OnSpecialBlockChosen())
ON_COMMAND(ID_CHOOSEBLOCKTYPE_INDESTRUCTIBLEBLOCK, &CCreateWindow::OnIndestructibleBlockChosen())
But when I did this, the error E024 a nonstatic member reference must be relative to a specific object
appears. So far I have an idea of how it can be solved (ON_COMMAND(ID_CHOOSEBLOCKTYPE_TOUGHBLOCK, &m_CreateWindow.OnToughBlockChosen())
) but just I dunno if that's the way to fix it and if it is I dunno where to declare the object since I tried to do it in the .h
and .cpp
and none worked. I just don't know what to do now since I did the same as in the Microsoft Documentation and it explicitly stated:
The
ON_COMMAND
macro is used to handle command messages generated by menus, buttons, and accelerator keys.