CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2017
    Posts
    8

    What does mean: lParam | 0x80000000 in a WM_LBUTTONDOWN

    Hello everyone,
    as the title, what does lParam | 0x80000000 mean in a WM_LBUTTONDOWN?
    I know that HI e LO lparam words specifies cursor coordinates, but what does it mean if I use an OR bitwise operator with 0x80000000?

    Thank you

  2. #2
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: What does mean: lParam | 0x80000000 in a WM_LBUTTONDOWN

    Are you using multiple monitors? The lo-order word specifies the x co-ord and the hi-order word specifies the y co-ord. These are signed values so LOWORD and HIWORD shouldn't be used to extract them as these treat the extraction as unsigned - use GET_X_LPARAM() and GET_Y_LPARAM(). The extracted hi-word and lo-word need to be treated as signed short - as systems with multiple monitors can have negative x and y co-ords. See https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    May 2017
    Posts
    8

    Re: What does mean: lParam | 0x80000000 in a WM_LBUTTONDOWN

    Quote Originally Posted by 2kaud View Post
    Are you using multiple monitors? The lo-order word specifies the x co-ord and the hi-order word specifies the y co-ord. These are signed values so LOWORD and HIWORD shouldn't be used to extract them as these treat the extraction as unsigned - use GET_X_LPARAM() and GET_Y_LPARAM(). The extracted hi-word and lo-word need to be treated as signed short - as systems with multiple monitors can have negative x and y co-ords. See https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
    Thank you for your answer,
    the problem is that I don't understand the use of bitwise operator "or" (| 0x80000000)

  4. #4
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: What does mean: lParam | 0x80000000 in a WM_LBUTTONDOWN

    Why do you want to use the bitwise operator with lparam? You extract the x and y co-ords as
    Code:
    short xPos = GET_X_LPARAM(lParam); 
    short yPos = GET_Y_LPARAM(lParam);
    You don't need to directly manipulate lparam.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    May 2017
    Posts
    8

    Re: What does mean: lParam | 0x80000000 in a WM_LBUTTONDOWN

    I think that too, but I found this operation in an example without any comment, and so I would like to know what does it mean

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: What does mean: lParam | 0x80000000 in a WM_LBUTTONDOWN

    Technically this sets the leftmost bit. But what use the code makes of it totally depends on the code. The code is at your disposal, so read it and see the use. Or show the code here and let us comment on it.
    Best regards,
    Igor

  7. #7
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: What does mean: lParam | 0x80000000 in a WM_LBUTTONDOWN

    It means its setting the MSB of lParam (bit 32). For a signed number, the MSB is the sign bit so it is creating a negative number. As a negative number is stored as 2's complement, what this number actually is depends upon what is in the other bit positions - and whether it is being treated as a 32 bit or 2 16 bit numbers. Alternatively, it might have nothing to do with being a negative number but is some special flag that is used by the program. How is lParam used elsewhere in the program?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: What does mean: lParam | 0x80000000 in a WM_LBUTTONDOWN

    Quote Originally Posted by 2kaud View Post
    it might have nothing to do with being a negative number but is some special flag that is used by the program.
    That exactly was my thought.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured