Recording a particular "View" or "Area" during scrolling.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Recording a particular "View" or "Area" during scrolling.

  1. #1
    Join Date
    Feb 2011
    Posts
    39

    Recording a particular "View" or "Area" during scrolling.

    Hello again,

    I was worrying myself over the following problem:

    Consider a CEdit control in a scrollable window. When the window is scrolled and consequently the CEdit control is scrolled out of view, the blinking cursor still follows to the next scrolled region. I assumed this was because the CEdit still retained focus and demanded to be present in the scrolled area. This is of course highly undesirable and what I wish is for the CEdit to retain focus only when it is scrolled back into view.

    So I recorded the values of m_nHScrollPos and m_nVScrollPos in separate variables, nHScreenView and nVScreenView respectively upon creation of the CEdit control. I then ordered the CEdit control to be destroyed as soon as the window was scrolled (at the very end of the OnVScroll, OnHScroll functions). Finally I use this code to recreate the CEdit control when the area containing the CEdit control is scrolled into view. Again this code is present at the end of the WM_*SCROLL message functions.

    Code:
    if(m_nHScrollPos == nHScreenView && m_nVScrollPos == nVScreenView)
    {
        ceTextIn.Create(/*parameters*/);
        ceTextIn.SetFocus();
    }
    It doesn't seem to be working. Debugging reveals that the above pocket of code is never reached.

    Could you shed light on what I'm doing wrong? In essence, I just want a CEdit control to behave itself (like a good CEdit control should) and only be editable when it is present in the scrolled area.

    Thanks a lot in advance,
    Cheers!

  2. #2
    Join Date
    Jul 2002
    Posts
    2,514

    Re: Recording a particular "View" or "Area" during scrolling.

    Your post contains the code which never executed. Obviously, the problem is somewhere else, please post enough code to see what happens.

  3. #3
    Join Date
    Feb 2011
    Posts
    39

    Re: Recording a particular "View" or "Area" during scrolling.

    Quote Originally Posted by Alex F View Post
    Your post contains the code which never executed. Obviously, the problem is somewhere else, please post enough code to see what happens.
    Thanks for replying, Alex. The problem is that the above code is not being reached. My question is: What could be the condition I need to use to achieve the desired effect?

  4. #4
    Join Date
    Jul 2002
    Posts
    2,514

    Re: Recording a particular "View" or "Area" during scrolling.

    The condition is to fix the unknown bug in the code that you didn't post.

  5. #5
    Join Date
    Feb 2011
    Posts
    39

    Re: Recording a particular "View" or "Area" during scrolling.

    Quote Originally Posted by Alex F View Post
    The condition is to fix the unknown bug in the code that you didn't post.
    Alex, are you saying that the condition is flawless? I'd be extremely relieved if the error lay outside that because I've been raking my brains hard.

    I've actually posted all the relevant code there is to this problem. I could further elaborate on the structure of this code.

    There is a special function CreateFields(...) in an object of my custom class CEntry which contains the CEdit control. This is called by the child window when it is necessary to create the CEdit control.

    Code:
    //Create the required CEdit, CComboBox objects
    void CEntry :: CreateFields(CWnd* pHome, int nHScrollPos, int nVScrollPos)
    {
    	pParent = pHome;
    
    	nHScreenView = nHScrollPos;
    	nVScreenView = nVScrollPos;
    
    	ceTextIn[0].Create(ES_CENTER | WS_VISIBLE | ES_NOHIDESEL, crEntries[0], pParent, ID_TEXTFIELD);
    	ceTextIn[1].Create(ES_CENTER | WS_VISIBLE | ES_NOHIDESEL, crEntries[1], pParent, ID_TEXTFIELD);
    	ceTextIn[2].Create(ES_CENTER | WS_VISIBLE | ES_NOHIDESEL, crEntries[2], pParent, ID_TEXTFIELD);
    	ceTextIn[3].Create(ES_CENTER | WS_VISIBLE | ES_NOHIDESEL, crEntries[3], pParent, ID_TEXTFIELD);
    
    }
    //Done

    Then there is a function called HandleCEditMisbehaviour() which belongs to the child window which is tasked with the behaviour of said CEdit control upon scrolling.

    Code:
    //Stupid CEdit focus insecurities when scrolling and ****.
    void CMainChildWnd :: HandleCEditMisbehaviour()
    {
    	cNewEntry.TSaveEntry();
    
    	for(i=0; i<4; i++)
    		cNewEntry.ceTextIn[i].DestroyWindow();
    	cNewEntry.bfSelected = FALSE;
    	
    	if(m_nHScrollPos == cNewEntry.nHScreenView && m_nVScrollPos == cNewEntry.nVScreenView) /* cNewEntry is an instance of CEntry */
    	{
    		cNewEntry.CreateFields(this, m_nHScrollPos, m_nVScrollPos);
    
    		cNewEntry.ceTextIn[cNewEntry.nFieldNo].SetFocus();
    		cNewEntry.bfSelected = TRUE;
    	}
    }
    //Done
    The above function is called at the very end of OnVScroll and OnHScroll. I strongly doubt the possibility that the error may lie outside the above regions of code.

    But on another note, surely you have also dealt with this problem before? A CEdit control which hops along, screen after screen of scrolling past it's area. How could I achieve a clean solution?

    Thanks a lot.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center