I am having a really strange issue with SHAppBarMessage
, have been trying out different things for few hours now but i am not getting it. I am trying to get the TaskBar Position. It works fine on Windows 8 but on Windows Server the return value is SHAppBarMessage
.
The following code from an answer works from fine on Windows 8, but on Windows 2008R2 it has a strange behavior.
public static System.Drawing.Rectangle GetTaskbarPosition()
{
var data = new APPBARDATA();
data.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(data);
IntPtr retval = SHAppBarMessage(ABM_GETTASKBARPOS, ref data);
if (retval == IntPtr.Zero) throw new Exception("Please re-install Windows");
return new System.Drawing.Rectangle(data.rc.left, data.rc.top,
data.rc.right - data.rc.left, data.rc.bottom - data.rc.top);
}
// P/Invoke goo:
private const int ABM_GETTASKBARPOS = 5;
[System.Runtime.InteropServices.DllImport("shell32.dll")]
private static extern IntPtr SHAppBarMessage(int msg, ref APPBARDATA data);
private struct APPBARDATA
{
public int cbSize;
public IntPtr hWnd;
public int uCallbackMessage;
public int uEdge;
public RECT rc;
public IntPtr lParam;
}
private struct RECT
{
public int left, top, right, bottom;
}
I am totally out of ideas. As it should work as it is. But i dont know why it is not working. Am i missing something?
StructLayoutAttribute
onAPPBARDATA
andRECT
pinvoke.net/default.aspx/shell32/APPBARDATA.html – KoziarzSTAThreadAttribute
on theMain
function. And try the code again, but in a WinForms project. Hook the code up to a button? – KoziarzHWND
forShell_TrayWnd
first. edn.embarcadero.com/article/26977 – Koziarz