Click here to Skip to main content
15,882,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

This may be a stupid question and the result of over-indulgence throughout the holiday period. Anyway here goes : I have created an owner draw button (CButtonEx) and one of the many features added is the ability to have a timeout period which when depleted causes the user-defined OnClick function to execute. I can put an onclick handler in the CButtonEx source file and can call that from within the CButtonEx class, I can also put an on click handler in the Dialog class where the button is placed. And can call the CButtonEx OnClick from the Dialog OnClick.

How do you call down the tree?? i.e. from the CbuttonEx to the CDialog class where the user code is??? I am sure this should be simple was thinking that you could post a message but I think that it sould be easier than that.

Any help greatly appreciated.


In your CButtonEx OnTimer() handler:
::PostMessage(GetParent()->m_hWnd, WM_COMMAND, MAKELONG(GetDlgCtrlID(), BN_CLICKED), (LPARAM)m_hWnd);

Share this answer
This is trivial in .NET, but I believe in C++ you need to use a function pointer to define a method in one class and then have it call a method in another. Or you could use messages, that may be simpler.
Share this answer
I would mimic the MFC behaviour, i.e. post a message.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900