KalleD wrote:
Why can I not move the windows taskbar with the SHAppBarMessage function?
I am able to use the function for hiding it and other things, but not moving it (I have unchecked the lock). The code is below.
Super greatefull for an answer!
KalleD
Declarations:
[StructLayout(La youtKind.Sequen tial)]
public struct APPBARDATA
{
public UInt32 cbSize;
public IntPtr hWnd;
public UInt32 uCallbackMessag e;
public UInt32 uEdge;
public RECT rc;
public Int32 lParam;
}
[DllImport("shel l32.dll")]
public static extern UInt32 SHAppBarMessage (UInt32 dwMessage,ref APPBARDATA pData);
private const int ABM_SETPOS = 0x3;
private const int ABM_GETTASKBARP OS = 0x5;
Code:
APPBARDATA msgData = new APPBARDATA();
msgData.cbSize = (UInt32)Marshal .SizeOf(msgData );
msgData.hWnd = (System.IntPtr) Handle;
SHAppBarMessage (ABM_GETTASKBAR POS, ref msgData);
msgData.uEdge=1 ; //for moving i to the top
msgData.rc.top= 0;
msgData.rc.bott om=34;
SHAppBarMessage (ABM_SETPOS, ref msgData);
[DllImport("User 32.dll", ExactSpelling=t rue,
CharSet=System. Runtime.Interop Services.CharSe t.Auto)]
private static extern bool MoveWindow(IntP tr hWnd, int x, int y, int cx,
int cy, bool repaint);
[DllImport("Shel l32.dll", CharSet=CharSet .Auto)]
private static extern int SHAppBarMessage (int dwMessage, ref
APP_BAR_DATA abd);
private const int ABM_NEW = 0x00;
private const int ABM_REMOVE = 0x01;
private const int ABM_QUERYPOS = 0x02;
private const int ABM_SETPOS = 0x03;
private const int ABM_SETAUTOHIDE BAR = 0x08;
private const int ABM_SETSTATE = 0x0000000a;
private const int ABE_LEFT = 0;
private const int ABE_TOP = 1;
private const int ABE_RIGHT = 2;
private const int ABE_BOTTOM = 3;
private const int ABS_AUTOHIDE = 0x01;
private const int ABS_ALWAYSONTOP = 0x02;
[StructLayout(La youtKind.Sequen tial)]
private struct APP_BAR_DATA
{
public int cbSize;
public IntPtr hWnd;
public int uCallbackMessag e;
public int uEdge;
public RECT rc;
public IntPtr lParam;
}
[StructLayout(La youtKind.Sequen tial)]
private struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
public RECT(int left, int top, int right, int bottom)
{
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
public static RECT FromXYWH(int x, int y, int width, int height)
{
return new RECT(x, y, x + width, y + height);
}
}
internal static void DockAppBar(IntP tr hWnd, int edge, Size idealSize)
{
APP_BAR_DATA abd = new APP_BAR_DATA();
abd.cbSize = Marshal.SizeOf( abd);
abd.hWnd = hWnd;
abd.uEdge = edge;
if (edge == ABE_LEFT || edge == ABE_RIGHT)
{
abd.rc.top = 0;
abd.rc.bottom = SystemInformati on.PrimaryMonit orSize.Height;
if (edge == ABE_LEFT)
{
abd.rc.right = idealSize.Width ;
}
else
{
abd.rc.right = SystemInformati on.PrimaryMonit orSize.Width;
abd.rc.left = abd.rc.right - idealSize.Width ;
}
}
else
{
abd.rc.left = 0;
abd.rc.right = SystemInformati on.PrimaryMonit orSize.Width;
if (edge == ABE_TOP)
{
abd.rc.bottom = idealSize.Heigh t;
}
else
{
abd.rc.bottom = SystemInformati on.PrimaryMonit orSize.Height;
abd.rc.top = abd.rc.bottom - idealSize.Heigh t;
}
}
// Query the system for an approved size and position.
SHAppBarMessage (ABM_QUERYPOS, ref abd);
// Adjust the rectangle, depending on the edge to which the
// appbar is anchored.
switch (edge)
{
case ABE_LEFT:
abd.rc.right = abd.rc.left + idealSize.Width ;
break;
case ABE_RIGHT:
abd.rc.left= abd.rc.right - idealSize.Width ;
break;
case ABE_TOP:
abd.rc.bottom = abd.rc.top + idealSize.Heigh t;
break;
case ABE_BOTTOM:
abd.rc.top = abd.rc.bottom - idealSize.Heigh t;
break;
}
// Pass the final bounding rectangle to the system.
SHAppBarMessage (ABM_SETPOS, ref 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);
}
Cheers
Arne Janning