Bill, Tony and Aladar,
Thanks for the code snippits, I've put the various bits together and come up with a function and sub for determining the bottom right of the screen. There are a few bodges, namely: I've calculated the width of dialog units by measuring the widths/ heights of the characters in pixels using a graphics package (I couldn't face navigating through Microsoft's web pages) and there is a correction factor of 10 and 145 pixels to take the dialog box to the bottom right of the MapInfo client window (bills code always seemed to put the dialog box at a consistant distance from the bottom right of the MapInfo client window).
It works for me at the moment (on 2 different screens but it is not always exactly in the BR corner and can be a few pixles out depending on the size of the dialog box and the shape of the client window). If anyone can see why the correction factors are needed / a way to get rid of them, or has a simple way of determining the dimensions of dialog units in pixels let me know.
Thanks,
G
zzzzzzzzzzzzzzzzzzzzzz
Call either the function:
GetBRtPixels(MI_WIN_BRX,Dialog width in paper units) - returns Base of MI window in Pixels'
GetBRtPixels(MI_WIN_BRY, Dialog height in paper units) - returns RHS of MI in Pixels
or the sub:
GetMICliRectPixForDiaPos(fWidth, fHeight) 'to return both
e.g.
'To place the dialog in the bottom RHS of screen:
Dim PosX, PosY as integer
'Then either use:
PosX = GetBRtPixels(MI_WIN_BRX,EndLength)
PosY = GetBRtPixels(MI_WIN_BRY,EndHt)
'or
Dim fWidth, fHeight As float
Call GetMICliRectPixForDiaPos(fWidth, fHeight)
PosX = fWidth + 10 - (EndLength * 1.538) ' sub routine uses just returns a point in piexles at a set distance from the top right of the screen
PosY = fHeight + 120 - (EndHt * 1.625) ' and the correction factors are needed after
'Then call your dialog box:
Dialog
Title AppName
Position PosX, PosY
Control OKButton
'and it should hopefully be in the bottom right of the MapInfo client window or thereabouts!
zzzzzzzzzzzzzzzzzzzzzzz
'Definition file:
'Definitions etc
Define LOGPIXELSX 88 ' Logical pixels/inch in X
Define LOGPIXELSY 90 ' Logical pixels/inch in Y
Define SM_CXSIZEFRAME 32
Define SM_CYSIZEFRAME 33
Define SM_CYHSCROLL 3
Define SM_CXVSCROLL 20
Define SM_CYCAPTION 4
Define MI_WIN_BRX "X"
Define MI_WIN_BRY "Y"
Type RECT_t
left As Integer
top As Integer
right As Integer
bottom As Integer
End Type
'Non MB 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
'MB Function and sub
Declare Function GetBRtPixels(Byval XY as string, ByVal DB_WH as integer) as float
Declare Sub GetMICliRectPixForDiaPos(fWidth As float, fHeight As float)
'Sub / function file:
Include "MapBasic.def"
Include 'the above defintion file
'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Function GetBRtPixels(Byval XY as string, ByVal DB_WH as integer) as float
Dim hWnd As Integer
Dim hDC As Integer
Dim nStatus As Integer
Dim tRect As RECT_t
Dim nWidth, nHeight As Integer
Dim PixRes,base_wnd,zero as integer
Dim MIHt, MIWidth as float
zero=0
base_wnd=GetDC(zero)
PixRes=GetDeviceCaps(base_wnd,88)
hWnd = SystemInfo(SYS_INFO_MDICLIENTWND)
nStatus = GetClientRect (hWnd, tRect)
nWidth = tRect.right - 2*GetSystemMetrics (SM_CXSIZEFRAME)
nHeight = tRect.bottom - GetSystemMetrics (SM_CYCAPTION) -
2*GetSystemMetrics (SM_CYSIZEFRAME)
hDC = GetDC (hWnd)
'this second part is based upon counting / averaging pixels from a bitmap (A-Z in capitals and a-z in lower case - a bit dubious I know)
'which were then used to convert 'dialog units' to pixels. This is where the code to calculate pixels per dialog units would be very useful
'The + 10 / + 145 parts of the equation are based on trial and error as the location of BRX and BRY are consistantly out by these numbers
if XY = "X" then
MIWidth = (nWidth / GetDeviceCaps (hDC, LOGPIXELSX)) * PixRes
'see above note about this second part
GetBRtPixels = MIWidth + 10 - (DB_WH * 1.538)
elseif XY = "Y" then
MIHt = (nHeight / GetDeviceCaps (hDC, LOGPIXELSY)) * PixRes
'see above note about this second part
GetBRtPixels = MIHt +120 - (DB_WH * 1.625)
Else
GetBRtPixels = 0
End if
End Function
'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
Sub GetMICliRectPixForDiaPos(fWidth As float, fHeight As float)
Dim hWnd As Integer
Dim hDC As Integer
Dim nStatus As Integer
Dim tRect As RECT_t
Dim nWidth, nHeight As Integer
Dim PixRes,base_wnd,zero as integer
zero=0
base_wnd=GetDC(zero)
PixRes=GetDeviceCaps(base_wnd,88)
hWnd = SystemInfo(SYS_INFO_MDICLIENTWND)
nStatus = GetClientRect (hWnd, tRect)
nWidth = tRect.right - 2*GetSystemMetrics (SM_CXSIZEFRAME)
nHeight = tRect.bottom - GetSystemMetrics (SM_CYCAPTION) -
2*GetSystemMetrics (SM_CYSIZEFRAME)
hDC = GetDC (hWnd)
fWidth = (nWidth / GetDeviceCaps (hDC, LOGPIXELSX)) * PixRes
fHeight = (nHeight / GetDeviceCaps (hDC, LOGPIXELSY)) * PixRes
nStatus = ReleaseDC (hWnd, hDC)
End Sub
'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz