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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:58:35+00:00 2026-05-15T01:58:35+00:00

I am attempting to learn about creating windows in c++, I have looked at

  • 0

I am attempting to learn about creating windows in c++, I have looked at an article about creating a wrapper class but I don’t really understand it. So far I know that you can’t have a class method WndProc (I dont know why) but honestly, that is all. Can somebody give an explanation, also explaining the reinterpret_cast? Here is the article.

LRESULT CALLBACK Window::MsgRouter(HWND hwnd, UINT message,
                                   WPARAM wparam, LPARAM lparam)
{
  Window *wnd = 0;

  if(message == WM_NCCREATE)
  {
    // retrieve Window instance from window creation data and associate
    wnd = reinterpret_cast<Window *>((LPCREATESTRUCT)lparam)->lpCreateParams;
    ::SetWindowLong(hwnd, GWL_USERDATA, reinterpret_cast<long>(wnd));

    // save window handle
    wnd->SetHWND(hwnd);
  }
  else
    // retrieve associated Window instance
    wnd = reinterpret_cast<Window *>(::GetWindowLong(hwnd, GWL_USERDATA));

  // call the windows message handler
  wnd->WndProc(message, wparam, lparam);
}

Thanks in advance, ell.

  • 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-15T01:58:36+00:00Added an answer on May 15, 2026 at 1:58 am

    The MsgRouter() procedure acts as a proxy between the Windows message handling system to the Window instance associated with a HWND. It routes Windows messages to C++ objects.

    A pointer to the Window instance is passed to the MsgRouter() procedure via the last parameter of the CreateWindow() function. When you first create a HWND via CreateWindow() (or CreateWindowEx()), some messages are sent – one of them being WM_NCCREATE. When the procedure receives a WM_NCCREATE message, the LPARAM parameter contains a pointer to a CREATESTRUCT which contains the arguments that was passed into the CreateWindow() function. The procedure retrieves the Window instance pointer from the CREATESTRUCT and saves it in the HWND by setting it as an attribute of the HWND (GWL_USERDATA via SetWindowLong()).

    Now that the pointer has been saved, the window procedure can from now on retrieve a pointer to the original Window instance from a HWND via GetWindowLong() when it receives a message. Finally, the window procedure calls WndProc() on the retrieved Window pointer, passing in the exact message and parameters, so the Window instance can handle the message.

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

Sidebar

Related Questions

I've got to admit, I really don't much about HTML, but I'm attempting to
I'm attempting to learn Scala so I have decided to implement datastructures with it.
I'm trying to learn python and I'm attempting a hangman game. But when I
I am attempting to learn how to develop on the Android platform but do
I'm following this tutorial attempting to learn XNA, but I'm having issues making my
I'm following this tutorial , attempting to learn a bit about iPhone development, and
I am attempting to implement Heap sort in my program to learn more about
I am attempting to learn php and I am at a really early stage!
I'm attempting to learn Ruby on Rails by creating a project and I can't
I'm attempting to learn a little more about handling sockets and network connections in

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.