Sascha
Sascha

Reputation: 21

Use SHAppBarMessage to move Taskbar

I am trying to move MY taskbar programmatically using the win32 function SHAppBarMessage() with the parameter ABM_SETPOS.

I know & follow the mantra "Always keep the user in control" & I know some will say that there is no reason for an app to do this. I am learning win32 & this problem has been getting the best of me for a while & that always makes me want to solve the this problem even more! If there is a function SHAppBarMessage then windows must ALLOW you to move the taskbar.

Could you offer advice on how I can get SHAppBarMessage to move the taskbar to the right?

My code below uses two methods to attempt to move the taskbar to the right border of my screen. Both methods fail & I am beginning to think that maybe windows 7 will not allow you to move the task bar although I have searched MSDN & none of the documentation suggests it is depreciated.

1st method follows the polite standard of 1st using ABM_QUERYPOS before I attempt ABM_SETPOS, but this doesn't move the taskbar.

BOOL moveTaskBar( UINT pos, bool a )
{
// Post:

APPBARDATA barData;
RECT       barRect;
HWND       hTaskbar = FindWindow( "Shell_TrayWnd", NULL );

SetRect( &barRect, 1310, 10, 1350, 740 ); // These dimensions & coords are within my screens bounds so thats not a problem

barData.cbSize           =  sizeof(APPBARDATA);
barData.hWnd             =  hTaskbar;
barData.uCallbackMessage =  0;
barData.uEdge            =  pos;
barData.rc               =  barRect;
barData.lParam           = (LPARAM) FALSE;

BOOL fResult = (BOOL) SHAppBarMessage( ABM_QUERYPOS, &barData ); // Get system to verify & suggest position
fResult = (BOOL) SHAppBarMessage( ABM_SETPOS, &barData );        // Set position
fResult = (BOOL) SHAppBarMessage( ABM_WINDOWPOSCHANGED, &barData ); // Inform ??? that the taskbar pos has been changed

// Debugging
// fResult = (BOOL) SHAppBarMessage( ABM_ACTIVATE, &barData );
// fResult = (BOOL) SHAppBarMessage( ABM_GETTASKBARPOS, &barData );


return ( fResult == 0 );
}

My second method attempts to force the taskbar HWND to move to an x,y position, this is something that I wouldn't like to do, but I am trying to find a method to move the taskbar, but anyway this method also doesn't work. Which makes me think you cannot move the taskbar in Windows 7?

BOOL moveTaskBar( UINT pos )
{
// Post:

HWND       hTaskbar = FindWindow( "Shell_TrayWnd", NULL );

SetWindowPos(hTaskbar, NULL, barData.rc.left, barData.rc.top, barData.rc.right, barData.rc.bottom, SWP_NOSENDCHANGING);
ShowWindow(hTaskbar, SW_SHOW);

UpdateWindow(hTaskbar);

HWND hDesktopWindow = GetDesktopWindow();

RedrawWindow( hDesktopWindow, NULL, NULL, RDW_FRAME|RDW_INVALIDATE|RDW_UPDATENOW|RDW_ALLCHILDREN );

SystemParametersInfo(SPI_SETWORKAREA, 0, NULL, SPIF_SENDCHANGE);

UpdateWindow(hDesktopWindow);

}

Upvotes: 2

Views: 3527

Answers (2)

gokdfgfokg
gokdfgfokg

Reputation: 1

That is not true. you can use a function to register the taskbar to a specific user you create within the program and then move it

Upvotes: 0

Ana Betts
Ana Betts

Reputation: 74654

There is no way to do this, the user owns that setting, not your program (I know that you might be the user of your own program, but that's why).

Upvotes: 1

Related Questions