You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects General forum

Screen coordinates of active view   Robert O'Rubik Oct 11, 2006
Re: Screen coordinates of active view   Neil Clemmons Oct 12, 2006
Re: Screen coordinates of active view   Robert O'Rubik Oct 16, 2006
Re: Screen coordinates of active view   James Hemphill Oct 16, 2006
Re: Screen coordinates of active view   Robert O'Rubik Oct 18, 2006
Re: Screen coordinates of active view   Robert O'Rubik Oct 18, 2006
Re: Screen coordinates of active view   Neil Clemmons Oct 18, 2006
Re: Screen coordinates of active view   Robert O'Rubik Oct 18, 2006
Re: Screen coordinates of active view   Neil Clemmons Oct 19, 2006
Re: Screen coordinates of active view   Robert O'Rubik Oct 19, 2006
Re: Screen coordinates of active view   Koteswara Rao Oct 25, 2006
Re: Screen coordinates of active view   Robert O'Rubik Oct 27, 2006
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Screen coordinates of active view 
Author Robert O'Rubik 
Date Oct 11, 2006 
Message I'm trying to get the screen coordinates of the active view in ArcMap. I can get the location of the application window, but I am trying to determine the area of the window that is not covered with toolbars or docked windows. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Screen coordinates of active view 
Author Neil Clemmons 
Date Oct 12, 2006 
Message Try IActiveView::ExportFrame. 
  Neil Clemmons
Senior GIS Developer
Geographic Information Services, Inc.
Birmingham, AL
http://www.gis-services.com

Check out our blog:
http://blog.gis-services.com/ 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Screen coordinates of active view 
Author Robert O'Rubik 
Date Oct 16, 2006 
Message The export frame doesn't get me quite what I'm looking for.

If the ActiveView is the Data View, then the export frame will tell me the dimensions of the active view area. It will give a top and left of zero, and then a left and bottom indicating the height and width of the area. It still isn't enough to figure out the screen coordinates, since I still don't know where the upper left corner is located.

In the Layout View, the export frame only gives pixel dimesions of the layout page area and has no relation to the size of the active view window area.

- Thanks anyway, that might come in handy somewhere else. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Screen coordinates of active view 
Author James Hemphill 
Date Oct 16, 2006 
Message Try the following... 
 
Private Sub FindCoords()

Dim pMxdoc As IMxDocument
Set pMxdoc = ThisDocument

Dim pMap As IMap
Set pMap = pMxdoc.FocusMap

Dim pAct As IActiveView
Set pAct = pMap

Dim pEnv As IEnvelope
Set pEnv = pAct.Extent

Dim xMin As Double
Dim yMin As Double
Dim xMax As Double
Dim yMax As Double

xMin = pEnv.xMin
yMin = pEnv.yMin
xMax = pEnv.xMax
yMax = pEnv.yMax

Dim strBottomLeft As String
strBottomLeft = xMin & "," & yMin

Dim strBottomRight As String
strBottomRight = xMax & "," & yMin

Dim strTopLeft As String
strTopLeft = xMin & "," & yMax

Dim strTopRight As String
strTopRight = xMax & "," & yMax

End Sub
 
  James Hemphill
GIS Programmer/Analyst 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Screen coordinates of active view 
Author Robert O'Rubik 
Date Oct 18, 2006 
Message Well, I am getting some coordinates from that, but they don't seem to be screen coordinates. I think they are map units. I would like to try converting the numbers from map units to screen units, but I can't figure out where to get the IDisplayTransformation interface. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Screen coordinates of active view 
Author Robert O'Rubik 
Date Oct 18, 2006 
Message OK, I figured out the transformation, but I guess that wasn't the problem. I can't figure out what these values correspond too. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Screen coordinates of active view 
Author Neil Clemmons 
Date Oct 18, 2006 
Message If you're talking about the values from the code above, those are the extents of the active view (in map units). If you want the screen coordinates of the map window, I think you're going to have to use the Windows API. It looks like everything in ArcObjects will give you coordinates relative to the ArcMap application window. You'll need to use something like Spy++ to figure out the name of the map window and use that to get the window position coordinates. 
  Neil Clemmons
Senior GIS Developer
Geographic Information Services, Inc.
Birmingham, AL
http://www.gis-services.com

Check out our blog:
http://blog.gis-services.com/ 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Screen coordinates of active view 
Author Robert O'Rubik 
Date Oct 18, 2006 
Message I actually can get the coordinates of the map window using the IWindowPosition interface off the application object.

I am trying to get the coordinates of the active view area of the window. That is, the portion of the window that is not covered with docked windows and toolbars. So, if in data view mode, it should be the rectangle where the map is being shown.

It's not a big deal, I've already worked arround it, but if someone knows a whay to get this info please post... as it would help make things a little slicker. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Screen coordinates of active view 
Author Neil Clemmons 
Date Oct 19, 2006 
Message I think you're confusing the application window with the map window. They are not the same thing. In Windows programming, everything with a handle is a "window". This includes forms and the controls on the forms. I am referring to the actual control that houses the map. You can use Spy++ to see what it's window handle is, plus other information. It may be possible to use that information along with the Windows API to find that window in code. If you can do that, you can get its screen coordinates. 
  Neil Clemmons
Senior GIS Developer
Geographic Information Services, Inc.
Birmingham, AL
http://www.gis-services.com

Check out our blog:
http://blog.gis-services.com/ 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Screen coordinates of active view 
Author Robert O'Rubik 
Date Oct 19, 2006 
Message Yes, you are right I was confused.

I've only done web programming before this, and I'm still trying to get a handle on handles.

Thanks for the clarification. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Screen coordinates of active view 
Author Koteswara Rao 
Date Oct 25, 2006 
Message Try this below code...
--------------

Type rect
left As Long
top As Long
right As Long
bottom As Long
End Type

Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, lpRect As rect) As Long

Public Sub GetActiveScreenCordinates()
Dim pMxDocument As IMxDocument
Dim rect As rect
Dim res As Long

Set pMxDocument = ThisDocument
res = GetWindowRect(pMxDocument.ActiveView.ScreenDisplay.hwnd, rect)

MsgBox rect.left & ", " & rect.bottom & "," & rect.right & "," & rect.top
End Sub

----
I hope this may help You. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Screen coordinates of active view 
Author Robert O'Rubik 
Date Oct 27, 2006 
Message Thanks, that worked. It took me a while to convert it to C# and get it working, but it is exactly what I was looking for. Works for both the DataView and LayoutView.

C# code: 
 
public class Utils
{
	public static void ShowActiveViewScreenCordinates(IMxDocument mxDocument) 
	{
		User32.WinRect rect = new User32.WinRect();
		User32.GetWindowRect(mxDocument.ActiveView.ScreenDisplay.hWnd, ref rect);
		string message = "Top:\t" + rect.Top + "\nLeft:\t" + rect.Left;
		message += "\nRight:\t" + rect.Right + "\nBottom:\t" + rect.Bottom;
		MessageBox.Show(message);
	}
	
	public static User32.WinRect GetActiveViewScreenCordinates(IMxDocument mxDocument) 
	{
		User32.WinRect rect = new User32.WinRect();
		User32.GetWindowRect(mxDocument.ActiveView.ScreenDisplay.hWnd, ref rect);
		return rect;
	}
}

/// <summary>
/// Helper class containing User32 API functions
/// </summary>
public class User32
{
	[StructLayout(LayoutKind.Sequential)]
	public struct WinRect
	{
		public int Left;
		public int Top;
		public int Right;
		public int Bottom;
	}
	
	[DllImport("user32.dll")]
	public static extern int GetDesktopWindow();
	[DllImport("user32.dll")]
	public static extern int GetWindowDC(int hWnd);
	[DllImport("user32.dll")]
	public static extern int ReleaseDC(int hWnd,int hDC);
	[DllImport("user32.dll")]
	public static extern int GetWindowRect(int hWnd,ref WinRect rect);
}