看到一个软件的效果是:在屏幕顶部显示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:50Jassim Rahma
Jassim Rahma
Al Resalah Medical Cente...
145 Pontos 6 0 0Realizações recentes.Perfil concluído Respostas em fóruns I Respondedor de código IAl Resalah Medical Cente...145 Pointsi 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:58Vikas - MSFT
Vikas - MSFT
Microsoft India (R&D) Pv...
Partner
4.962 Pontos 6 3 2Realizações recentes.Starter de Participante Comentarista do Blog II Bloggers IIIMicrosoft India (R&D) Pv...(Partner)4.962 Pointscan 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:25Jassim Rahma
Jassim Rahma
Al Resalah Medical Cente...
145 Pontos 6 0 0Realizações recentes.Perfil concluído Respostas em fóruns I Respondedor de código IAl Resalah Medical Cente...145 Pointsno
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:34Vikas - MSFT
Vikas - MSFT
Microsoft India (R&D) Pv...
Partner
4.962 Pontos 6 3 2Realizações recentes.Starter de Participante Comentarista do Blog II Bloggers IIIMicrosoft India (R&D) Pv...(Partner)4.962 Pointsuse 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 TypePublic Function SetWorkingArea()
Dim WorkArea As RECTWith WorkArea
.Left = 0
.Top = 0
.Bottom = 768
.Right = 1024
End With
SystemParametersInfo SPI_SETWORKAREA, Len(WorkArea), WorkArea, 1
End Functionplease make sure to refresh the work area again if sumone resize or move the taskbar.
-
segunda-feira, 19 de junho de 2006 19:43Jassim Rahma
Jassim Rahma
Al Resalah Medical Cente...
145 Pontos 6 0 0Realizações recentes.Perfil concluído Respostas em fóruns I Respondedor de código IAl Resalah Medical Cente...145 Pointssorry... forgot to say I am using C#
-
quarta-feira, 21 de junho de 2006 16:16Vikas - MSFT
Vikas - MSFT
Microsoft India (R&D) Pv...
Partner
4.962 Pontos 6 3 2Realizações recentes.Starter de Participante Comentarista do Blog II Bloggers IIIMicrosoft India (R&D) Pv...(Partner)4.962 PointsSorry 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:57Vinay Pole
Vinay Pole
Partner
0 Pontos 1 0 0Realizações recentes.Primeira resp. em fóruns(Partner)0 PointsHow 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:53Vikas Verma [MSFT]
Vikas Verma [MSFT]
15 Pontos 1 0 0Realizações recentes.Primeira resp. em fórunsDeclare following constants
Code Snippetprivate 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 Snippetint
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:20Vinay Pole
Vinay Pole
Partner
0 Pontos 1 0 0Realizações recentes.Primeira resp. em fóruns(Partner)0 PointsIt 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:42nobugz
nobugz
MVP
235.820 Pontos 15 5 5Realizações recentes.Novo Classificador Respondedor proposto I Novo Comentarista do Blog(MVP)235.820 PointsModeradorYou are kinda fighting the system here. Look into doing it this way...
-
segunda-feira, 25 de junho de 2007 18:58Vinay Pole
Vinay Pole
Partner
0 Pontos 1 0 0Realizações recentes.Primeira resp. em fóruns(Partner)0 PointsHi 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Ðãvę Âņđęŕŝőŋ1
Ðãvę Âņđęŕŝőŋ1
1.760 Pontos 5 2 0Realizações recentes.Respondedor de fóruns III Respostas em fóruns III Respondedor de fóruns IIYou 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:42Hi 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:42Vinay Pole
Vinay Pole
Partner
0 Pontos 1 0 0Realizações recentes.Primeira resp. em fóruns(Partner)0 PointsI 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:18Vikas Verma [MSFT]
Vikas Verma [MSFT]
15 Pontos 1 0 0Realizações recentes.Primeira resp. em fórunsMax... 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 SnippetImports 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:25Vikas Verma [MSFT]
Vikas Verma [MSFT]
15 Pontos 1 0 0Realizações recentes.Primeira resp. em fórunsVinay,
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>