471,050 Members | 1,331 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,050 software developers and data experts.

Moving windows takbar?

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(LayoutKind.Sequential)]
public struct APPBARDATA
{
public UInt32 cbSize;
public IntPtr hWnd;
public UInt32 uCallbackMessage;
public UInt32 uEdge;
public RECT rc;
public Int32 lParam;
}

[DllImport("shell32.dll")]
public static extern UInt32 SHAppBarMessage(UInt32 dwMessage,ref APPBARDATA pData);
private const int ABM_SETPOS = 0x3;
private const int ABM_GETTASKBARPOS = 0x5;

Code:
APPBARDATA msgData = new APPBARDATA();
msgData.cbSize = (UInt32)Marshal.SizeOf(msgData);
msgData.hWnd = (System.IntPtr)Handle;
SHAppBarMessage(ABM_GETTASKBARPOS, ref msgData);
msgData.uEdge=1; //for moving i to the top
msgData.rc.top=0;
msgData.rc.bottom=34;
SHAppBarMessage(ABM_SETPOS, ref msgData);

Nov 16 '05 #1
2 10074
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(LayoutKind.Sequential)]
public struct APPBARDATA
{
public UInt32 cbSize;
public IntPtr hWnd;
public UInt32 uCallbackMessage;
public UInt32 uEdge;
public RECT rc;
public Int32 lParam;
}

[DllImport("shell32.dll")]
public static extern UInt32 SHAppBarMessage(UInt32 dwMessage,ref APPBARDATA pData);
private const int ABM_SETPOS = 0x3;
private const int ABM_GETTASKBARPOS = 0x5;

Code:
APPBARDATA msgData = new APPBARDATA();
msgData.cbSize = (UInt32)Marshal.SizeOf(msgData);
msgData.hWnd = (System.IntPtr)Handle;
SHAppBarMessage(ABM_GETTASKBARPOS, ref msgData);
msgData.uEdge=1; //for moving i to the top
msgData.rc.top=0;
msgData.rc.bottom=34;
SHAppBarMessage(ABM_SETPOS, ref msgData);

[DllImport("User32.dll", ExactSpelling=true,
CharSet=System.Runtime.InteropServices.CharSet.Aut o)]
private static extern bool MoveWindow(IntPtr hWnd, int x, int y, int cx,
int cy, bool repaint);

[DllImport("Shell32.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_SETAUTOHIDEBAR = 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(LayoutKind.Sequential)]
private struct APP_BAR_DATA
{
public int cbSize;
public IntPtr hWnd;
public int uCallbackMessage;
public int uEdge;
public RECT rc;
public IntPtr lParam;
}

[StructLayout(LayoutKind.Sequential)]
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(IntPtr 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 = SystemInformation.PrimaryMonitorSize.Height;
if (edge == ABE_LEFT)
{
abd.rc.right = idealSize.Width;
}
else
{
abd.rc.right = SystemInformation.PrimaryMonitorSize.Width;
abd.rc.left = abd.rc.right - idealSize.Width;
}

}
else
{
abd.rc.left = 0;
abd.rc.right = SystemInformation.PrimaryMonitorSize.Width;
if (edge == ABE_TOP)
{
abd.rc.bottom = idealSize.Height;
}
else
{
abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height;
abd.rc.top = abd.rc.bottom - idealSize.Height;
}
}

// 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.Height;
break;
case ABE_BOTTOM:
abd.rc.top = abd.rc.bottom - idealSize.Height;
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
Nov 16 '05 #2
Thanks!!!
KalleD
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Mark S Pryor | last post: by
5 posts views Thread by Pablo Cedeno | last post: by
4 posts views Thread by Ron Mexico | last post: by
6 posts views Thread by Woody Splawn | last post: by
2 posts views Thread by Carl Gilbert | last post: by
4 posts views Thread by Nathaniel | last post: by
1 post views Thread by rsteph | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.