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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:36:48+00:00 2026-06-04T07:36:48+00:00

I don’t know what title should I use, but please read this. I’m making

  • 0

I don’t know what title should I use, but please read this.

I’m making an program that displays the color at the mouse pointer location. I want to use WM_INPUT because WM_MOUSEMOVE is not update quickly enough.

Here’s some of my main code.

#include <Windows.h>
#include <WindowsX.h>

/* void Cls_OnInput(HWND hWnd, UINT inputCode, HRAWINPUT hRawInput) */
#define HANDLE_WM_INPUT(hWnd, wParam, lParam, fn) \
  ((fn)((hWnd), GET_RAWINPUT_CODE_WPARAM(wParam), (HRAWINPUT)(lParam)), 0L)

static LPCTSTR main_window_class_name = TEXT("MainWindow");
static HDC hdc_screen;
static COLORREF color;

LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
BOOL MainWindow_OnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct);
void MainWindow_OnDestroy(HWND hWnd);
void MainWindow_OnPaint(HWND hWnd);
void MainWindow_OnInput(HWND hWnd, UINT inputCode, HRAWINPUT hRawInput);

ATOM RegisterMainWindowClass(HINSTANCE hInstance)
{
  WNDCLASSEX wcex;

  wcex.cbSize = sizeof(wcex);
  wcex.style = 0;
  wcex.lpfnWndProc = MainWindowProc;
  wcex.cbClsExtra = 0;
  wcex.cbWndExtra = 0;
  wcex.hInstance = hInstance;
  wcex.hIcon = (HICON)LoadImage(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED);
  wcex.hCursor = (HCURSOR)LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED);
  wcex.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
  wcex.lpszMenuName = NULL;
  wcex.lpszClassName = main_window_class_name;
  wcex.hIconSm = wcex.hIcon;

  return RegisterClassEx(&wcex);
}

HWND CreateMainWindow(HINSTANCE hInstance)
{
  return CreateWindow(main_window_class_name, TEXT("WhatColor"), WS_CAPTION | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, HWND_DESKTOP, NULL, hInstance, NULL);
}

LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  switch (uMsg)
  {
    HANDLE_MSG(hWnd, WM_CREATE, MainWindow_OnCreate);
    HANDLE_MSG(hWnd, WM_DESTROY, MainWindow_OnDestroy);
    HANDLE_MSG(hWnd, WM_PAINT, MainWindow_OnPaint);
    HANDLE_MSG(hWnd, WM_INPUT, MainWindow_OnInput);
  default:
    return DefWindowProc(hWnd, uMsg, wParam, lParam);
  }
}

BOOL MainWindow_OnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct)
{
  RAWINPUTDEVICE rid[1];

  UNREFERENCED_PARAMETER(lpCreateStruct);

  rid[0].usUsagePage = 1;
  rid[0].usUsage = 2;
  rid[0].dwFlags = 0;
  rid[0].hwndTarget = hWnd;
  RegisterRawInputDevices(rid, 1, sizeof(rid[0]));

  hdc_screen = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);

  return TRUE;
}

void MainWindow_OnDestroy(HWND hWnd)
{
  UNREFERENCED_PARAMETER(hWnd);

  DeleteDC(hdc_screen);
  PostQuitMessage(EXIT_SUCCESS);
}

void MainWindow_OnPaint(HWND hWnd)
{
  static PAINTSTRUCT ps;

  BeginPaint(hWnd, &ps);
  EndPaint(hWnd, &ps);
}

void MainWindow_OnInput(HWND hWnd, UINT inputCode, HRAWINPUT hRawInput)
{
  static RAWINPUT raw_input;
  static UINT raw_input_size = sizeof(raw_input);
  static POINT point;

  UNREFERENCED_PARAMETER(inputCode);

  GetRawInputData(hRawInput, RID_HEADER, &raw_input, &raw_input_size, sizeof(raw_input.header));

  if (raw_input.header.dwType == RIM_TYPEMOUSE)
  {
    GetCursorPos(&point);
    color = GetPixel(hdc_screen, point.x, point.y);
    DeleteBrush(SetClassLong(hWnd, GCL_HBRBACKGROUND, (LONG)CreateSolidBrush(color)));
    InvalidateRect(hWnd, NULL, TRUE);
  }
}

The problem is the program seems to process WM_INPUT message again and again, and the main window is stuck. If I remove

color = GetPixel(hdc_screen, point.x, point.y);

the window is normal, but I can’t get the color I want.

I think it’s better if you try to test my code.

What should I do to fix this?

  • 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-04T07:36:49+00:00Added an answer on June 4, 2026 at 7:36 am

    I’ll use Timer and process WM_TIMER message instead.

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

Sidebar

Related Questions

I don't know which title I should use for this question. I have a
Don't really know how to formulate the title, but it should be pretty obvious
i don't know good title but heres the explain i have this link <a
Sorry if the title is not that specific, but I don't know how else
Sorry about the vague title, but I really don't know how to describe this
Sorry for the title but I don't know other way of asking. EDITED FOR
I don't know if I explained this in my title, this is what i
The title may be a little confusing, but I don't know how else to
The title might not be clear, but I don't know how else to put
Disclaimer Please don't just vote to close this because the title looks subjective, 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.