Thread: MAKEPOINTS structure (win32)

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    7

    MAKEPOINTS structure (win32)

    I'm very new to C++ and am confused with how the MAKEPOINT structure works.
    POINTS MAKEPOINTS(
    DWORD dwValue // coordinates of a point
    );
    The definition of dwValue is as follows:
    Specifies the coordinates of a point. The x-coordinate is in the low-order word, and the y-coordinate is in the high-order word.
    What are low and high order words? How do I create an instance of MAKEPOINTS with 10, 10?

    Thanks for your patience.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    If you want a POINTS struct with 10, 10 just do it like any other structure:
    Code:
    POINTS pts;
    
    pts.x = 10;
    pts.y = 10;
    or, even easier:
    Code:
    POINTS pts = { 10, 10 };
    The MAKEPOINTS macro is a helper macro that can be used with certain window messages. For example the WM_RBUTTONDOWN passes an x, y value in the lParam:
    Quote Originally Posted by MSDN WM_RBUTTONDOWN
    lParam
    The low-order word(the lower 16 bits) specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.

    The high-order word(the upper 16 bits) specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.
    Now, instead of extracting the x,y values manually, we can just use the MAKEPOINTS macro.
    Code:
    int x = MAKEPOINTS(lParam).x;
    int y = MAKEPOINTS(lParam).y;

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    it's not a structure, it's a macro that cast a pointer to a 4 byte integer into a pointer to a POINTS structure (consisting of 2, 2 byte integers).

    >> #define MAKEPOINTS(l) (*((POINTS FAR *)&(l)))

    it's mainly useful for when your window procedure passes you coordinates in the LPARAM variable.

    you can make your own variable like: LPARAM p = MAKELONG(x, y);

    note that the cast is guaranteed to work since the POINTS structure is aligned to single-byte boundaries - other structures you must be careful with similar cast hacks.

    [edit]
    foiled!
    [/edit]
    Last edited by Sebastiani; 12-22-2004 at 10:45 PM.
    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;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem referencing structure elements by pointer
    By trillianjedi in forum C Programming
    Replies: 19
    Last Post: 06-13-2008, 05:46 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 03:26 PM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  5. C structure within structure problem, need help
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-30-2001, 05:48 PM