Thread: wndclass data questions

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    157

    wndclass data questions

    i was just thinking deeply about the WNDCLASS(EX) structure and i have a couple of remaining questions about the content of this struct. 1) what is the purpose and definition of the "cbClsExtra" field? 2) what is the purpose and definition of the "cbWndExtra" field?

    thanks.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Both of these variables allow you to append extra bytes to the end of the WNDCLASSEX structure for storing "user defined" data.
    I think the limit for both is 40 extra bytes, and keep in mind that the bytes are effectively cut into 4-byte chunks (ie: the size of a pointer ). As an example, the "button" class has I think 8 extra class bytes (a value that Windows itself set of course).

    So what good are extra bytes? Let's say that you want to store in every instance of a registered window class a pointer to an object. To retrieve that pointer, you use GetWindowLong(), and specify the offset, in bytes, that the pointer resides at in the extra window bytes. To change the pointer, just use SetWindowLong() in a similar fashion.

    Windows, in fact, appends a few of it's own extra bytes to your windows that you can use right away, without adding any yourself. The offset #defined by GWL_USERDATA is useful since it's unused by Windows. In addition there is the offset GWL_WNDPROC, (probably not an extra offset, but in fact your lpfnWndProc offset *within* the confines of the structure) which stores a pointer to your window procedure, and also offsets to the class/window styles you create instances of your windows with, such as WS_VISIBLE, etc, etc.

    The class extra bytes are of course accessed with GetClassLong()/SetClassLong().

    These two pairs of functions are your best friends, you should experiment with them and figure out what you can do with them.

    - Cheers.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    157
    is it useful to use these extra bytes, or do you most of the time just keep them set at 0?

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    For now, just set them to zero. If the need ever arises, you'll know what to do.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    157
    hehe okay, i see what you mean. as of now, i dont need to store any extra class/wnd information. thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Data structures basic questions
    By WarDoGG in forum C Programming
    Replies: 7
    Last Post: 07-11-2008, 09:42 AM
  3. Reading a file with Courier New characters
    By Noam in forum C Programming
    Replies: 3
    Last Post: 07-07-2006, 09:29 AM
  4. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM