MAKEPOINTS structure (win32)

This is a discussion on MAKEPOINTS structure (win32) within the C++ Programming forums, part of the General Programming Boards category; I'm very new to C++ and am confused with how the MAKEPOINT structure works. POINTS MAKEPOINTS( DWORD dwValue // coordinates ...

  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,600
    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 09:45 PM.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

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, 09:52 AM
  5. C structure within structure problem, need help
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-30-2001, 04:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21