Solved

Set the working area of the screen

Posted on 2004-10-11
8
1,755 Views
Last Modified: 2008-01-09
Hi

I am trying to create a program that will act similar to the taskbar, by that it will always be on top and windows will not maximise over the top of it.

I have tracked this setting down to workingarea in Screen.PrimaryScreen.WorkingArea.<something>

Is there anyway to set this working area or any other solution that will solve this problem

Thanks
Adam
0
Comment
Question by:adam_pedley
  • 5
  • 2
8 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 450 total points
ID: 12283958
You don't change the WorkingArea of the screen.  Instead, you have to create an AppBar and register it with the system using the SHAppBarMessage API.  This will update the workingarea of the desktop and subsequently cause other applications to not maximize over yours.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shappbarmessage.asp

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

Here is a C# app: (site has been having problems lately)
http://www.codeproject.com/Purgatory/AppBar.asp

I haven't tried converting it to VB.Net yet (it's on my list of things to tinker with) nor have I found an example in VB.Net out on the net.

~IM
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12283960
I'll see if I can come up with a VB.Net version of that code tomorrow.

~IM
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12284086
Thanks

I should be able to convert c# code i will fill you in once i've done it
0
 
LVL 9

Assisted Solution

by:checoo
checoo earned 50 total points
ID: 12284113
use the following link to convert the C# code to VB.NET

http://authors.aspalliance.com/aldotnet/examples/translate.aspx
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Author Comment

by:adam_pedley
ID: 12284326
Thanks checoo and Idle_Mind

I used the conversion tool, it did an ok job but quite a lot was not done correctly

But i managed to fix the rest

Here is the code

Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Runtime.InteropServices

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(72, 80)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(80, 40)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Close"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

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

    Structure RECT
        Public left As Integer
        Public top As Integer
        Public right As Integer
        Public bottom As Integer
    End Structure 'RECT


    Structure APPBARDATA
        Public cbSize As Integer
        Public hWnd As IntPtr
        Public uCallbackMessage As Integer
        Public uEdge As Integer
        Public rc As RECT
        Public lParam As IntPtr
    End Structure 'APPBARDATA
    Enum ABMsg

        ABM_NEW = 0
        ABM_REMOVE = 1
        ABM_QUERYPOS = 2
        ABM_SETPOS = 3
        ABM_GETSTATE = 4
        ABM_GETTASKBARPOS = 5
        ABM_ACTIVATE = 6
        ABM_GETAUTOHIDEBAR = 7
        ABM_SETAUTOHIDEBAR = 8
        ABM_WINDOWPOSCHANGED = 9
            ABM_SETSTATE=10

    End Enum
    Enum ABNotify

        ABN_STATECHANGE = 0
        ABN_POSCHANGED
        ABN_FULLSCREENAPP
        ABN_WINDOWARRANGE

    End Enum
    Enum ABEdge

        ABE_LEFT = 0
        ABE_TOP
        ABE_RIGHT
        ABE_BOTTOM
    End Enum



    Private fBarRegistered As Boolean = False

    Public Declare Function SHAppBarMessage Lib "shell32.dll" Alias "SHAppBarMessage" (ByVal dwMessage As Integer, ByRef pData As APPBARDATA) As System.UInt32
    Public Declare Function GetSystemMetrics Lib "User32.dll" Alias "GetSystemMetrics" (ByVal index As Integer) As Integer
    Public Declare Function MoveWindow Lib "User32.dll" Alias "MoveWindow" (ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal repaint As Boolean) As Boolean
    Private Declare Auto Function RegisterWindowMessage Lib "User32.dll" (ByVal msg As String) As Integer
    Private uCallBack As Integer

    Private Sub RegisterBar()
        Dim abd As New APPBARDATA()
        abd.cbSize = Marshal.SizeOf(abd)
        abd.hWnd = Me.Handle
        If Not fBarRegistered Then
            uCallBack = RegisterWindowMessage("AppBarMessage")
            abd.uCallbackMessage = uCallBack

            Dim ret As System.UInt32 = SHAppBarMessage(CInt(ABMsg.ABM_NEW), abd) 'ToDo: Unsigned Integers not supported
            fBarRegistered = True

            ABSetPos()

        Else
            SHAppBarMessage(CInt(ABMsg.ABM_REMOVE), abd)
            fBarRegistered = False
        End If
    End Sub 'RegisterBar


    Private Sub ABSetPos()
        Dim abd As New APPBARDATA()
        abd.cbSize = Marshal.SizeOf(abd)
        abd.hWnd = Me.Handle
        abd.uEdge = CInt(ABEdge.ABE_TOP)

        If abd.uEdge = CInt(ABEdge.ABE_LEFT) Or abd.uEdge = CInt(ABEdge.ABE_RIGHT) Then
            abd.rc.top = 0
            abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height
            If abd.uEdge = CInt(ABEdge.ABE_LEFT) Then
                abd.rc.left = 0
                abd.rc.right = Size.Width
            Else
                abd.rc.right = SystemInformation.PrimaryMonitorSize.Width
                abd.rc.left = abd.rc.right - Size.Width
            End If

        Else
            abd.rc.left = 0
            abd.rc.right = SystemInformation.PrimaryMonitorSize.Width
            If abd.uEdge = CInt(ABEdge.ABE_TOP) Then
                abd.rc.top = 0
                abd.rc.bottom = Size.Height
            Else
                abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height
                abd.rc.top = abd.rc.bottom - Size.Height
            End If
        End If

        ' Query the system for an approved size and position.
        SHAppBarMessage(CInt(ABMsg.ABM_QUERYPOS), abd)

        ' Adjust the rectangle, depending on the edge to which the
        ' appbar is anchored.
        Select Case abd.uEdge
            Case CInt(ABEdge.ABE_LEFT)
                abd.rc.right = abd.rc.left + Size.Width
            Case CInt(ABEdge.ABE_RIGHT)
                abd.rc.left = abd.rc.right - Size.Width
            Case CInt(ABEdge.ABE_TOP)
                abd.rc.bottom = abd.rc.top + Size.Height
            Case CInt(ABEdge.ABE_BOTTOM)
                abd.rc.top = abd.rc.bottom - Size.Height
        End Select

        ' Pass the final bounding rectangle to the system.
        SHAppBarMessage(CInt(ABMsg.ABM_SETPOS), abd)

        ' Move and size the appbar so that it conforms to the
        ' bounding rectangle passed to the system.
        MoveWindow(abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, True)
    End Sub 'ABSetPos


    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = uCallBack Then
            Select Case m.WParam.ToInt32()
                Case CInt(ABNotify.ABN_POSCHANGED)
                    ABSetPos()
            End Select
        End If

        MyBase.WndProc(m)
    End Sub 'WndProc


    Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
        Get
            Dim cp As CreateParams = MyBase.CreateParams
            cp.Style = cp.Style And Not &HC00000 ' WS_CAPTION
            cp.Style = cp.Style And Not &H800000 ' WS_BORDER
            cp.ExStyle = &H80 Or &H8 ' WS_EX_TOOLWINDOW | WS_EX_TOPMOST
            Return cp
        End Get
    End Property

    Private Sub End_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        RegisterBar()
        End
    End Sub
End Class
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12284968
Hey does anyone know how to change the position of the app bar to the bottom of the screen?
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12284971
Its just driving me crazy, i can get it to the bottom of the screen but it doesnt correct the working area
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12284993
Ok yes i know, dont point out my stupidity i missed it

you change

abd.uEdge = CInt(ABEdge.ABE_TOP)

to

abd.uEdge = CInt(ABEdge.ABE_BOTTOM)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now