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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:29:21+00:00 2026-05-17T16:29:21+00:00

I’ve been playing around with the Windows api for uni, but I cant get

  • 0

I’ve been playing around with the Windows api for uni, but I cant get the window messages to call WM_PAINT after the inital creation. It calls it when the window is created but not after.

All Other messages get called! Just cant get the WM_PAINT to be called.

This is part of a game lib we have to make using the Windows api, (the goal is to learn abit of the windows api, rather than the intricacies of making game libs).

From what I gather the UpdateWindow(handle) command calls inititates the WM_PAINT message, but no matter where I put this command (currently in the game loop) I cant get it to call the message.

There’s a lot of code, so I’ve trimmed it a little.

I know I have multiple WM_PAINT cases, they are a result of trying to make sure its getting through.

Window Creation
HWND hwnd;

    hwnd = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE,
        L"FirstWindowClass",
        L"Mootlib",
        WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        m_screenWidth,
        m_screenHeight,
        NULL,
        NULL,
        WindowsUtilities::windowInstance(),
        NULL);

Register the Window

    WNDCLASSEX  wcex;                                   

    wcex.cbSize        = sizeof (wcex);             
    wcex.style         = CS_HREDRAW | CS_VREDRAW;       
    wcex.lpfnWndProc   = windowProc;
    wcex.cbClsExtra    = 0;                             
    wcex.cbWndExtra    = 0;                             
    wcex.hInstance     = WindowsUtilities::windowInstance();
    wcex.hIcon         = 0; 
    wcex.hCursor       = LoadCursor (NULL, IDC_ARROW);  

    wcex.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
    wcex.lpszMenuName  = NULL;                          
    wcex.lpszClassName = L"FirstWindowClass";               
    wcex.hIconSm       = 0; 

    RegisterClassEx (&wcex);

Winproc

    LRESULT CALLBACK windowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        LONG_PTR lptr = GetWindowLongPtr(hwnd, GWLP_USERDATA);

        switch(message)
        {
        case(WM_PAINT):
            int f = 3;
        }

        if (lptr)
        {
            Window* obj = reinterpret_cast<Window*>(lptr);
            return obj->handleWindowsMessages(message, wParam, lParam);
        }
        else
            return DefWindowProc(hwnd, message, wParam, lParam);
    }

Internal command

LRESULT Window::handleWindowsMessages(UINT message, WPARAM wParam, LPARAM lParam)
{

    std::wstring szHello = L"Hello, world!";
    PAINTSTRUCT ps;
    HDC hdc;

    switch(message)
    {
    case(WM_PAINT):
        hdc = BeginPaint(m_handle, &ps); 
        TextOut(hdc, 0, 0, L"Hello, Windows!", 15); 
        EndPaint(m_handle, &ps); 
        return 0; 

    case(WM_CLOSE):
        quitGame();
        return 0;

    // Move Me!!!
    case(WM_KEYDOWN):
    case(WM_LBUTTONDOWN):
    case(WM_RBUTTONDOWN):
        inputManager().addButtonEvent(reinterpret_cast<int&>(wParam), BUTTON_DOWN);
        return 0;

    // Move Me!!!
    case(WM_KEYUP):
    case(WM_LBUTTONUP):
    case(WM_RBUTTONUP):
        inputManager().addButtonEvent(reinterpret_cast<int&>(wParam), BUTTON_UP);
        return 0;   
    }

    return DefWindowProc(handle(), message, wParam, lParam);
}

Game Loop

        while(IsWindowVisible(handle()))
        {
            UpdateWindow(handle());
            WindowsUtilities::processMessages();

            draw();
            update();

            inputManager().update();
            inputManager().clearButtonUpEvents(); // this should be in the input update()
        }

Thanks.

  • 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-17T16:29:21+00:00Added an answer on May 17, 2026 at 4:29 pm

    First, I really don’t like your game loop as its not at all obvious where the windows message pump is.

    Somewhere along the line you need to call PeekMessage() or GetMessage() and TranslateMessage() & DispatchMessage() on any messages retrieved. Lots of people unfamiliar with windows will filter the messages, either in a range, or for a window: don’t – always pump all messages for all windows on the current thread.

    Then you need to call InvalidateRect to mark the areas of the window you want repainted. Games will want to pass FALSE as getting the background painted is just a waste of time when youre painting the entire scene in WM_PAINT.

    RedrawWindow is useful for a game if you just want to mark an entire part of the window dirty and repaint it in one step. The advantage of InvalidateRect is that it just adds the rectangle to a dirty region, so if your game consists of just a few small ‘active’ sprites, as each sprite animates you can mark just the corresponding rect dirty, and windows will collect the dirty rects and paint them in a batch when next you call UpdateWindow, or let the message loop generate a WM_PAINT message.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to count how many characters a certain string has in PHP, but
I'm looking for suggestions for debugging... If you view this site in Firefox or
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.