Solved

LOWORD/HIWORD vs GET_X_LPARAM/GET_Y_LPARAM and MAKELONG vs MAKELPARAM

Posted on 2013-11-28
3
1,379 Views
Last Modified: 2013-11-29
Hi!

While searching for something else, I ran across the statement that in Windows functions interpreting coordinates, one should use GET_X_LPARAM/GET_Y_LPARAM instead of LOWORD/HIWORD on the lParam parameter. Also it seems one should use MAKELPARAM instead of MAKELONG.

I do understand the difference, but feel a little uncertain about the benefits and pitfalls by simply replacing:

- LOWORD -> GET_X_LPARAM
- HIWORD -> GET_Y_LPARAM
- MAKELONG -> MAKELPARAM

in all of my company's code.

First about the need to do this: is it correct that the only problem with not changing this is that things might (or certainly will?) not work if your multiple monitor setup is different from having the main monitor to the left and others as extensions to the right of it?

Or does it even then work as long as you avoid some very specific functions?

Then to the pitfalls: if we simply do the replacements above in all our code, is there any reason to believe something that works correct now doesn't work the same afterwards?

I am guessing not, but I would like to be very sure before I suggest such a change in all our code.

Thank you for any insight into this!
0
Comment
Question by:khun
3 Comments
 
LVL 51

Accepted Solution

by:
Ted Bouskill earned 250 total points
ID: 39684757
It will definitely cause problems with many functions if there are multiple monitors.  There is no harm to making the change.  I'd do it.
0
 
LVL 33

Assisted Solution

by:sarabande
sarabande earned 250 total points
ID: 39684806
#define GET_X_LPARAM(lp)  ((int)(short)LOWORD(lp))

Open in new window

in vs2010 both macros are identically beside that the result is int or short. because of that you could use the GET_X_LPARAM if you don't use short (16-bit) integers.

generally all those macros are helpers only. you can trust that for existing API the results will not change. for new api things are different. for example LPARAM turned to a 64-bit integer type what allows to pass a 64-bit pointer (address). for newer code you probably would avoid bit masking and pass pointers or handles which may point to larger objects and structures. then you would not use those macros at all but use your own functions to resolve the parameters.

Sara
0
 
LVL 8

Author Comment

by:khun
ID: 39684865
Actually, I have now tested with some weird 2 monitor setups and confirmed that HIWORD/LOWORD don't work correctly! I'll go for a global replace in all our code.

Thanks for the input reassuring me that this is risk free and necessary!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now