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
AI Thread Summary
In programming with MFC in C++, sending parameters directly to an IDC (I.D. Control) is not possible due to the requirement that event handler functions, like OnBnClicked, must have a specific signature: they cannot accept arguments and must be defined as "void OnBnClicked()". To work around this limitation, member variables can be used to store the necessary values. When the button is clicked, the OnBnClicked function can call another function (e.g., DoBlah) using these member variables. This approach allows the desired parameters to be utilized indirectly. Users experiencing issues with implementation are encouraged to ensure they are correctly referencing member variables and function calls.
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 arguements 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 arguements 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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top