Reserving a specified area on Windows Desktop

Hello to everyone !

I am currently trying to develop a self-testing application for Microsoft Word.

I would like to be able to display my application's main windows at the bottom of the screen while the rest of the Windows Desktop be available for Microsoft Word.

When I set my application's window "Always on top" other windows are displayed under it.

What I want is to reserve that area of the desktop so that no other window is displayed there.

Thank you in advance.



Answer this question

Reserving a specified area on Windows Desktop

  • medel

    ' The right way to do this is at the link below, but, as always,

    ' it's in C

    ' http://msdn.microsoft.com/library/default.asp url=/library/en-us/shellcc/platform/shell/programmersguide/shell_int/shell_int_programming/appbars.asp

    ' So, here's playing around with some hopeful APIs

    Public Class Form1

    Private Declare Function SystemParametersInfo _

    Lib "user32" Alias "SystemParametersInfoA" _

    (ByVal uAction As Integer, ByVal uParam As Integer, _

    ByRef lpvParam As RECT, ByVal fuWinIni As Integer) As Integer

    Public Declare Function SendNotifyMessage Lib "user32.dll" _

    Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal Msg As Integer, _

    ByVal ByValByValwParam As Integer, ByVal lParam As String) As Integer

    Private Const SPI_GETWORKAREA As Integer = 48 'get the current screen size

    Private Const SPI_SETWORKAREA As Integer = 47 'change the screen size

    Private Const SPIF_SENDCHANGE As Integer = 2 'broadcast the change to other windows so that they know

    Private Const WIDTH_OF_TOOLBAR As Integer = 100

    Private oldRect As RECT = New RECT()

    Private Const HWND_BROADCAST As Integer = -1

    Private Const WM_SETTINGCHANGE As Integer = &H1A

    Public Structure RECT 'store the screen size in this structure

    Dim Left As Integer

    Dim Top As Integer

    Dim Right As Integer

    Dim Bottom As Integer

    End Structure

    Private Sub GetWorkspace(ByRef oRECT As RECT)

    Dim iResult As Integer = SystemParametersInfo(SPI_GETWORKAREA, 0, oRECT, 0)

    End Sub

    Private Function SetWorkspace(ByVal oRECT As RECT) As Integer

    Return SystemParametersInfo(SPI_SETWORKAREA, 0, oRECT, SPIF_SENDCHANGE)

    End Function

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Me.MaximizedBounds = New Rectangle(Screen.PrimaryScreen.WorkingArea.Width - WIDTH_OF_TOOLBAR, 0, WIDTH_OF_TOOLBAR, Screen.PrimaryScreen.WorkingArea.Height)

    Me.TopMost = True

    Me.WindowState = System.Windows.Forms.FormWindowState.Maximized

    Dim RECT As RECT = New RECT()

    RECT.Left = 0

    RECT.Top = 0

    RECT.Right = Screen.PrimaryScreen.WorkingArea.Width - WIDTH_OF_TOOLBAR

    RECT.Bottom = Screen.PrimaryScreen.WorkingArea.Bottom

    GetWorkspace(oldRect)

    ' The next line works somewhat. When you maximize other windows

    ' they observe the setting, but do nothing initially.

    SetWorkspace(RECT)

    ' The 'SendNotifyMessage' hung. Partly because it came back to this program.

    ' But the change took and required a re-boot to get rid of.

    'SendNotifyMessage(CType(HWND_BROADCAST, IntPtr), WM_SETTINGCHANGE, SPI_SETWORKAREA, CStr(0))

    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

    SetWorkspace(oldRect)

    End Sub

    End Class



  • Reserving a specified area on Windows Desktop