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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:20:47+00:00 2026-05-18T08:20:47+00:00

In Windows, suppose you have multiple windows (HWNDs) of the same window class open.

  • 0

In Windows, suppose you have multiple windows (HWNDs) of the same window class open. How do you keep track of the context data in the window procedure so that, for example, window 1 does not get modified when the user tried to type in window 2?

CreateWindow() does not return until after the WndProc() has been called several times, so you can’t simply set the resulting HWND to the context data and do a lookup in the WndProc(); you do need to set it in the WndProc().

WndProc() doesn’t directly have the context information passed to it except on window creation messages, but unfortunately window creation messages aren’t exactly the first messages to be passed to WndProc(). Nay, I find things such as WM_SIZE, WM_NCSIZE, and even some others are passed before I ever see WM_CREATE.

Storing the HWND in a linked list type of storage mechanism would be inefficient with large amounts of windows: each control in a window is simply another type of window and therefore another HWND of which you need to keep track; after a few hundred controls, searching the linked list for the HWND will be a major bottleneck in the program after a few dozen messages are passed to the program in a short amount of time!

From what I hear, some people use SetWindowLong() – but I also hear that some libraries like to use that too to store their own context information separate from the program and that window data collisions can sometimes occur. How can that be avoided?

  • 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-18T08:20:48+00:00Added an answer on May 18, 2026 at 8:20 am

    if I’m understanding you correctly, you want to avoid one window to catch the messages from another. One way to avoid this is to use the solution proposed in this thread, which keeps track of the windows that is created by you and makes sure that the correct windows gets the messages associated to it by storing the pointer for the caller in the GWL_USERDATA .

    // ...
    m_hWnd = CreateWindowEx(0,"Classname","Title",WS_OVERLAPPEDWINDOW,
                            CW_USEDEFAULT,CW_USEDEFAULT,
                            320,200,NULL,NULL,hInstance, /*the magic pointer*/ this);
    
    // ...
    
    if(uMsg == WM_CREATE)
    {
        // collected here..
        pParent = (CWindow*)((LPCREATESTRUCT)lParam)->lpCreateParams;
        // .. and then stored for later lookup
        SetWindowLongPtr(hWnd,GWL_USERDATA,(LONG_PTR)pParent); 
    }
    // ...
    

    You can also catch the WM_NCCREATE message, as proposed by Moo-Juice.
    And I don’t think you should worry about the messages pre-WM_CREATE, because the window isn’t even fully initialized at that point. If you need to set text you do that after the call to CreateWindow(Ex), be it user input or a SendMessagecall.

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

Sidebar

Related Questions

Suppose multiple Modal Windows shown above each other. All of those have ShowInTaskbar =
Suppose I have this Windows wchar_t string: L\x4f60\x597d and L\x00e4\x00a0\x597d and would like to
Suppose I have two branches of a project IMClient-MacOS and IMClient-Windows, and their code
Suppose I have some XAML like this: <Window.Resources> <v:MyClass x:Key=whatever Text=foo\nbar /> </Window.Resources> Obviously
Suppose some Windows service uses code that wants mapped network drives and no UNC
Windows Forms allows you to develop Components, non-visual elements that can have a designer.
I have the code below: namespace WindowMover { using System.Windows.Forms; static class Logic {
Suppose you have a script that takes a couple of command-line arguments and dumps
Suppose I have the following hierarchy: class A { public: A() private: int aa;
Suppose user has opened my web application in many different browser windows. After sometime

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.