473,326 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 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 10413
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mark S Pryor | last post by:
hello c.l.p., I'm using: Python 2.2 (ActiveState) Win2k sp3 P4 2GHz, 512 RAM Matrox p550 (dual head video card) I run my desktop at 2560 x 1024. When I get involved manually resizing and...
5
by: Pablo Cedeno | last post by:
Hi all, I'm having a problem with a form position. I need to prevent the user to drag the window. I tried to maximize the window but i still can move the window. I found something about...
4
by: Ron Mexico | last post by:
Hi, Currently have an app that maintain that is written in VB6 and uses an access db (backend db only used as a data store not writing to the db). This app is a client app not server multi-teir...
6
by: Woody Splawn | last post by:
I have been using SQL Server 2000 on my stand-alone machine as a back-end to a VS.net application. It is time to switch environments and take the application to the customer. I need to install...
3
by: Just Me | last post by:
If I move the mouse cursor over a control and stop moving I get a MouseHover event. If I then move the cursor while staying within the control and then stop moving I do not get another...
2
by: Carl Gilbert | last post by:
Hi I have a math kinda problem where I'm trying to split some lines when two or more lines connect two shapes. The reason I am doing this is to make it clear that there are multiple lines...
4
by: Nathaniel | last post by:
How do i move windows in vb.net?
1
by: rsteph | last post by:
I bought a book to help me learn to use DirectX with windows programming. It's first trying to walk me through some basic windows programming and graphics before getting into DirectX. I'm trying to...
4
by: summerchase | last post by:
Hi. Has anyone ever seen a problem with Windows Vista where you can't close a window with the X, nor can you move a small window by dragging? Any answers?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.