Why can't i sent parameters to an IDC(I.D. Control)

  • Thread starter Thread starter sweetjones
  • Start date Start date
  • Tags Tags
    Control Parameters
Click For Summary
SUMMARY

The discussion centers on the inability to pass parameters directly to an IDC (I.D. Control) in an MFC (Microsoft Foundation Class) project using C++ in Visual Studio. The error encountered is error C2440, indicating a type conversion issue when attempting to use a member function with parameters in the message map. The solution involves using a parameterless function, such as void OnBnClicked(), which then calls another function like DoBlah(int a, int b) using member variables (m_a, m_b) set elsewhere in the class.

PREREQUISITES
  • Understanding of MFC (Microsoft Foundation Class) framework
  • Familiarity with C++ programming language
  • Knowledge of Visual Studio IDE
  • Experience with message maps in MFC applications
NEXT STEPS
  • Research MFC message maps and their usage in event handling
  • Learn about member variables in C++ classes and their scope
  • Explore function pointers and their limitations in C++
  • Study best practices for handling button click events in MFC
USEFUL FOR

C++ developers working with MFC, software engineers dealing with event-driven programming, and anyone troubleshooting parameter passing in Visual Studio applications.

sweetjones
Messages
44
Reaction score
0
Why can't i send parameters to an IDC(I.D. Control)

I'm programming a MFC project in C++ using Visual Studio. I'm trying to send 2 parameters through an IDC, so the values of these variables can past through other methods, but i keep getting an error message:error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMFC_testDlg::* )(int &,int &)' to 'AFX_PMSG'
So I took the "afx_msg" off of the class function in my header file, but it still doesn't work. It keeps referring back to this line of code in my Message Map: "ON_BN_CLICKED(IDC_Multiply, OnBnClickedMultiply)" What could I do to pass parameters to a Control, or is it just not possible? Let me know if you need anymore info to help me out. Thankx In Advance!
 
Last edited:
Technology news on Phys.org
You can't have any arguments to the OnBnClicked function it must be "void OnBnClicked()"

If you have a function DoBlah(int a,int b) that must be called when clicked you have to do something like

void OnBnClicked()
{
DoBlah(m_a,m_b);
}

Where m_a, m_b are member variables set somewhere else
 
mgb_phys said:
You can't have any arguments to the OnBnClicked function it must be "void OnBnClicked()"

If you have a function DoBlah(int a,int b) that must be called when clicked you have to do something like

void OnBnClicked()
{
DoBlah(m_a,m_b);
}

Where m_a, m_b are member variables set somewhere else

Ok! I think I know what you mean. I tried that before, but I think I put in the wrong function call. I'll try it again your way. I would have move some things around to get the right results, though. I'll keep you posted. Thanks for your help.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
5
Views
2K
  • · Replies 16 ·
Replies
16
Views
5K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
3
Views
3K
Replies
8
Views
4K
  • · Replies 15 ·
Replies
15
Views
4K