CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2012
    Posts
    6

    Question ScrollWindowEx not repeating

    Hello,

    I'm writing a screensaver that scrolls text horizontally. It works almost as expected except it does not repeat. The text will scroll once and then the screen shows nothing. The code is still running. I'm using a timer to control the speed. Is there a way to get it to repeat, reset or something like that? Code looks like this:

    void MyWnd::OnPaint()
    {
    if (theTimer.Expired())
    {
    CRect test;
    theTimer.Reset();

    CFont font;
    CPaintDC dc(this);
    font.CreatePointFont(200,_T("Arial"),&dc);
    dc.SelectObject(&font);
    dc.SetTextColor(RGB(0,255,255));
    dc.SetBkColor(RGB(0,0,255));

    myView.left = rect.left + 400;
    myView.top = rect.top + 50;
    myView.bottom = myView.top + 100;
    myView.right = 1000;

    dc.DrawTextExA(str,myView,DT_NOCLIP|DT_MODIFYSTRING|DT_WORDBREAK,NULL);

    this->ScrollWindowEx(-1,0,rect,rect,NULL,test,SW_INVALIDATE);
    this->UpdateWindow();

    }

    Thanks in advance!

  2. #2
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: ScrollWindowEx not repeating

    Isn't it obvious that your myView.left, top, bottom and right values go beyond the screen ordinates after a while ?

    Have you tried debugging this code?
    Regards,
    Ramkrishna Pawar

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: ScrollWindowEx not repeating

    Quote Originally Posted by rfirtion View Post
    ... Code looks like this:

    Code:
    void MyWnd::OnPaint()
    {
        if (theTimer.Expired())
        {
            [hl]CRect test;[hl]
            theTimer.Reset();
    
            CFont font;
            CPaintDC dc(this);
            font.CreatePointFont(200,_T("Arial"),&dc);
            dc.SelectObject(&font);    
            dc.SetTextColor(RGB(0,255,255));
            dc.SetBkColor(RGB(0,0,255));
    
            myView.left = rect.left + 400;
            myView.top = rect.top + 50;
            myView.bottom = myView.top + 100;
            myView.right = 1000;
    
            dc.DrawTextExA(str,myView,DT_NOCLIP|DT_MODIFYSTRING|DT_WORDBREAK,NULL);
    
            this->ScrollWindowEx(-1,0,rect,rect,NULL,test,SW_INVALIDATE);
            this->UpdateWindow();
     
    }
    1. You are using undeclared variable 'rect'
    2. You are using undeclared variable 'myView'
    3. CRect test is used without initialiyation.
    Victor Nijegorodov

  4. #4
    Join Date
    Mar 2012
    Posts
    6

    Re: ScrollWindowEx not repeating

    Everything is initialized elsewhere.

    Of course I tried debugging the code! In fact, I tried to determine when the window moved off the screen. From what I understand, ScrollWindowEx just takes a snapshot of the window and moves the snapshot across the window. So, the coordinates of the window weren't changing. Is there a way to determine when the window goes off the screen using ScrollWindowEx?

    I am currently calling RedrawWindow after a certain amount of time but, obviously it would be much better to know when ScrollWindowEx has moved the image off the screen.

    Any thoughts would be appreciated.

    Thanks!

  5. #5
    Join Date
    Jan 2009
    Posts
    596

    Re: ScrollWindowEx not repeating

    Quote Originally Posted by rfirtion View Post
    Of course I tried debugging the code! In fact, I tried to determine when the window moved off the screen. From what I understand, ScrollWindowEx just takes a snapshot of the window and moves the snapshot across the window. So, the coordinates of the window weren't changing. Is there a way to determine when the window goes off the screen using ScrollWindowEx?
    ScrollWindowEx does not remember what you asked it to do in the past - so you can't use it directly to do this.

    You will need to keep track of how far you have scrolled the window in a variable somewhere. Update this variable after each call to ScrollWindowEx. Then you can use it to determine when the result of the cumulative calls to ScrollWindowEx is such that the entire window has been scrolled off the screen.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured