exe im zweiten monitor ausführen lassen???

  • VB.NET

Es gibt 19 Antworten in diesem Thema. Der letzte Beitrag () ist von Niko Ortner.

    exe im zweiten monitor ausführen lassen???

    hallo kann mir jemand helfen?

    habe ein programm, dass ich starte. geht gut. aber ich will es im zweiten monitor haben. wie geht das?

    danke im voraus

    bis jetzt habe ich das:

    VB.NET-Quellcode

    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.
    2. Dim p As New Process()
    3. p.StartInfo.FileName = "C:\Users\Eugen\Desktop\Neuer Ordner (2)\Neues Textdokument.txt"
    4. p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
    5. p.Start()
    6. End Sub
    Per API verschieben:

    VB.NET-Quellcode

    1. ''' <summary>
    2. ''' Setzt ein Fenster mit dem übergebenen Handle auf eine Position und ändert Eigenschaften
    3. ''' </summary>
    4. ''' <param name="hWnd">Fensterhandle<example> z.B. Me</example></param>
    5. ''' <param name="hWndInsertAfter">Zuweisungshandle; 1 = Ganz unten; -2 = Hinter TopMost; 0 = Vor TopMost; -1 = Vor TopMost und bleibt</param>
    6. ''' <param name="X">Fensterposition X<example> z.B. Me.Location.X</example></param>
    7. ''' <param name="Y">Fensterposition Y<example> z.B. Me.Location.Y</example></param>
    8. ''' <param name="cx">Fensterbreite<example> z.B. Me.Width</example></param>
    9. ''' <param name="cy">Fensterhöhe<example> z.B. Me.Height</example></param>
    10. ''' <param name="uFlags">Zusätzliche Parameter; Wird mit Or kombiniert</param>
    11. ''' <returns></returns>
    12. ''' <remarks></remarks>
    13. <System.Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True)> _
    14. Public Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As UInteger) As Boolean
    15. End Function
    16. Enum uFlags As UInteger
    17. ''' <summary>
    18. ''' If the calling thread and the thread that owns the window are attached to different input queues, the system posts the request to the thread that owns the window. This prevents the calling thread from blocking its execution while other threads process the request.
    19. ''' </summary>
    20. SWP_ASYNCWINDOWPOS = &H4000
    21. ''' <summary>
    22. ''' Prevents generation of the WM_SYNCPAINT message.
    23. ''' </summary>
    24. SWP_DEFERERASE = &H2000
    25. ''' <summary>
    26. ''' Draws a frame (defined in the window's class description) around the window.
    27. ''' </summary>
    28. SWP_DRAWFRAME = &H20
    29. ''' <summary>
    30. ''' Applies new frame styles set using the SetWindowLong function. Sends a WM_NCCALCSIZE message to the window, even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window's size is being changed.
    31. ''' </summary>
    32. SWP_FRAMECHANGED = &H20
    33. ''' <summary>
    34. ''' Hides the window.
    35. ''' </summary>
    36. SWP_HIDEWINDOW = &H80
    37. ''' <summary>
    38. ''' Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).
    39. ''' </summary>
    40. SWP_NOACTIVATE = &H10
    41. ''' <summary>
    42. ''' Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client area are saved and copied back into the client area after the window is sized or repositioned.
    43. ''' </summary>
    44. SWP_NOCOPYBITS = &H100
    45. ''' <summary>
    46. ''' Retains the current position (ignores X and Y parameters).
    47. ''' </summary>
    48. SWP_NOMOVE = &H2
    49. ''' <summary>
    50. ''' Does not change the owner window's position in the Z order.
    51. ''' </summary>
    52. SWP_NOOWNERZORDER = &H2
    53. ''' <summary>
    54. ''' Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of the window being moved. When this flag is set, the application must explicitly invalidate or redraw any parts of the window and parent window that need redrawing.
    55. ''' </summary>
    56. SWP_NOREDRAW = &H8
    57. ''' <summary>
    58. ''' Same as the SWP_NOOWNERZORDER flag.
    59. ''' </summary>
    60. SWP_NOREPOSITION = &H200
    61. ''' <summary>
    62. ''' Prevents the window from receiving the WM_WINDOWPOSCHANGING message.
    63. ''' </summary>
    64. SWP_NOSENDCHANGING = &H400
    65. ''' <summary>
    66. ''' Retains the current size (ignores the cx and cy parameters).
    67. ''' </summary>
    68. SWP_NOSIZE = &H1
    69. ''' <summary>
    70. ''' Retains the current Z order (ignores the hWndInsertAfter parameter).
    71. ''' </summary>
    72. SWP_NOZORDER = &H40
    73. ''' <summary>
    74. ''' Displays the window.
    75. ''' </summary>
    76. SWP_SHOWWINDOW = &H40
    77. End Enum
    78. Enum hWndInsertAfter As Integer
    79. ''' <summary>
    80. ''' Setzt das Fenster in den Hintergrund und verhindert, dass es vor ein anderes Fenster gesetzt werden kann.
    81. ''' Wenn sich die anzahl an geöffneten Fenstern auf dem Desktop ändert wird diese Aktion unwirksam.
    82. ''' </summary>
    83. TotalBottom = 1
    84. ''' <summary>
    85. ''' Setzt das Fenster auf die Ebene, die gewählt wird, wenn TopMost True ist.
    86. ''' Es können andere TopMost Fenster darüber angezeigt werden.
    87. ''' </summary>
    88. BehindTopMost = -2
    89. ''' <summary>
    90. ''' Setzt das Fenster vor alle Fenster, die TopMost auf True haben.
    91. ''' Es können andere TopMost Fenster darüber angezeigt werden.
    92. ''' </summary>
    93. TotalFront = 0
    94. ''' <summary>
    95. ''' Setzt das Fenster vor alle Fenster und verhindert, das ein anderes Fenster vor dieses gesetzt werden kann.
    96. ''' Wenn sich die anzahl an geöffneten Fenstern auf dem Desktop ändert wird diese Aktion unwirksam.
    97. ''' </summary>
    98. TotalFrontFixed = -1
    99. End Enum
    "Luckily luh... luckily it wasn't poi-"
    -- Brady in Wonderland, 23. Februar 2015, 1:56
    Desktop Pinner | ApplicationSettings | OnUtils
    Die API Deklaration für die SetWindowPos() Funktion (mit Dokumentierung und Enums, zum leichten Verwenden).

    Du rufst auf:

    VB.NET-Quellcode

    1. With Screen.AllScreens(1).Bounds
    2. SetWindowPos(P.MainWindowHandle, New IntPtr(hWndInsertAfter.BehindTopMost), .X, .Y, .Width, .Height, uFlags.SWP_SHOWWINDOW)
    3. End With
    "Luckily luh... luckily it wasn't poi-"
    -- Brady in Wonderland, 23. Februar 2015, 1:56
    Desktop Pinner | ApplicationSettings | OnUtils
    probiere das hier...am sonsten bin ratlos:

    VB.NET-Quellcode

    1. rivat Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2. Wie Dim Form Neues Formular
    3. Dim Screen als Bildschirm
    4. "Wir wollen ein Formular auf dem Bildschirm angezeigt werden 1
    5. Bildschirm = screen.AllScreens (1)
    6. "Stellen Sie die StartPosition auf Manuell sonst wird das System eine automatische Zuordnung Startposition
    7. form.StartPosition = FormStartPosition.Manual
    8. "Setzen Sie das Formular so dass es am Standort Standort erscheint (100, 100) auf dem Bildschirm ein
    9. Form.Location = screen.Bounds.Location + new Point (100, 100)
    10. 'Zeigen die Form
    11. form.ShowDialog (Me)
    12. Ende Sub

    quelle: social.msdn.microsoft.com/foru…08-4f16-a8aa-db6ff77b3656

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „SystemUnknow“ ()

    Was habe ich eigentlich in Post #4 geschrieben?
    Genau. Die Lösung zum Verschieben des Fensters.

    Der Prozess muss natürlich gestartet sein, und somit ein Fenster sichtbar sein.

    Also:
    Prozess deklarieren
    Prozess starten
    SetWindowPos mit Prozess.MainWindowHandle
    "Luckily luh... luckily it wasn't poi-"
    -- Brady in Wonderland, 23. Februar 2015, 1:56
    Desktop Pinner | ApplicationSettings | OnUtils
    niko, dein beispiel klappt.

    jetzt ist nur noch eine Frage: wenn ich es so ausführe:

    VB.NET-Quellcode

    1. screen = screen.AllScreens(1)
    2. form.StartPosition = FormStartPosition.Manual
    3. form.Location = screen.Bounds.Location + New Point(100, 100)


    dann geht ein fenster in meinem zweiten monitor auf.

    und wenn ich es so ausführe:

    VB.NET-Quellcode

    1. Dim p As New Process()
    2. p.StartInfo.FileName = "C:\Users\Eugen\Desktop\Neuer Ordner (2)\Neues Textdokument.txt"
    3. p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
    4. p.StartInfo.CreateNoWindow = False
    5. p.Start()
    6. With Screen.AllScreens(1).Bounds
    7. SetWindowPos(p.MainWindowHandle, New IntPtr(hWndInsertAfter.BehindTopMost), .X, .Y, .Width, .Height, uFlags.SWP_SHOWWINDOW)
    8. End With


    dann geht es im ersten auf. obwohl beide screens auf 1 sind. wenn ich dann With Screen.AllScreens(1).Bounds eine 0 reinschreibe geht es in den zweiten monitor. hat man dafür eine erklärung? oder nimms so wie es ist?

    danke im voraus.
    Ist der "zweite" Monitor bei Dir in Wirklichkeit der erste?
    Hab's bei mir getestet und bei mir ist 0 der primäre (der mit der Taskleiste) und 1 der sekundäre.
    "Luckily luh... luckily it wasn't poi-"
    -- Brady in Wonderland, 23. Februar 2015, 1:56
    Desktop Pinner | ApplicationSettings | OnUtils
    kannst du mir deinen beispiel hier posten, was genau du ausprobiert hast. ich habe es so ebend getestet, und er macht immer im zweiten monitor auf. wenn ich 0 eintrage, reagiert er drauf nicht... vielleicht übersehe ich etwas...



    jetzt habe ich es.

    Der fehler war, dass es an einem Sleep gefehlt hat. wenn der prozess gerade gestartet wird, funktioniert das minitor setzten noch nicht. wenn man das in debug modus ausgeführt hat, dann hat es geklappt. aber wenn man sleep dazwischen einbaut, funktioniert es auch.

    VB.NET-Quellcode

    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2. Dim p As New Process()
    3. p.StartInfo.FileName = "C:\Users\Eugen\Desktop\Neuer Ordner (2)\Neues Textdokument.txt"
    4. p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
    5. ' p.StartInfo.CreateNoWindow = True
    6. p.Start()
    7. Threading.Thread.Sleep(50)
    8. With Screen.AllScreens(1).Bounds
    9. SetWindowPos(p.MainWindowHandle, New IntPtr(hWndInsertAfter.BehindTopMost), .X, .Y, .Width, .Height, uFlags.SWP_SHOWWINDOW)
    10. End With
    11. End
    12. End Sub

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „EugenIS“ ()