Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flytt WMC til høyre
15-12-2010, 22:31 (This post was last modified: 15-12-2010 22:37 by fermate.)
Post: #1
Flytt WMC til høyre
Jeg har en MSPC i kjelleren der jeg også har en HD projector.
Denne PCen har et Thermaltake DH102 kabinett med en liten LCD berørings skjerm på.

Den er fin å kjøre menyene på WMC med, men med en gang filmen/programmet starter vil jeg ha WMC på veggen.

Jeg har lenge tenkt at jeg skulle lage et programm som flyttet WMC fra den lille skjermen til den store med ett tastetrykk. (Som jeg kunne mappe til en av tastene på kabinettet)

I dag satte jeg meg ned og skrev noe som funker. Siden jeg er gammel VB programmerer ble det i VB.NET

Om noen har lyst til å bygge videre på den så er sourcen her:
Quote:Imports System.Runtime.InteropServices
Module Module1
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Function FindWindow( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
End Function

<DllImport("user32.dll", SetLastError:=True)> _
Private 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
End Function

Public Const SWP_NOSIZE As Integer = &H1
Public Const SWP_NOMOVE As Integer = &H2
Public Const SWP_NOZORDER As Integer = &H4
Public Const SWP_NOREDRAW As Integer = &H8
Public Const SWP_NOACTIVATE As Integer = &H10
Public Const SWP_DRAWFRAME As Integer = &H20
Public Const SWP_FRAMECHANGED As Integer = &H20
Public Const SWP_SHOWWINDOW As Integer = &H40
Public Const SWP_HIDEWINDOW As Integer = &H80
Public Const SWP_NOCOPYBITS As Integer = &H100
Public Const SWP_NOOWNERZORDER As Integer = &H200
Public Const SWP_NOREPOSITION As Integer = &H200
Public Const SWP_NOSENDCHANGING As Integer = &H400
Public Const SWP_DEFERERASE As Integer = &H2000
Public Const SWP_ASYNCWINDOWPOS As Integer = &H4000


Public Sub main()
Dim lpszWindowClass As String = "eHome Render Window"
Dim lpszWindowCaption As String = "Windows Media Center"
Dim hWnd As New IntPtr(0)

hWnd = FindWindow(lpszWindowClass, lpszWindowCaption) ' find WMC window
If hWnd.Equals(IntPtr.Zero) Then
MsgBox("WMC Not Running!")
Else
Move_to_next_screen(hWnd)
End If
End Sub

Sub Move_to_next_screen(ByVal h As IntPtr)
Dim nScreens As Integer
Dim is_in_screen_n As Integer ' tellt fra 0

Dim i As Integer
Dim screen_rect As Rectangle

' How many screens on this system?
nScreens = System.Windows.Forms.Screen.AllScreens.Length
' Where is window now?
For i = 0 To nScreens - 1
If System.Windows.Forms.Screen.FromHandle(h).Equals(System.Windows.Forms.Screen.All​Screens(i)) Then
is_in_screen_n = i
End If
Next
' where is target screen
If nScreens = 1 Then ' just one screen
screen_rect = System.Windows.Forms.Screen.AllScreens(0).WorkingArea ' same screen
ElseIf is_in_screen_n = nScreens - 1 Then ' are in last screen (far right)
screen_rect = System.Windows.Forms.Screen.AllScreens(0).WorkingArea ' put in far left screen
Else
screen_rect = System.Windows.Forms.Screen.AllScreens(is_in_screen_n + 1).WorkingArea ' put in next scrren
End If
' move it
SetWindowPos(h, 0, screen_rect.X, screen_rect.Y, screen_rect.Width, screen_rect.Height, SWP_NOOWNERZORDER Or SWP_SHOWWINDOW)
End Sub
End Module

Oups. Alle de pene innrykkene mine forsvant i quoten. Jaja .NET legger på igjen de fleste automatisk.

Har testet den i Win7 både i 32 og 64 bit.
Find all posts by this user
Quote this message in a reply
21-12-2010, 23:15
Post: #2
Flytt WMC til høyre
Christian/JEG:
Kan jeg legge ut exe filen her ett sted?
Hvor børe det være?
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)