Hello Guest it is November 22, 2019, 09:48:43 AM

Author Topic: Screen Start Position  (Read 2902 times)

0 Members and 1 Guest are viewing this topic.

Screen Start Position
« on: March 08, 2010, 06:44:16 AM »
Hi
I am just wondering if there is a way to make the mach3 screen start up in a certain position (ie centre screen), and with a certain size, and if it is possible to change the FormBorderSyle?  I have written an application in C# and I have interfaced to mach with the com object, but for one particular task I want to actually look at the mach screen, but I want this to be at a certain spot within my main screen (within a control).

Any help would be greatly appreciated.

Regards
Andrew
Re: Screen Start Position
« Reply #1 on: June 04, 2010, 06:29:34 AM »
Hello
I don't know any C# code, but I could do this in VB, and I expect a similar approach could translate into your language.
I'd do it by addressing the Windows API.  Each window on the screen will have a "handle" which is its reference number.  The API call "FindWindow" will deliver you the relevant reference.  In VB you'd declare the function like this:

    Public Declare Function apiFindWindow _
        Lib "user32" Alias "FindWindowA" _
        (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Then this would find the window, if you knew its class:  (Or you could adapt to find by Name, which would be the text showing in the coloured window bar e.g. Mach3 CSC Licensed to...  )
    Const cstWinNAme As String = "Mach3 CSC Licensed To:Fill your name in here"
    Dim lgHwnd As Long

'   Locate top level window
    Let lgHwnd = apiFindWindow(vbNullString, cstWinNAme)

Then you can use an API call "GetWindowRect"  if you want to know the current window position and dimensions.  But since you want to move it you'd use the "MoveWindow" call, which as you see passes in it's first variable as the handle you'd just found, then the X and Y coordinates, in pixels

    Public Declare Function apiMoveWindow _
        Lib "user32.dll" Alias "MoveWindow" _
        (ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long, _
        ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long


You can play more games as each main application window will have all the objects within it as "Child" windows.  There are APIs to enumerate these, and then you can move components around, or click other program's buttons etc.

Hope this helps

Wilfrid Underwood