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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:59:01+00:00 2026-06-17T16:59:01+00:00

I know one can use SetWindowLongPtr + GWLP_USERDATA to store a pointer which points

  • 0

I know one can use SetWindowLongPtr + GWLP_USERDATA to store a pointer which points to some data.
But could one store the data directly, for example “a handle”, “a bool, an “int” or other larger data.

From http://msdn.microsoft.com/zh-tw/library/windows/desktop/ms644898%28v=vs.85%29.aspx, it says:

Sets new extra information that is private to the application, such as handles or pointers.

, so I guess to store a handle is OK. I also used this method to store an RGB value without problem.
But I don’t know if this is a good idea to do things like this. And can we store other data which is large (for example, a structure)?

p.s: The motivation of this question is: When I create a dialog window, I want to store data for each of its controls. Of course I can use static variables in the window procedure and pass pointer (to them) to SetWindowLongPtr function. But this is not “perfect” in theory, because when the dialog window is closed, I don’t need these data anymore. Of course, in practice, the data I need to use is very small, and I should not care about the usage of memory. But I still like to know if there is a better way.

  • 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-17T16:59:02+00:00Added an answer on June 17, 2026 at 4:59 pm

    The SetWindowLongPtr function can store a piece of data which has the same size as LONG_PTR (most likely 32bit or 64bit). If your data can be stored in that size, you’re fine. I.e. a bool would be fine, so would most handles (since handles tend to be pointers, too).

    A typical RGB value would work as well since it’s stored as three bytes (one byte per color component) or four bytes (an extra byte for the alpha channel).

    If you need more space than this, you should allocate a structure somewhere else and store a pointer to that structure.

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

Sidebar

Related Questions

In Xcode 4.2, I know that one can use the storyboard segue to have
Before somebody points me to that question, I know that one can't parse html
does any one know of any good countdown timer's for flash which i can
From code how can we know which interfaces one class implements? Example: interface IDrink
I know that ScrollView can have only one Child but in my case I
This one goes round and round I know but I can't seem to find
I know one can use '<alt><shift>J' to create tags for a single code element
I know one can use OR operator on regular expressions: $str = Here is
I know that one can use Pry to see what a model in composed
In Qt, when moving a QToolBar, one can use the QToolBar::topLevelChanged(bool) signal to know

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.