Thanks Frank J. Lagattuta! It's really problem with coloring CListCtrl with using Geometry in Dialog! NM_CUSTOMDRAW doesn't work cristal! to get CDDS_ITEMPREPAINT you should use Frank J. Lagattuta OnNotify function!
ReplyOriginally posted by: smd
Need help on how to use the Geometry templates in Composite
ATL controls used in MFC applications. For example a Composite ATL control has couple of edit controls and comboboxes. Need only to resize Edit controls.
Originally posted by: Trey Van Riper
I wanted to be able to allow the user to save the resized
So, I modified and exposed the GeometryInitialize()
The new GeometryInitialized() function now looks like this:
template <typename T> inline void CGeometryWnd<T>::GeometryInitialize()
pThis->GetClientRect(m_minRect);
BuildGeometryList();
And, to expose this, I modified the
#define DECLARE_GEOMETRY_RTSUPPORT() \
So now, I'm able to do something like this:
BOOL MyDialog::OnInitDialog()
I hope this is useful to someone.
Motivation:
window dimensions, but unfortunately I could not initialize
the window to the new size without experiencing some
amusing problems with the controls. That is, the controls
would be one size, while the window would be the original
size of the resource.
function to give me a way around the problem.
{
static bool is_initialized = false;
if ( !is_initialized ) {
T* pThis = static_cast<T*>(this);
pThis->GetClientRect(m_originalRect);
m_cList.SetRects(pThis->GetSafeHwnd());
is_initialized = true;
}
}
DECLARE_GEOMETRY_RTSUPPORT() macro as follows:
public: \
bool AddConstraint(UINT nID,CConstraint& cstr) { return AddConstraint(nID,cstr,this); };\
virtual bool AddConstraint(UINT nID,CConstraint& cstr,CWnd* pParent) { ASSERT(FALSE); return true; };\
virtual void RemoveConstraint(UINT nID) { ASSERT(FALSE); }; \
virtual void GeometryInitialize() { ASSERT(FALSE); };
{
CDialog::OnInitDialog();
AddConstraint( IDC_SPIFFY_CONTROL, CConstraint("CX") );
GeometryInitialize();
ReadAndSetDialogSizeFromRegistry();
}
Originally posted by: Michael
inline void CBindCtlToConstraint::ResizeControl(HWND hwndParent,CSize pExt,CSize mExt)
// pExt is the new size of the parent rect
if (m_constraint.m_options & CConstraint::eRatioX)
if (x < m_rsctl.m_iRect.left)
UINT nFlags = SWP_NOZORDER | ((GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE)? SWP_SHOWWINDOW : 0);
if(pwc) pwc->SetWindowPos(NULL,x,y,cx,cy,nFlags); //pwc->MoveWindow(x,y,cx,cy);
inline void CResizeCtlList::SetRects(HWND hParent)
while (pos)
//////////////////inserted //////////////
CWnd::FromHandle(hParent)->ScreenToClient(rect);
To be able to resize ActiveX one should chande two subroutines in the Geometry.h:
{
// changes 11.4.2001
CRect rCtl;
CWnd* pParent = CWnd::FromHandle(hwndParent);
HWND hwnd = NULL;//GetDlgItem(hwndParent,m_rsctl.m_nID);
CWnd *pwc=NULL;
if(pParent) {
pwc = pParent->GetDlgItem(m_rsctl.m_nID);
if(pwc) hwnd= pwc->GetSafeHwnd();
}
ASSERT(hwnd != NULL);
if(pwc) pwc->GetWindowRect(rCtl);
///else ::GetWindowRect(hwnd,rCtl);
pParent->ScreenToClient(rCtl);
// mExt is the initial size of the parent rect
int x = m_rsctl.m_iRect.left;
int y = m_rsctl.m_iRect.top;
int cx = m_rsctl.m_iRect.Width();
int cy = m_rsctl.m_iRect.Height(); // the new coordinates of the control rect
x = pExt.cx*m_rsctl.m_iRect.left/mExt.cx;
if (m_constraint.m_options & CConstraint::eRatioCX)
cx = pExt.cx*m_rsctl.m_iRect.Width()/mExt.cx;
if (m_constraint.m_options & CConstraint::eRatioY)
y = pExt.cy*m_rsctl.m_iRect.top/mExt.cy;
if (m_constraint.m_options & CConstraint::eRatioCY)
cy = pExt.cy*m_rsctl.m_iRect.Height()/mExt.cy;
if (m_constraint.m_options & CConstraint::eCenterX)
x += (pExt.cx-mExt.cx)/2;
if (m_constraint.m_options & CConstraint::eCenterY)
y += (pExt.cy-mExt.cy)/2;
if (m_constraint.m_options & CConstraint::eResizeCX)
cx += (int)((pExt.cx-mExt.cx) * m_constraint.m_cxratio);
if (m_constraint.m_options & CConstraint::eResizeCY)
cy += (int)((pExt.cy-mExt.cy) * m_constraint.m_cyratio);
if (m_constraint.m_options & CConstraint::eMoveX)
x += (int)((pExt.cx-mExt.cx) * m_constraint.m_xratio);
if (m_constraint.m_options & CConstraint::eMoveY)
y += (int)((pExt.cy-mExt.cy) * m_constraint.m_yratio);
x = m_rsctl.m_iRect.left;
if (y < m_rsctl.m_iRect.top)
y = m_rsctl.m_iRect.top;
if (cx < m_rsctl.m_iRect.Width())
cx = m_rsctl.m_iRect.Width();
if (cy < m_rsctl.m_iRect.Height())
cy = m_rsctl.m_iRect.Height();
//ShowWindow(hwnd,SW_HIDE);
////else SetWindowPos(hwnd,NULL,x,y,cx,cy,nFlags);
// InvalidateRects(pParent,rCtl,CRect(x,y,x+cx,y+cy));
}
{
CRect rect;
POSITION pos = m_gCtl.GetHeadPosition();
{
CBindCtlToConstraint* pcbc = m_gCtl.GetNext(pos);
HWND hCtl = GetDlgItem(hParent,pcbc->m_rsctl.m_nID);
CWnd* pParent = CWnd::FromHandle(hParent);
CWnd *pwc=NULL;
if(pParent) {
pwc = pParent->GetDlgItem(pcbc->m_rsctl.m_nID);
if(pwc) hCtl= pwc->GetSafeHwnd();
}
if(pwc) pwc->GetWindowRect(rect);
//////////////////////////////////////////
pcbc->SetRect(rect);
}
}
Originally posted by: Mahesh Kumar
How to put a combobox for a particular column in msflexgrid in vc++
ReplyOriginally posted by: Mahesh Kumar
How to put a combobox for a particular column in msflexgrid in vc++
ReplyOriginally posted by: Philip Chang
Thanks for a very elegant and easy to use solution.
However, when I try to AddConstraint() for a Wang Image Edit ActiveX Control inserted via resource editor, I would get the ASSERT() failure in geometry.h, line 422.
Please let me know how I can find out what I am doing wrong.
Thanks!
Philip Chang
Originally posted by: Srinivas Vaddi
Tryed to reduce and resize dialog layout but i am not able to achive the reduced size.
Code works perfectly when Trying to enlarge the size of the dialog & Controls.
Please suggest....
VSReddy.
Originally posted by: Prasanna
Can you please explain me what is the creteria of deciding the ratio in the following lineBOOL CAddedPage2::OnInitDialog()
{
CPropertyPage::OnInitDialog();
AddConstraint(IDOK,CConstraint(1));
AddConstraint(IDCANCEL,CConstraint(1));
AddConstraint(IDC_EDIT1,CConstraint(0,0,1,0));
AddConstraint(IDC_EDIT2,CConstraint(0,0,1,0));
AddConstraint(IDC_LIST1,CConstraint(0,0,1,0.5));
AddConstraint(IDC_LIST2,CConstraint(0,0.5,1,0.5));
}
Reply
Originally posted by: Frank J. Lagattuta
However, I ran into a problem. In my FormView I have
Basically, the list/tree ctrls use message reflection to
In geometry.h there is an override of the CWnd::OnNotify
template <class T> BOOL ACtrlGeometryWnd<T>::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
T::OnNotify(wParam,lParam,pResult);
// don't handle messages not from the page/sheet itself
if (pNMHDR->code == PSN_SETACTIVE)
*pResult = 0;
This breaks the notification chain because, even though it
In addition, it checks to see where the notification came
To fix I changed this function to:
template <class T> BOOL ACtrlGeometryWnd<T>::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
bRetVal = T::OnNotify(wParam,lParam,pResult);
if (pNMHDR->code == PSN_SETACTIVE)
return bRetVal;
This preserves the base class values for the return value
All repositioning/resizig works as before and my custom
-Frank
Great code! I use it with a CFormView derived class of
mine - repositions/resizes controls, works great!
list ctrls and tree ctrls that allow for in-place editing
for subitems using dropdown list ctrl, spin ctrls, etc.
I have implemented this as described in other sections of
CodeGuru.
handle the BeginLabelEdit and EndLabelEdit notifications
and in their handling create an in-place ctrl of the proper
type, give it focus, and let the user edit. When the
in-place edit ctrl loses focus, it destroys itself and
sends an EndLabelEdit message back to the list/tree ctrl.
function that looks like this:
{
NMHDR* pNMHDR = (NMHDR*)lParam;
CRect rWnd;
if (pNMHDR->hwndFrom != m_hWnd && pNMHDR->hwndFrom != ::GetParent(m_hWnd))
return FALSE;
{
GetWindowRect(rWnd);
SetWindowPos(NULL,0,0,rWnd.Width(),rWnd.Height(),SWP_NOZORDER|SWP_NOMOVE);
}
return TRUE;
}
calls the base class OnNotify functionality, it ignores
the value set in pResult and always returns TRUE.
from and ignores it if it is not from the "page/sheet
itself". I don't know why you would want to do this.
{
NMHDR* pNMHDR = (NMHDR*)lParam;
CRect rWnd;
BOOL bRetVal;
{
GetWindowRect(rWnd);
SetWindowPos(NULL,0,0,rWnd.Width(),rWnd.Height(),SWP_NOZORDER|SWP_NOMOVE);
}
}
and pResult and doesn't simply return FALSE if the message
is not from the page/sheet.
in-place edit ctrls work also.