如何编程实现裁剪工作区

看到一个软件的效果是:在屏幕顶部显示Message Bar,它运行时整个桌面的工作区域都发生了偏移,并且其它程序最大化时,也不影响它,关闭时桌面恢复。 其它特性还包括: 点击"显示桌面"也不受影响,结束explorer.exe进程也不影响它。

 

其实关键代码是:

SystemParametersInfo(SPI_SETWORKAREA, Marshal.SizeOf(_WorkArea), ptr, SPIF_change);

 

参考地址: http://social.msdn.microsoft.com/Forums/pt-BR/winforms/thread/9fe831e5-ccfb-4e8d-a129-68c301c83acb (how to develop a taskbar)

 

Fazer uma Pergunta       

  • segunda-feira, 19 de junho de 2006 18:50
    Avatar de Jassim Rahma
    Jassim Rahma
    Avatar de Jassim Rahma

    Jassim Rahma

    Al Resalah Medical Cente...

    145 Pontos 6 0 0
    Realizações recentes.
    Perfil concluído Respostas em fóruns I Respondedor de código I
    Al Resalah Medical Cente...
    145 Points
                    
                                                
    Entrar para Votar
    0
    i want to develop an application which will be like a ticker above the windows taskbar and i need to reserve a space so the windows dekstop will be -taskbar -my ticker

                Todas as Respostas;           

  • segunda-feira, 19 de junho de 2006 18:58
    Avatar de Vikas - MSFT
    Vikas - MSFT
    Avatar de Vikas - MSFT

    Vikas - MSFT

    Microsoft India (R&D) Pv...

    Partner

    4.962 Pontos 6 3 2
    Realizações recentes.
    Starter de Participante Comentarista do Blog II Bloggers III
    Microsoft India (R&D) Pv...
                                        (Partner)                               
    4.962 Points
                    
                                                
    Entrar para Votar
    0
    can you please explain what you are trying to do. are you trying to emulate windows taskbar and want to recieve events for every new task being created/updated or destroyed.
  • segunda-feira, 19 de junho de 2006 19:25
    Avatar de Jassim Rahma
    Jassim Rahma
    Avatar de Jassim Rahma

    Jassim Rahma

    Al Resalah Medical Cente...

    145 Pontos 6 0 0
    Realizações recentes.
    Perfil concluído Respostas em fóruns I Respondedor de código I
    Al Resalah Medical Cente...
    145 Points
                    
                                                
    Entrar para Votar
    0

    no

    i want to develop something like a news ticker which should resize the windows desktop because application should be always on top and i don't want to disturb other application by being on the top of it so i prefer to have a space for me to put my applicatio on it which will be above the taskbar

  • segunda-feira, 19 de junho de 2006 19:34
    Avatar de Vikas - MSFT
    Vikas - MSFT
    Avatar de Vikas - MSFT

    Vikas - MSFT

    Microsoft India (R&D) Pv...

    Partner

    4.962 Pontos 6 3 2
    Realizações recentes.
    Starter de Participante Comentarista do Blog II Bloggers III
    Microsoft India (R&D) Pv...
                                        (Partner)                               
    4.962 Points
                    
                                                
    Entrar para Votar
    0

    use the following code to resize the work area (the area in which an application can be maximized)

    Public Declare Function SystemParametersInfo Lib "user32.dll" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
    Public Const SPI_SETWORKAREA As Long = 47
    Public Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type

    Public Function SetWorkingArea()
    Dim WorkArea As RECT

        With WorkArea
            .Left = 0
            .Top = 0
            .Bottom = 768
            .Right = 1024
        End With
       
        SystemParametersInfo SPI_SETWORKAREA, Len(WorkArea), WorkArea, 1
    End Function

    please make sure to refresh the work area again if sumone resize or move the taskbar.

  • segunda-feira, 19 de junho de 2006 19:43
    Avatar de Jassim Rahma
    Jassim Rahma
    Avatar de Jassim Rahma

    Jassim Rahma

    Al Resalah Medical Cente...

    145 Pontos 6 0 0
    Realizações recentes.
    Perfil concluído Respostas em fóruns I Respondedor de código I
    Al Resalah Medical Cente...
    145 Points
                    
                                                
    Entrar para Votar
    0

    sorry... forgot to say I am using C#

  • quarta-feira, 21 de junho de 2006 16:16
    Avatar de Vikas - MSFT
    Vikas - MSFT
    Avatar de Vikas - MSFT

    Vikas - MSFT

    Microsoft India (R&D) Pv...

    Partner

    4.962 Pontos 6 3 2
    Realizações recentes.
    Starter de Participante Comentarista do Blog II Bloggers III
    Microsoft India (R&D) Pv...
                                        (Partner)                               
    4.962 Points
                    
                                                
    Entrar para Votar
    1

    Sorry for late reply

    Please use the following class to set the work area

    using

    System;

    using

    System.Runtime.InteropServices;

    public class WorkArea

    {

    [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint="SystemParametersInfoA")]

    private static extern Int32 SystemParametersInfo(Int32 uAction, Int32 uParam, IntPtr lpvParam, Int32 fuWinIni);

    private const Int32 SPI_SETWORKAREA = 47;

    public WorkArea(Int32 Left,Int32 Right,Int32 Top,Int32 Bottom)

    {

    _WorkArea.Left = Left;

    _WorkArea.Top = Top;

    _WorkArea.Bottom = Bottom;

    _WorkArea.Right = Right;

    }

    public struct RECT

    {

    public Int32 Left;

    public Int32 Right;

    public Int32 Top;

    public Int32 Bottom;

    }

    private RECT _WorkArea;

    public void SetWorkingArea()

    {

    IntPtr ptr=IntPtr.Zero;

    ptr = Marshal.AllocHGlobal(Marshal.SizeOf(_WorkArea));

    Marshal.StructureToPtr(_WorkArea,ptr,

    false);

    int i=SystemParametersInfo(SPI_SETWORKAREA,0,ptr,0);

    }

    }

  • quarta-feira, 13 de junho de 2007 22:57
    Avatar de Vinay Pole
    Vinay Pole
    Avatar de Vinay Pole

    Vinay Pole

    Partner

    0 Pontos 1 0 0
    Realizações recentes.
    Primeira resp. em fóruns
                                        (Partner)                               
    0 Points
                    
                                                
    Entrar para Votar
    0

    How do i make other windows automatically adjust to the reduced working area. The SendNotifyMessage does not seem to work.?

    Please help.

    Vinay

  • quinta-feira, 14 de junho de 2007 11:53
    Avatar de Vikas Verma [MSFT]
    Vikas Verma [MSFT]
    Avatar de Vikas Verma [MSFT]

    Vikas Verma [MSFT]

    15 Pontos 1 0 0
    Realizações recentes.
    Primeira resp. em fóruns
    15 Points
                    
                                                
    Entrar para Votar
    0

     

    Declare following constants

     

    Code Snippet

    private const int SPIF_SENDWININICHANGE = 2;

    private const int SPIF_UPDATEINIFILE = 1;

    private const int SPIF_change = SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE;

    and use the following line of code

    Code Snippet

    int

    i = SystemParametersInfo(SPI_SETWORKAREA, Marshal.SizeOf(_WorkArea), ptr, SPIF_change);

    Let me know if you still face any problem

  • sexta-feira, 15 de junho de 2007 20:20
    Avatar de Vinay Pole
    Vinay Pole
    Avatar de Vinay Pole

    Vinay Pole

    Partner

    0 Pontos 1 0 0
    Realizações recentes.
    Primeira resp. em fóruns
                                        (Partner)                               
    0 Points
                    
                                                
    Entrar para Votar
    0

    It worked thanks very much

    I did my Get and Set Working area methods as below

    [

    DllImport("user32.dll", EntryPoint = "SystemParametersInfoA")]

    private static extern Int32 SystemParametersInfo(Int32 uAction, Int32 uParam, IntPtr lpvParam, Int32 fuWinIni);

    public static void GetWorkspace(ref RECT oRECT)

    {

    IntPtr ptr = IntPtr.Zero;

    ptr =

    Marshal.AllocHGlobal(Marshal.SizeOf(oRECT));

    Marshal.StructureToPtr(oRECT, ptr, true);

    SystemParametersInfo(SPI_GETWORKAREA,

    Marshal.SizeOf(oRECT), ptr, 0);

    oRECT = (

    RECT) Marshal.PtrToStructure(ptr, new RECT().GetType());

    }

    public static int SetWorkspace(RECT oRECT)

    {

    IntPtr ptr = IntPtr.Zero;

    ptr =

    Marshal.AllocHGlobal(Marshal.SizeOf(oRECT));

    Marshal.StructureToPtr(oRECT, ptr, true);

    return SystemParametersInfo(SPI_SETWORKAREA, Marshal.SizeOf(oRECT), ptr, SPIF_change);

    }

  • domingo, 17 de junho de 2007 21:42
    Avatar de nobugz
    nobugz
    Avatar de nobugz

    nobugz

    MVP

    235.820 Pontos 15 5 5
    Realizações recentes.
    Novo Classificador Respondedor proposto I Novo Comentarista do Blog
                                        (MVP)                               
    235.820 Points
    Moderador
                    
                                                
    Entrar para Votar
    0
    You are kinda fighting the system here.  Look into doing it this way...
  • segunda-feira, 25 de junho de 2007 18:58
    Avatar de Vinay Pole
    Vinay Pole
    Avatar de Vinay Pole

    Vinay Pole

    Partner

    0 Pontos 1 0 0
    Realizações recentes.
    Primeira resp. em fóruns
                                        (Partner)                               
    0 Points
                    
                                                
    Entrar para Votar
    0

    Hi Vikas,

      Iam coming across some issues with the docking sidebar on WIndows XP and Windows 2000 Systems. On XP the Sidebar reduces the work area as defined by its width and docks to the extreme right(in this case other windows get aligned to the left of the appbar and the appbars right is aligned with the right of the desktop before the work area was reduced) when i have an option set for Sidebar. If it is not a sidebar(reset actual work area) then i can drag my window and place it anywhere on the desktop. It works perfectly fine as desired.. But when i run the application on Windows 2000/2003 systems, the application when set as sidebar gets docked to the reduced desktop work area(the bars right is aligned with the right of reduced work area and all other windows right is aligned with bars left) leaving a blank space at the right of the desktop whose width is equal to the bars width.. It seems like it reduces the work area and then docks to the right(of the reduced work area) unlike in Windows XP system. iam not sure why this different behaviour on different systems.

    Can you help.. Appreciate your earlier help. I hope i explained the problem correctly.

    Thanks,

    Vinay

  • segunda-feira, 25 de junho de 2007 20:15
    Avatar de Ðãvę Âņđęŕŝőŋ1
    Ðãvę Âņđęŕŝőŋ1
    Avatar de Ðãvę Âņđęŕŝőŋ1

    Ðãvę Âņđęŕŝőŋ1

    1.760 Pontos 5 2 0
    Realizações recentes.
    Respondedor de fóruns III Respostas em fóruns III Respondedor de fóruns II
    1.760 Points
                    
                                                
    Entrar para Votar
    0
    You need to register your form as an "AppBar".  Click here.

    I used this tutorial about a year ago and it worked just fine. With the class he made in that article you are able to register your application as an "AppBar" just like the taskbar. There are different dock modes you can set as well.
  • terça-feira, 3 de julho de 2007 18:42
    Avatar de Maxtormax
    Maxtormax
    Avatar de Maxtormax

    Maxtormax

    0 Pontos 1 0 0
    Realizações recentes.
    Primeira resp. em fóruns
    0 Points
                    
                                                
    Entrar para Votar
    0
    Hi all.. Can any one help me finding a VB .net version of the code in the above article.  I read through the blog and found Vikas having some info about it. I would really appreciate you help guys.. thanks
  • quarta-feira, 4 de julho de 2007 00:42
    Avatar de Vinay Pole
    Vinay Pole
    Avatar de Vinay Pole

    Vinay Pole

    Partner

    0 Pontos 1 0 0
    Realizações recentes.
    Primeira resp. em fóruns
                                        (Partner)                               
    0 Points
                    
                                                
    Entrar para Votar
    0

    I was doing wrong code..it works on Windows 2000 as well..but some some reason, the form docks to the reduced work area for a moment and then docks to the right corner of the desktop work area(original before reducing) and then it sets back the work area so that all other windows get refreshed to the reduced work area..

    I now need help on automatically resizing my form as taskbar is resized..right now thats not happening...How do i achieve that in C#?

    Vinay

  • sexta-feira, 6 de julho de 2007 14:18
    Avatar de Vikas Verma [MSFT]
    Vikas Verma [MSFT]
    Avatar de Vikas Verma [MSFT]

    Vikas Verma [MSFT]

    15 Pontos 1 0 0
    Realizações recentes.
    Primeira resp. em fóruns
    15 Points
                    
                                                
    Entrar para Votar
    1

    Max... although I have not tested it as its automatic conversion... hopefully it should work...

    Conversion Courtesy

    C# to VB.Net

    http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx

    VB.Net to C#

    http://www.developerfusion.co.uk/utilities/convertvbtocsharp.aspx

    Code Snippet

    Imports System

    Imports System.Runtime.InteropServices


    Public Class WorkArea



    <System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint := "SystemParametersInfoA")> _
    Private Shared Function SystemParametersInfo(ByVal uAction As Int32, ByVal uParam As Int32, ByVal lpvParam As IntPtr, ByVal fuWinIni As Int32) As Int32
    End Function

    Private Const SPI_SETWORKAREA As Int32 = 47

    Public Sub New(ByVal Left As Int32, ByVal Right As Int32, ByVal Top As Int32, ByVal Bottom As Int32)


      _WorkArea.Left = Left

      _WorkArea.Top = Top

      _WorkArea.Bottom = Bottom


      _WorkArea.Right = Right
    End Sub

    Public Structure RECT


      Public Left As Int32

      Public Right As Int32

      Public Top As Int32

      Public Bottom As Int32

    End Structure

    Private _WorkArea As RECT

    Public Sub SetWorkingArea()



      Dim ptr As IntPtr = IntPtr.Zero

      ptr = Marshal.AllocHGlobal(Marshal.SizeOf(_WorkArea))

      Marshal.StructureToPtr(_WorkArea, ptr, False)

      Dim i As Integer = SystemParametersInfo(SPI_SETWORKAREA, 0, ptr, 0)

    End Sub

    End Class

  • sexta-feira, 6 de julho de 2007 14:25
    Avatar de Vikas Verma [MSFT]
    Vikas Verma [MSFT]
    Avatar de Vikas Verma [MSFT]

    Vikas Verma [MSFT]

    15 Pontos 1 0 0
    Realizações recentes.
    Primeira resp. em fóruns
    15 Points
                    
                                                
    Entrar para Votar
    0

    Vinay,

    I am little confused about the requirements.

    You want to set the working area again as soon as someone resize the taskbar? Is that what you are trying to achieve?

 

<img alt="" border="0" id="DCSIMG" width="1" height="1" src="http://m.webtrends.com/dcsour5e80000008ybade4ttg_1i1l/njs.gif?dcsuri=/nojavascript&WT.js=No"> <a href="http://www.omniture.com" title="Web Analytics"> <img src="http://msstonojssocial.112.2O7.net/b/ss/msstonojssocial/1/H.20.2--NS/0" height="1" width="1" alt="" /> </a>

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看REaDME.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值