CEdit: How do I track non visible edit changes?
-
I have a subclass of a CEdit. I want to be able to resize the visible edit control until it reaches a preset bound and then to keep scrolling horizontaly and vertically. I wrote the following code To create the control
dwStyle = ES_LEFT | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL; if( multiline ) { m_pEdit->setMultilineOn(); dwStyle = dwStyle | ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN; } // First set the visible text bounds. Simply store them // in member variables. m_pEdit->set_bounds(maxWidth, maxHeight); // Now create the edit control window m_pEdit->Create(dwStyle, rect, this, ID_inline_edit); // Adjust the edit control window m_pEdit->SetWindowText(text.data());
The message mapping of my CEdit isBEGIN_MESSAGE_MAP(U_W_Edit, CEdit) //{{AFX_MSG_MAP(U_W_Edit) ON_WM_CTLCOLOR_REFLECT() ON_CONTROL_REFLECT(EN_UPDATE, OnEditUpdate) ON_NOTIFY_REFLECT(EN_UPDATE, OnEditUpdate) ON_WM_KEYUP() ON_WM_SIZE() ON_WM_CHAR() //}}AFX_MSG_MAP END_MESSAGE_MAP()
My resize code is simpleafx_msg void U_W_Edit::OnEditUpdate() { // Probably called before the window is created. if( !::IsWindow(this->m_hWnd) ) return; // Nothing to do. Internal flag to check for maximum sizes if( m_bMaxSizeReached ) return; int length = this->GetWindowTextLength() + 1; AB_TextBuffer text(length); GetWindowText(text.data(), length); AB_Integer width; AB_Integer height; this->get_text_extend((AB_Text) text, width, height); BOOL resize = FALSE; if( width.to_long() > m_width && width <= m_maxWidth ) { resize = TRUE; m_width = width.to_long(); } if( height.to_long() > m_height && height <= m_maxHeight ) { resize = TRUE; m_height = height.to_long(); } if( resize ) this->SetWindowPos( NULL, 0, 0, m_width, m_height, SWP_NOMOVE | SWP_NOREPOSITION | SWP_NOZORDER ); }
However, any time that I type a new character it scrolls it horizontally or vertically. It never resizes the control until it reaches the maximum sizes. I used Spy++ and realised that the EN_UPDATE message never reaches my CEdit subclass. I wonder how can I know that the stored text has changed. I tried doing it within the OnChar but it is a nightmare to filter out all characters like arrow keys etc and add in the existing text the new key. Is any simple way to track that the stored tex -
I have a subclass of a CEdit. I want to be able to resize the visible edit control until it reaches a preset bound and then to keep scrolling horizontaly and vertically. I wrote the following code To create the control
dwStyle = ES_LEFT | WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL; if( multiline ) { m_pEdit->setMultilineOn(); dwStyle = dwStyle | ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN; } // First set the visible text bounds. Simply store them // in member variables. m_pEdit->set_bounds(maxWidth, maxHeight); // Now create the edit control window m_pEdit->Create(dwStyle, rect, this, ID_inline_edit); // Adjust the edit control window m_pEdit->SetWindowText(text.data());
The message mapping of my CEdit isBEGIN_MESSAGE_MAP(U_W_Edit, CEdit) //{{AFX_MSG_MAP(U_W_Edit) ON_WM_CTLCOLOR_REFLECT() ON_CONTROL_REFLECT(EN_UPDATE, OnEditUpdate) ON_NOTIFY_REFLECT(EN_UPDATE, OnEditUpdate) ON_WM_KEYUP() ON_WM_SIZE() ON_WM_CHAR() //}}AFX_MSG_MAP END_MESSAGE_MAP()
My resize code is simpleafx_msg void U_W_Edit::OnEditUpdate() { // Probably called before the window is created. if( !::IsWindow(this->m_hWnd) ) return; // Nothing to do. Internal flag to check for maximum sizes if( m_bMaxSizeReached ) return; int length = this->GetWindowTextLength() + 1; AB_TextBuffer text(length); GetWindowText(text.data(), length); AB_Integer width; AB_Integer height; this->get_text_extend((AB_Text) text, width, height); BOOL resize = FALSE; if( width.to_long() > m_width && width <= m_maxWidth ) { resize = TRUE; m_width = width.to_long(); } if( height.to_long() > m_height && height <= m_maxHeight ) { resize = TRUE; m_height = height.to_long(); } if( resize ) this->SetWindowPos( NULL, 0, 0, m_width, m_height, SWP_NOMOVE | SWP_NOREPOSITION | SWP_NOZORDER ); }
However, any time that I type a new character it scrolls it horizontally or vertically. It never resizes the control until it reaches the maximum sizes. I used Spy++ and realised that the EN_UPDATE message never reaches my CEdit subclass. I wonder how can I know that the stored text has changed. I tried doing it within the OnChar but it is a nightmare to filter out all characters like arrow keys etc and add in the existing text the new key. Is any simple way to track that the stored tex -
Just tried that, makes no difference. I think the parent (a CScrollView subclass) does not reflect the EN_UPDATE/EN_CHANGE message properly to the child CEdit for some reason.