Solved SAM_ContextMenu fails on multimonitor setup (+workaround)

Report bugs and possible workarounds for ANSI TD versions
Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3218
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

SAM_ContextMenu fails on multimonitor setup (+workaround)

Post by Dave Rabelink » 18 May 2012, 08:00

Issue on all TD versions !
(Tested on TD15, TD42 and TD6x)

See help on SAM_ContextMenu (excerpt) :
wParam X coordinate in screen pixels relative to the upper left corner of the screen.
lParam Y coordinate in screen pixels relative to the upper left corner of the screen.
When using a specific multimonitor setup, this message will not give the correct coordinates.
If the setup has the main monitor at the right, the second monitor will have negative X and Y coordinates.

See screenshot setup:
MonitorSetup.png
(by dragging the main (1) monitor and placing them in the order like in the screenshot)

Then, when a window is placed on the second monitor, SAM_ContextMenu does not give the correct x and y coordinates.

In fact, the message gives exactly what WM_CONTEXTMENU gives. Which means here, the Low and High values of lParam.
And this is wrong. The SAM message should convert the values correctly. I suspect that it does no conversion at all !!!

See docs on WM_CONTEXTMENU:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx

But the Low and High values are non-signed packed integers. This means that a negative number will be coded as a positive number using two's complement.
And looking at the docs on WM_CONTEXT menu, the X and Y coordinates are:
xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam);
Look at the sample testcase:
Sample.png
(the window is placed on the second monitor here, so the coordinates are negative for X positions and positive for Y positions)

As can be seen, the wParam and lParam of SAM_ContextMenu are the same as for the Low and High lParam values of WM_CONTEXTMENU.
So this proves that SAM_ContextMenu is not converting the values to signed numbers but gives the values 1:1.
And that is wrong !!!!

The purpose of this sample is to right-click on the listbox items and show the index of the clicked item in the datafield below.
Just by using the x and y positions SAM_ContextMenu provides, the sample will fail when the window is placed on the second monitor.
The checkbox "Use real pos" will enable the workaround for this issue: it will convert the unsigned two's complement to the real signed values.

And then the issue is fixed.

This defect seems to be in the TD product for ages.
But it needs to be fixed. Unify can do this by adding the GET_X_LPARAM and GET_Y_LPARAM macro's to the internal SAM_ContextMenu code.
Or change the documentation to indicate that the wParam and lParam are NOT the x and y coordinates, but need to be converted to signed numbers first before use.

Testcase is saved as TD15 text format.
SAM_ContextMenu_Issue.zip
You do not have the required permissions to view the files attached to this post.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Jeff Luther

Re: SAM_ContextMenu fails on multimonitor setup (+workaround)

Post by Jeff Luther » 16 Aug 2012, 23:29

I guess I didn't hear anything back. I would have replied to this thread if I had.

Well, I was going to ask but thought I'd try your test case again. I don't see a problem:
I guess I didn't hear anything back. I would have replied to this thread if I had. I'll have to ask again.
jl_resultsOn2ndary-monitor.png
That's your window with my Ext. Monitor/notebook swapped so the notebook (to my physical right) is 'Main' and the Ext. Monitor (physically in front of me) are swapped and that form has been moved to the Ext. Monitor/secondary monitor.

How about testing again and condensing down the issue you think you still have, if any. If I can understand and duplicate it I can ask internally.
You do not have the required permissions to view the files attached to this post.

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 3218
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: SAM_ContextMenu fails on multimonitor setup (+workaround)

Post by Dave Rabelink » 17 Aug 2012, 06:28

Well ok.

One thing I can make up from your latest screenshot is that the cursor position when you right-clicked the listbox item is at position x=2550.
This means that the monitor which the window is located on is on the right of the main monitor.
So:

Monitor1 (main)
Monitor2 (at right side)

This is because it has a positive value. Only monitors starting from x=0 and up are the main monitor and the monitors to the right of that main monitor.

This means that you did not correctly setup your system so that the testcase fails.

You should try to get the value in datafield "Real x-pos" to a negative (-) value.

Explanation:
The main monitor has x positions 0..[max resolution]. Depending on your resolution setting of this monitor (eg 1280x1024) it could be 0..1280.
Now, all monitors situated at the right from the main monitor will have positive x positions.
All monitors situated at the left from the main monitor will have negative x positions.

So for instance you have a setup of two monitors, both resolutions 1280x1024

Mon1 (main)
Mon2 (right from main)

In this case you will have x positions:

Mon1 : 0..1280
Mon2 : 1280..2560

When you have this setup:

Mon2 (left from main)
Mon1 (main)

In this case you will have x positions:

Mon1 : 0..1280
Mon2 : -1280..0

As you screenshot shows +2550 as x position, it can only be placed to the right of main.


Please use this WIKI sample to query and inspect the monitor setup:

https://samples.tdcommunity.net/index ... nitors.zip

- Setup your monitors (do not change which monitor is main but only swap the monitors by dragging the monitor icons)
- Start sample and press button "create sample dialog"
- Now drag the window around your monitors.

See screenshot:

The arrows point to the x position. When you have the correct monitor setup it will show a negative x position.
When you have succeeded in setting the monitors up so that one of them has negative x positions, start the sample from this thread and place the window on the monitor which shows the negative x positions. Then the sample will fail.
MultiMon.png
So to be most clear: the sample in this thread must show a negative number in the datafield "real x-pos". Only then you will have the setup needed to show that SAM_ContextMenu does not correctly pass negative x positions !
You do not have the required permissions to view the files attached to this post.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

Return to “Bug Reports (TD 4.2 and older)”

Who is online

Users browsing this forum: [Ccbot] and 0 guests