author=Fred Tomke link=topic=1625.msg8010#msg8010 date=1306077243 wrote:
I'm not sure if it is really possible to get the information via ActiveX because WindowLeft and WindowTop seem to return standard values if maximized to the screen:
I cannot say anything about the situation in AutoCAD but in Bricscad this is not true.
If I am running the cad application on my secondary monitor and have this monitor positioned above my primary monitor this:
(vla-get-windowtop (vlax-get-acad-object))
will return a large negative value (for a screen height of 1024 with the cad application maximized the value is -1028).
Using the fact that (dcl_GetScreenSize) returns values for the primary monitor it is possible to determine on which monitor the cad application is running.
But that information is not necessary: the center of the cad application window is enough to position a form.
; returns the center of the application window (may not be the screen center)
(defun GetCadAppCenter ( / oCad result)
(vl-load-com)
(setq oCad (vlax-get-acad-object))
(setq result
(list
(+ (vla-get-windowleft oCad) (/ (vla-get-width oCad) 2))
(+ (vla-get-windowtop oCad) (/ (vla-get-height oCad) 2))
)
)
(vlax-release-object oCad)
result
)
; algorithm suggested by Owen Wengerd
; code will also return nil if the center of the application
; window is on the task bar of the primary monitor
(defun kg_odcl_CadAppOnPrimaryMonitorP ()
(equal
(mapcar
'(lambda (app scr)
(< 0 app scr)
)
(GetCadAppCenter)
(dcl_GetScreenSize)
)
'(T T)
)
)
; example: (kg_odcl_FormCenter_To_CadAppCenter MyProject_MyForm)
(defun kg_odcl_FormCenter_To_CadAppCenter (form)
(apply
'dcl_Control_SetPos
(cons
form
(mapcar
'-
(GetCadAppCenter)
(list
(/ (dcl_Control_GetWidth form) 2)
(/ (dcl_Control_GetHeight form) 2)
)
)
)
)
)
EDIT1: Something is going wrong with the code highlighting...
EDIT2: added
(vl-load-com)