Introduction
Let me tell you that this is not a new article. But this is a modified version of Muhammad Ahmed's article "Tabbed ActiveX control". So if you haven't gone through it, then do it now and then read the following.
Background
I came up with this version of the said article, while I was testing Muhammad's control on my own test container (MFC based client app) instead of the ActiveX Control Test Container provided by Microsoft. If you read his article and the comments thereon, you will find that some people (particularly IrishaS and Subash.k) faced weird problems while using the control. Even I faced the same when I recently tried it. Then I started digging the forums, articles on the related topics on the other sites and put some effort (believe me, at least half a day to figure out a particular solution) to get my own test container working with the control (I will call it as a "Property Sheet as an ActiveX control").
Using the Code
- I have used VS 2005 to design/change the code attached here.
- I am also providing the
FormView
based SDI client app (our own test container) to test the control. - You can test the MDI client app on your own.
Major Change Made to the Control
Note: Check the comment "!! Freezing - Solution for property sheets" authored by "Tihamer Levendovszky".
BOOL CSimpleAdditionAtxCtrl::PreTranslateMessage(MSG* pMsg)
{
::TranslateMessage(pMsg);
::DispatchMessage(pMsg);
return TRUE; }
Other Changes that are Made to Make the Code More Understandable
- Now the ActiveX method
SetFirstNumber
gets as simple as this:
void CSimpleAdditionAtxCtrl::SetFirstNumber(LONG Num1)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
m_InputPage.SetIPageFirstNum(Num1);
}
I added a method in the CInputPage
class that looks like:
void CInputPage::SetIPageFirstNum(long num)
{
m_FirstNumber=num;
UpdateData(FALSE);
}
Note: Similarly I did it for the ActiveX method SetSecondNumber
. Review the attached code for full information.
- I replaced the code
UpdateData(TRUE);
from the OnEnChangeEdit1
and OnEnChangeEdit2
event handlers respectively, which was not serving any purpose to the following line in order to enable the button only if the user inputs the value in any of the edit boxes.
((CButton*)(GetDlgItem(IDC_BUTTON1)))->EnableWindow();
That's it.
Points of Interest
- With the Dialog based client application/test container, this control doesn't work, i.e. it only works with SDI/MDI
FormView
type of applications. It is most appreciated if somebody could get this working.
- The tab key, arrow key, ctrl keys, etc. are not functioning in the ActiveX control. For this, I tried implementing as described by Microsoft here. It worked fine but introduced the app freezing again while testing the control. So I dropped the idea. I wish somebody gets some time to check this out.
History
- 9th February, 2010: Initial post