External Window Location - Multi Monitor

M

Matt

I'm writing a plug-in in VB.NET to a an application called
DesktopSidebar for Windows. Right clicking my plug-in's "panel" gives
shows among other things a Properties Dialog. All I need to do is pop
up the dialog in the proper place. After quite a bit of trial and
error I came up with this:

Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Int32,
ByRef lpRect As RECT) As Int32

Public Structure RECT
Dim Left As Int32
Dim Top As Int32
Dim Right As Int32
Dim Bottom As Int32
End Structure

Dim colProcess() As System.Diagnostics.Process
Dim oProcess As Diagnostics.Process
colProcess = Diagnostics.Process.GetProcessesByName("sidebar")
If colProcess.Length > 0 Then
oProcess = colProcess(0)
Dim handle As System.IntPtr = oProcess.MainWindowHandle
Dim loc As RECT
If GetWindowRect(handle.ToInt32, loc) > 0 Then
'Where are we docked?
If loc.Left = 0 Then
Me.Location = New Drawing.Point(loc.Right,(loc.Bottom -
loc.Top)/2)
Else
Me.Location = New Drawing.Point(loc.Left - Me.Width,
(loc.Bottom - loc.Top)/2)
End If
End If
End If

This works great as long as you have a single monitor, whether
DesktopSideBar is docked to the Left or the Right. However, I run in a
multi-monitor environment. In my particular setup my primary display
is my laptop and my secondary display actually hovers ABOVE my primary
display (it's a 19 inch monitor) and I have my desktop EXTENDED onto
it. So, essentially I can move my mouse straight UP to the other
monitor. Quite handy as a developer stuck on a laptop. The code above,
only targets the primary display, even though I dock DesktopSideBar on
my secondary monitor. My screen coordinates are still good... just not
on the right monitor.

Could anyone offer up some suggestions on how to deal with this in
VB.NET?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top