描述:
为了让ComboBox能够支持多选,用VC做了一个特殊的ActiveX控件,该控件将用于VB。在OnSize()中改变控件大小,欲令其始终等于ComboBox控件的Edit框的大小。代码如下:
void CComboBoxExCtrl::OnSize(UINT nType, int cx, int cy)
{
COleControl::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
m_width = cx;
if( IsCmboxCreated() ) //如果m_pComBox已经创建
{
CRect rctCombox(0, 0, 0, 0);
rctCombox.right = rctCombox.left + m_width;
rctCombox.bottom = rctCombox.top + m_height;
m_pComBox->MoveWindow(rctCombox, TRUE);
int nEditCtrlHight = m_pComBox->GetItemHeight(-1) + 6;
SetControlSize(m_width, nEditCtrlHight);
}
}
在Test Container中测试完全可用,但当加入到VB的Form中时,SetControlSize(m_width, nEditCtrlHight)函数虽然执行了,但控件大小并没有如预期那样。
请问高手:
1.Test Container与VB的Form到底是怎么不同的呢?为何Form中不行?
2.或者,OnSize()中的处理是否恰当?
解决方案1:
BOOL COleControl::SetRectInContainer( LPRECT lpRect );
Call this function to set the coordinates of the control’s rectangle relative to the container, expressed in device units. If the control is open, it is resized; otherwise the container’s OnPosRectChanged function is called.