7 Replies - 1047 Views - Last Post: 05 November 2015 - 10:07 AM Rate Topic: -----

#1 ISPFALC   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 05-November 15

Resizing the windows desktop(WorkArea) and adding a bar in the space

Posted 05 November 2015 - 07:56 AM

I am trying to resize the WorkArea so that I can put a bar at the top of the desktop. This bar would act something like the windows start bar, where windows would not overlap and maximize right below it.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

[Flags]
public enum SPIF
{
    None = 0x00,
    /// <summary>Writes the new system-wide parameter setting to the user profile.</summary>
    SPIF_UPDATEINIFILE = 0x01,
    /// <summary>Broadcasts the WM_SETTINGCHANGE message after updating the user profile.</summary>
    SPIF_SENDCHANGE = 0x02,
    /// <summary>Same as SPIF_SENDCHANGE.</summary>
    SPIF_SENDWININICHANGE = 0x02
}

#region SPI
    /// <summary>
    /// SPI_ System-wide parameter - Used in SystemParametersInfo function
    /// </summary>
        [Description("SPI_(System-wide parameter - Used in SystemParametersInfo function )")]
        public enum SPI : uint
        {
            /// <summary>
            /// Retrieves the size of the work area on the primary display monitor. The work area is the portion of the screen not obscured
            /// by the system taskbar or by application desktop toolbars. The pvParam parameter must point to a RECT structure that receives
            /// the coordinates of the work area, expressed in virtual screen coordinates.
            /// To get the work area of a monitor other than the primary display monitor, call the GetMonitorInfo function.
            /// </summary>
            SPI_GETWORKAREA = 0x0030
        }
#endregion

namespace test
{

    public partial class Form1 : Form
    {

        public const uint SPI_SETWORKAREA = 0x002F;
        public const uint SPI_GETWORKAREA = 0x0030;
        public const uint SPIF_SENDCHANGE = 0x02;

        [DllImport("user32.dll", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        //                                 SPI_GETWORKAREA 0x0030, 0  ,pvParam points to Rec, send global change
        static extern bool SystemParametersInfo(SPI uiAction, uint uiParam, ref Rect pvParam, SPIF fWinIni);
        public Form1()
        {
            InitializeComponent();
        }
        
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        public struct Rect
        {
            public Int32 Left, Top, Right, Bottom;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Rect DeskArea = new Rect();
            SystemParametersInfo(48/*SPI_GETWORKAREA*/, 0, ref DeskArea, 2/*SPIF_SENDCHANGE*/);
            this.Left = 0;
            this.Width = DeskArea.Right;
            this.Top = DeskArea.Bottom - this.Height - 4;
            DeskArea.Bottom = DeskArea.Bottom - 150;
            SystemParametersInfo(47/*SPI_SETWORKAREA*/, 0, ref DeskArea, 2/*SPIF_SENDCHANGE*/);
        }

        //And now you need to replace the orkarea to its original size.

        private void button2_Click(object sender, EventArgs e)
        {
            Rect DeskArea = new Rect();
            SystemParametersInfo(48/*SPI_GETWORKAREA*/, 0, ref DeskArea, 2/*SPIF_SENDCHANGE*/);
            DeskArea.Bottom = DeskArea.Bottom + 150;
            SystemParametersInfo(47/*SPI_SETWORKAREA*/, 0, ref DeskArea, 2/*SPIF_SENDCHANGE*/);
        }
    }
}




Is This A Good Question/Topic? 0
  • +

Replies To: Resizing the windows desktop(WorkArea) and adding a bar in the space

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15797
  • View blog
  • Posts: 63,297
  • Joined: 12-June 08

Re: Resizing the windows desktop(WorkArea) and adding a bar in the space

Posted 05 November 2015 - 08:19 AM

Are you sharing your project, or is there a question?
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7453
  • View blog
  • Posts: 25,095
  • Joined: 05-May 12

Re: Resizing the windows desktop(WorkArea) and adding a bar in the space

Posted 05 November 2015 - 08:23 AM

Why go through that painful process when you can use AppBars and let the OS manage the usable area for you?
Was This Post Helpful? 0
  • +
  • -

#4 ISPFALC   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 05-November 15

Re: Resizing the windows desktop(WorkArea) and adding a bar in the space

Posted 05 November 2015 - 09:54 AM

View Postmodi123_1, on 05 November 2015 - 08:19 AM, said:

Are you sharing your project, or is there a question?


I have a problem with the code. SystemParametersInfo is throwing an error and saying I have invalid arguments.
I am not sure what I should be entering as far as parameters.
SPI uiAction, uint uiParam, ref Rect pvParam, SPIF fWinIni

I really just wish I understood the API better.
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15797
  • View blog
  • Posts: 63,297
  • Joined: 12-June 08

Re: Resizing the windows desktop(WorkArea) and adding a bar in the space

Posted 05 November 2015 - 09:55 AM

Please copy/paste the error code here.
Was This Post Helpful? 0
  • +
  • -

#6 ISPFALC   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 05-November 15

Re: Resizing the windows desktop(WorkArea) and adding a bar in the space

Posted 05 November 2015 - 09:59 AM

View PostSkydiver, on 05 November 2015 - 08:23 AM, said:

Why go through that painful process when you can use AppBars and let the OS manage the usable area for you?



I have never used this before. Could you show a small example. This is not a windows start bar is it? I just want to create a custom application that sits on the top of the window without being covered by other windows. Thank you!

View Postmodi123_1, on 05 November 2015 - 09:55 AM, said:

Please copy/paste the error code here.

Argument 1: cannot convert from 'int' to 'SPI'
Argument 4: cannot convert from 'int' to 'SPIF'

I am not sure what kind of data these arguments are looking for.
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7453
  • View blog
  • Posts: 25,095
  • Joined: 05-May 12

Re: Resizing the windows desktop(WorkArea) and adding a bar in the space

Posted 05 November 2015 - 10:03 AM

See CodeProject.
Was This Post Helpful? 0
  • +
  • -

#8 ISPFALC   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 05-November 15

Re: Resizing the windows desktop(WorkArea) and adding a bar in the space

Posted 05 November 2015 - 10:07 AM

View PostSkydiver, on 05 November 2015 - 10:03 AM, said:




This seems to be very useful thank you!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1