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

  • SEARCH
  • Home
  • 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 7076935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:21:33+00:00 2026-05-28T06:21:33+00:00

I’m trying to learn how to use and receive raw input messages, and so

  • 0

I’m trying to learn how to use and receive raw input messages, and so I devised the following program to test my understanding so far…

When I recieve the input message, I try to change the string which is displayed and place a new WM_PAINT message on the queue. But this message doesn’t seem to get called. Only when I resize the window does the text appear different.

Why is the WM_PAINT message not getting processed at all, until I resize the window for example?

#define _WIN32_WINNT 0x501
#include <Windows.h>
#include <assert.h>
#include <cstring>
#include <cstdio>

LRESULT CALLBACK WinProcedure(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);

int WinMain(HINSTANCE hInst,HINSTANCE,LPSTR,int nCmdShow)
{
    WNDCLASS wc;
    HWND hwnd;

    wc.hInstance = hInst;
    wc.lpfnWndProc = WinProcedure;
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOWFRAME;
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "Untitled";

    if (!RegisterClass(&wc)) {
        // Error registering class
        return -1;
    }

    if (!(hwnd = CreateWindow(wc.lpszClassName, wc.lpszClassName, WS_OVERLAPPEDWINDOW, 
                    CW_USEDEFAULT,CW_USEDEFAULT,500,300,NULL,NULL,hInst,NULL))) {
        // Error creating window
        return -1;
    }

    ShowWindow(hwnd,nCmdShow); 
    UpdateWindow(hwnd);

    RAWINPUTDEVICE Rid[1];

    Rid[0].usUsagePage = 0x01; 
    Rid[0].usUsage = 0x06; 
    Rid[0].dwFlags = 0;   // adds HID keyboard and also ignores legacy keyboard messages
    Rid[0].hwndTarget = 0;

    if (RegisterRawInputDevices(Rid, 1, sizeof(Rid[0])) == FALSE) {
        return -5;
    }

    MSG msg;
    while (GetMessage(&msg,NULL,0,0) > 0) 
    { 
        TranslateMessage(&msg); 
        DispatchMessage(&msg); 
    }
    return 0;
}

LRESULT CALLBACK WinProcedure(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
    static char buffer[5000] = "hi";

    if (msg == WM_PAINT) {
        PAINTSTRUCT ps; 
        HDC dc; 
        RECT r; 
        GetClientRect(hwnd,&r); 
        dc=BeginPaint(hwnd,&ps); 
        DrawText(dc,buffer,-1,&r,DT_SINGLELINE|DT_CENTER|DT_VCENTER); 
        EndPaint(hwnd,&ps);
        return 0;
    }

    if (msg == WM_INPUT) {
        strcpy(buffer, "Recieved input.");
        //assert(false);
        PostMessage(hwnd, WM_PAINT, wparam, lparam);
        return 0;
    }

    if (msg == WM_DESTROY) {
        PostQuitMessage(0);
        return 0;
    }

    return DefWindowProc(hwnd, msg, wparam, lparam);
}
  • 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-28T06:21:34+00:00Added an answer on May 28, 2026 at 6:21 am

    If you take a look at the documentation for the WM_PAINT message, it says very clearly:

    The WM_PAINT message is generated by the system and should not be sent
    by an application.

    If something doesn’t work the way you expect, consult the documentation first. There’s a reason why they exist. Use them to your advantage.

    The reason why just posting WM_PAINT doesn’t work because there’s way more to painting than just sending a WM_PAINT message. The system sets up the proper structures to allow the application to paint on the window, among other things, for example. Sending WM_PAINT to a window is only a samll part of the entire painting process.

    What you probably want is the InvalidateRect() function, which tells the operating system that you want to repaint a certain region of a window. The OS then does the proper painting procedure.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

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.