Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7932653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:04:52+00:00 2026-06-03T21:04:52+00:00

I followed an example in Charles Petzold’s book Programming Windows. That example shows the

  • 0

I followed an example in Charles Petzold’s book “Programming Windows”. That example shows the keyboard message when keyboard event occurs. It scrolls automatically to show the display. Here is part of the code (with some small modification). The problem is that: normally, when a keyboard message is received, it should display 0 at the bottom. When another keyboard message is received, it scrolls down by a line, display 0 at the bottom, and above the bottom, it should display 1.
But what I have is that it displays always 0. Only when I resize the window, I get the correct result like: …. 4, 3, 2, 1, 0. I think the problem is that something is not repainted when it called ScrollWindow, but I don’t know what’s exactly the problem, since I followed the book.

    case WM_SIZE:

        if (message == WM_SIZE)
        {   cxClient = LOWORD (lParam);
            cyClient = HIWORD (lParam);
        }

        // Calculate scrolling rectangle

        rectScroll.left   = 0;
        rectScroll.right  = cxClient;
        rectScroll.top    = cyChar;
        rectScroll.bottom = cyChar * ( cyClient / cyChar);

        InvalidateRect(hwnd, NULL, TRUE);

        return 0;

    case WM_KEYDOWN:
    case WM_KEYUP:
    case WM_CHAR:
    case WM_DEADCHAR:
    case WM_SYSKEYDOWN:
    case WM_SYSKEYUP:
    case WM_SYSCHAR:
    case WM_SYSDEADCHAR:

        for ( i = cLinesMax - 1; i > 0 ; i-- )
        {
            pmsg[i] = pmsg[i - 1];
        }

        // Store new message

        pmsg[0].hwnd    = hwnd;
        pmsg[0].message = message;
        pmsg[0].wParam  = wParam;
        pmsg[0].lParam  = lParam;

        cLines = min(cLines + 1, cLinesMax);

        // Scroll up the display

        ScrollWindow(hwnd, 0, -cyChar, &rectScroll, &rectScroll);

        break; // call DefWindowProc so System messages work

    case WM_PAINT:

        hdc = BeginPaint(hwnd, &ps);

        for (i = 0; i < min(cLines, cyClient / cyChar - 1); i++)
        {
            TextOut(hdc, 0, (cyClient / cyChar - 1 - i) * cyChar, szBuffer,
                    wsprintf(szBuffer, TEXT("%5d"), i));

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:04:53+00:00Added an answer on June 3, 2026 at 9:04 pm

    The whole point of ScrollWindow() is to move the existing contents of a window without needing to repaint everything. The fundamental assumption is that the content that is moved does not change as a result of the scrolling action, and only the “uncovered” region needs to be painted.

    In your example you want to change the content (by renumbering the lines), not just move it. That means it needs to be redrawn – which the ScrollWindow() in your key message processing doesn’t cause, but the InvalidateRect() in your WM_SIZE handler does.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I followed an example from the following url that shows how to use the
I appear to have followed this example (found under Defining Your Own Event Class)
I want to replace char '&' if it's not followed by '#'. For example
I've just followed this example from Wordpress and I have successfully added an extra
I am attempting to use the TouchXML library and followed the example with the
I have been trying to register 3 hotkeys. I followed this example (or this
I followed the example in the Android website to create a tab activity with
I have followed the example in for the gradient dividers: http://www.connorgarvey.com/blog/?p=34 I have tried
I am new to PHP+MySQL and followed an example to build a web page.
I checked out the following thread and followed the example to try and bind

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.