Avatar billede anthex Nybegynder
30. marts 2006 - 20:30 Der er 3 kommentarer

sæt et windows-programs position

hej eksperter

jeg er lidt nybegynder inde for faget VB.
Jeg skal åbne et windowsprogram og sætte dets position i venstre hjørne. hvad gør jeg?
Jeg ved at jeg åbner programmet ved at bruge shell;

Private Sub Command1_Click()
Shell ("X:\Spil\Bodog Poker\GameClient.exe")
End Sub

hvad gør jeg så der efter for at placere vinduet? skal jeg erklære programmet som noget først? kender funktionen SetWindowPos, men ved ikke hvordan jeg bruger det i sammenhæng.
Avatar billede sjh Nybegynder
30. marts 2006 - 23:15 #1
' ---------------------------- Form1 ----------------------------
Option Explicit

Private Type RECT
        Left  As Long
        Top    As Long
        Right  As Long
        Bottom As Long
End Type

Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function MoveWindow Lib "user32" (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
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long

Private Const GW_HWNDNEXT = 2

Private Function InstanceToWnd(ByVal target_pid As Long) As Long
Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
  test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
  Do While test_hwnd <> 0
    If GetParent(test_hwnd) = 0 Then
      test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
      If test_pid = target_pid Then
        InstanceToWnd = test_hwnd
        Exit Do
      End If
    End If
    test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
  Loop
End Function

Private Sub Command1_Click()
Dim r As RECT
Dim nLeft As Long
Dim nWidth As Long
Dim nHeight As Long
Dim nhWnd As Long
Dim strShell As String

  strShell = "X:\Spil\Bodog Poker\GameClient.exe"

  nhWnd = InstanceToWnd(Shell(strShell))
  If nhWnd <> 0 Then
    Call GetWindowRect(nhWnd, r)

    nWidth = (r.Right - r.Left)
    nHeight = (r.Bottom - r.Top)
    nLeft = (Screen.Width \ 15) - nWidth

    Call MoveWindow(nhWnd, nLeft, 0, nWidth, nHeight, 1)
  End If
End Sub
' ---------------------------- Form1 ----------------------------
Avatar billede sjh Nybegynder
30. marts 2006 - 23:19 #2
venstre hjørne:

nLeft = 0 ' (Screen.Width \ 15) - nWidth

;)
Avatar billede anthex Nybegynder
30. marts 2006 - 23:20 #3
takker..:)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester