Position form on screen

flfl Member Posts: 184
Hi,

I want to position a form allways on the upper right corner of the screen undependent on the type of screen the user is using (800x600, 1024x768,...).

Any idea how i can find out the max screen resolution in Navision ?

Thanks
Francois
Consultant-Developper

http://www.CreaChain.com

Comments

  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Maybe some DLL?

    Google on 'retrieve resolution dll'

    I've done it once in a new table "Computer Setup" retrieving the computername via Windows DLL.
  • SavatageSavatage Member Posts: 7,142
    while on your form go to Tools->Designer->View-> Properties
    (I haven;t tried to put a form on the right but....

    AutoPosition
    Use this property to have the system automatically position the form in one of several places.

    Applies to: Forms

    Settings : The AutoPosition settings are:

    To... Choose...

    Center this form on the screen: CenterScreen
    Center this form with respect to the active form: CenterActiveForm
    Place this form outside the active form: OutsideActiveForm
    Place this form outside the active control: OutsideActiveControl
    Not have the system automatically position the form: None (default)

    Comments
    If you choose None, the system relies on the XPos and YPos properties to determine where to place the form. If you choose another setting, the system ignores the XPos and YPos settings.

    If the form is displayed as a lookup (in lookup mode), the system automatically places it outside the active control.

    The system checks this property when it opens the form.
    Your entry here has no effect on any related subforms.
  • kinekine Member Posts: 12,562
    May be that something with VB Script helps you? System shell dll... or your new DLL for this...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • janpieterjanpieter Member Posts: 298
    Create a DLL with the following functions in VB6:
    Public Declare Function APIGetWindowRect Lib "user32" _
                     Alias "GetWindowRect" _
                     (ByVal hWnd As Long, _
                     lpRect As RECT) As Long
    
    Public Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
    
    Public Declare Function GetForegroundWindow Lib "user32" () As Long
    
    Public Declare Function APIFindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, _
                                                                              ByVal hWnd2 As Long, _
                                                                              ByVal lpsz1 As String, _
                                                                              ByVal lpsz2 As String) As Long
    
    Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, _
                                                                      ByVal lpClassName As String, _
                                                                      ByVal nMaxCount As Long) As Long
    
    Public Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    
    Public g_hwndOBJECTDESIGNER As Long
    Public g_hwndMDICLIENT As Long
    Public g_hwndFINEXE As Long
    Public g_hwndTOOLBAR As Long
    Public g_hwndSTATUSBAR As Long
    
    Public Function GetWindowRect(ByVal hWnd As Long, _
                                  ByRef x As Long, _
                                  ByRef y As Long, _
                                  ByRef width As Long, _
                                  ByRef height As Long) As Long
        GetWindowRect = gGetWindowRect(hWnd, x, y, width, height)
    End Function
    
    Public Function GetParentForeGroundWindow() As Long
        Dim tmphwnd As Long
        tmphwnd = GetForegroundWindow
        Do
            GetParentForeGroundWindow = tmphwnd
            tmphwnd = GetParent(tmphwnd)
        Loop Until tmphwnd = 0
    End Function
    
    Private Function StripNulls(OriginalStr As String) As String
       If (InStr(OriginalStr, Chr(0)) > 0) Then
          OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1)
       End If
       StripNulls = OriginalStr
    End Function
    
    
    Public Sub GetHwnd()
        Dim oldHWNDFINEXE As Long
        Dim tmphwnd As Long
        
        oldHWNDFINEXE = g_hwndFINEXE
        tmphwnd = GetForegroundWindow
        g_hwndFINEXE = GetParentForeGroundWindow
        
        ' check ik valid FIN EXE window
        Dim WinClassBuf As String * 255
        Dim WinClass As String
        GetClassName g_hwndFINEXE, WinClassBuf, 255
        WinClass = StripNulls(WinClassBuf)  ' remove extra Nulls & spaces
        
        If InStr(UCase(WinClass), "C/SIDE") = 0 Then
            g_hwndFINEXE = oldHWNDFINEXE
        End If
    
        If g_hwndFINEXE <> 0 Then
            g_hwndMDICLIENT = APIFindWindowEx(g_hwndFINEXE, 0&, "MDICLIENT", vbNullString)
            g_hwndTOOLBAR = APIFindWindowEx(g_hwndFINEXE, 0&, "C/SIDE Glued", "Toolbar")
            g_hwndSTATUSBAR = APIFindWindowEx(g_hwndFINEXE, 0&, "C/SIDE Glued", "Status Bar")
            g_hwndOBJECTDESIGNER = APIFindWindowEx(g_hwndMDICLIENT, 0&, vbNullString, "Object Designer")
        End If
    End Sub
    
    Public Property Get hwndFINEXE() As Long
        GetHwnd
        hwndFINEXE = g_hwndFINEXE
    End Property
    Public Property Get hwndMDICLIENT() As Long
        GetHwnd
        hwndMDICLIENT = g_hwndMDICLIENT
    End Property
    Public Property Get hwndOBJECTDESIGNER() As Long
        GetHwnd
        hwndOBJECTDESIGNER = g_hwndOBJECTDESIGNER
    End Property
    Public Property Get hwndCurrForm(ByVal WindowCaption As String)
        GetHwnd
        hwndCurrForm = APIFindWindowEx(g_hwndMDICLIENT, 0&, vbNullString, WindowCaption)
        If hwndCurrForm = 0 Then
            hwndCurrForm = APIFindWindowEx(g_hwndFINEXE, 0&, vbNullString, WindowCaption)
        End If
    End Property
    Public Property Get hwndTOOLBAR() As Long
        GetHwnd
        hwndTOOLBAR = g_hwndTOOLBAR
    End Property
    Public Property Get hwndSTATUSBAR() As Long
        GetHwnd
        hwndSTATUSBAR = g_hwndSTATUSBAR
    End Property
    

    It is not possible in vbscript because it uses windows APIs :whistle:

    How it works? Just reference the DLL and call the function:
    DLLREFERENCE.GetWindowRect(DLLREFERENCE.hwndMDIClient, 
                                                   LocalIntX,
                                                   LocalIntY,
                                                   LocalIntWidth,
                                                   LocalIntHeight);
    

    The LocalIntWidth will have the maximum width of a navision form (thus the outer right x position).

    I hope you have all necesarry functions here, i made this post by collection several code snippets from a much larger program. If not, let me now which (API) function you are missing i have all.[/code]
    In a world without Borders or Fences, who needs Windows and Gates?
Sign In or Register to comment.