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 7585769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:15:16+00:00 2026-05-30T19:15:16+00:00

The Code I have this problem, I am trying to create a simple rectangle

  • 0

The Code

I have this problem, I am trying to create a simple rectangle that moves with the arrow keys ( just to test out the abilities of the Graphics Device Interface ).

/** NOT IMPORTANT **/
// -------------------------------------------------- //
/* Globals (hey, its just a test program!) */
static int x = 0;
static int y = 0;

/** MAINLOOP **/

// All classes are just simple wrapper
// code in /* comments */ shows what the class methods internally do.

Graphics g;      // HDC Wrapper
g.GetGraphics( winmodel.GetHandle() ); /* ::GetDC( hwnd ); */

HWND hwnd = winmodel.GetHandle();

// IMPORTANT PART //
//-------------------------------------------//
while(TRUE)
{
    // PROBLEM HERE!!!
    ::InvalidateRect( hwnd, NULL, 0 ); // NOT WORKING??
    ::UpdateWindow( hwnd ); // NOT WORKING??

    if( msg.Peek(NULL,0,0,PM_REMOVE) ) /* PeekMessage() */
    {
        msg.Translate(); /* ::TranslateMessage() */
        msg.Dispatch(); /* ::DispatchMessage() */
    }

    g.Rectangle( x, y, x + 100, y + 100); /* GDI's ::Rectangle() Function */
    fpsHandler.Tick(); /* while( ( GetTickCount() - start_time ) < 33 ); */
}

g.Release(); /* ::ReleaseDC( hwnd ); */


// NOT IMPORTANT //
// --------------------------------------------------------//
/** IN WNDPROC **/

// in WM_KEYDOWN
 case VK_LEFT:
       x--;
       break;
 case VK_RIGHT:
       x++;
       break;
 case VK_UP:
       y--;
       break;
 case VK_DOWN:
       y++;
       break;

The Problem

Now my problem is that when the rectangle leaves a place, that place remains black ( maybe it isn’t redrawn? ), as can be seen:

Not Redrawing?

However the black part disappears when I minimize the window and load it again, hence obviously a redraw issue. But why isn’t it redrawing when I used InvalidateRect and UpdateWindow ? I even tried ::SendMessage( hwnd, WM_PAINT, NULL, NULL ); to no avail. What is the problem?

  • 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-05-30T19:15:17+00:00Added an answer on May 30, 2026 at 7:15 pm

    It looks as though you are trying to code the main functionality of your app in its main loop.

    This is a design mainly used in full screen games. A more mainstream approach is:

    • A generic event loop (default processing for each event)
    • A wndproc for your window
    • in this wndproc, you handle events, including the paint event. Dont forget to paint the entire window.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an erlang problem, it seems. I have this code to test the
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I'm trying to create simple DER decoder - console application that just outputs content
I have been trying to create a simple application that will let the user
Hello Guys! I have been trying to create a simple sample code for my
I am trying to create a simple parser/lexer, my problem is I have to
Never thought I'd have this problem :) The following snippet of code works in
I have this code, but I have a problem. When I update but do
Problem Hello all! I have this code which takes my jpg image loops through
I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script

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.