Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CEdit: How do I track non visible edit changes?

CEdit: How do I track non visible edit changes?

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dimitris Vikeloudas
    wrote on last edited by
    #1

    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 is BEGIN_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 simple afx_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

    K 1 Reply Last reply
    0
    • D Dimitris Vikeloudas

      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 is BEGIN_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 simple afx_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

      K Offline
      K Offline
      KellyR
      wrote on last edited by
      #2

      Have you tried catching the EN_CHANGE message instead of EN_UPDATE?

      Kelly Ryan

      D 1 Reply Last reply
      0
      • K KellyR

        Have you tried catching the EN_CHANGE message instead of EN_UPDATE?

        Kelly Ryan

        D Offline
        D Offline
        Dimitris Vikeloudas
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups