I asked for help on how to find the sizes of various parts of the MapInfo window so that I could size a map window to exactly fill the client rectangle of the MapInfo window without maximizing it. I wanted to do this because I have to display more than one map window at the same time but use the maximum available space for the base map without maximizing it.
As Eric Blasenheim pointed out to me, if I use MapInfo's MDI client rectangle instead of the basic client rectangle I don't need to worry about the sizes of the menu bar or toolbars to determine the available space. The following MapBasic code does the trick and also provides an example showing how to use some Windows API functions that may be useful for people who want to determine the sizes of windows fetaures. One note on this program. Even though it starts off by closing all tables (and therefore all windows) if MapInfo's scroll bars were showing when you run it, the MDI client rectangle will be reduced as if they were still on. I don't know why this happens. But if there are no scroll bars visible, the window will fill the available space exactly no matter what size the main MapInfo window is. - Bill Thoen ' MI_ClientRect.mb Include "MapBasic.def" Define LOGPIXELSX 88 ' Logical pixels/inch in X Define LOGPIXELSY 90 ' Logical pixels/inch in Y Define SM_CXSIZEFRAME 32 ' Width of right and left sizable window ' borders Define SM_CYSIZEFRAME 33 ' Height of top and bottom sizable window ' borders Define SM_CYCAPTION 4 ' Height of caption (title bar) of sizable ' window Type RECT_t left As Integer top As Integer right As Integer bottom As Integer End Type ' Windows API functions Declare Function GetSystemMetrics Lib "User32" Alias "GetSystemMetrics" (ByVal nIndex As Integer) As Integer Declare Function GetClientRect Lib "user32" Alias "GetClientRect" (ByVal hwnd As Integer, lpRect As RECT_t) As Integer Declare Function GetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps" (ByVal hdc As Integer, ByVal nIndex As Integer) As Integer Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Integer) As Integer Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Integer, ByVal hdc As Integer) As Integer Declare Sub Main Declare Sub GetMIClientRect (fWidth As Float, fHeight As Float) Sub Main Dim fWidth, fHeight As Float CLS Close All Interactive ' Get the MapInfo MDI client rectangle size Call GetMIClientRect (fWidth, fHeight) ' Get a map window to resize to client rectangle Open Table "C:\Program Files\MapInfo\Data\Map_Data\Namerca\USA\Usa_Maps\USA.TAB" Interactive Map From USA ' Size the window to fit exactly in the avaliable client area. Set Window FrontWindow() Position (0,0) Width fWidth Height fHeight End Sub Sub GetMIClientRect ( fWidth As Float, ' Returned width of MDI client area in inches fHeight As Float) ' Returned height of MDI client area in inches ' Returns the width and height (in inches) of the available space ' in the MapInfo client rectangle area Dim hWnd As Integer Dim hDC As Integer Dim nStatus As Integer Dim tRect As RECT_t Dim nWidth, nHeight As Integer ' Get a handle to the MapInfo MDI client rectangle window hWnd = SystemInfo(SYS_INFO_MDICLIENTWND) ' Get the rectangle in pixels nStatus = GetClientRect (hWnd, tRect) ' Reduce the rectangle size by subtracting width of borders and caption nWidth = tRect.right - 2*GetSystemMetrics (SM_CXSIZEFRAME) nHeight = tRect.bottom - GetSystemMetrics (SM_CYCAPTION) - 2*GetSystemMetrics (SM_CYSIZEFRAME) '--- Convert pixels to inches hDC = GetDC (hWnd) fWidth = nWidth / GetDeviceCaps (hDC, LOGPIXELSX) fHeight = nHeight / GetDeviceCaps (hDC, LOGPIXELSY) nStatus = ReleaseDC (hWnd, hDC) End Sub _______________________________________________ MapInfo-L mailing list MapInfo-L@lists.directionsmag.com http://www.directionsmag.com/mailman/listinfo/mapinfo-l