Setting the Appbar Size and Position

An application should set an appbar's size and position after registering the appbar, after the user user moves or sizes the appbar, and whenever the appbar receives the ABN_POSCHANGED notification message. Before setting the size and position of the appbar, the application queries the system for an approved bounding rectangle by sending the ABM_QUERYPOS message. The system returns a bounding rectangle that does not interfere with the taskbar or any other appbar. The system adjusts the rectangle purely by rectangle subtraction; it makes no effort to preserve the rectangle's initial size. For this reason, the appbar should readjust the rectangle, as necessary, after sending ABM_QUERYPOS.

Next, the application passes the bounding rectangle back to the system by using the ABM_SETPOS message. Then it calls the MoveWindow function to move the appbar into position.

The following example shows how to set an appbar's size and position.

// AppBarQuerySetPos - sets the size and position of an appbar.

// uEdge - screen edge to which the appbar is to be anchored

// lprc - current bounding rectangle of the appbar

// pabd - address of APPBARDATA structure with the hWnd and

// cbSize members filled

void PASCAL AppBarQuerySetPos(UINT uEdge, LPRECT lprc, PAPPBARDATA pabd)

{

int iHeight = 0;

int iWidth = 0;

pabd->rc = *lprc;

pabd->uEdge = uEdge;

// Copy the screen coordinates of the appbar's bounding

// rectangle into the APPBARDATA structure.

if ((uEdge == ABE_LEFT) ||

(uEdge == ABE_RIGHT)) {

iWidth = pabd->rc.right - pabd->rc.left;

pabd->rc.top = 0;

pabd->rc.bottom = GetSystemMetrics(SM_CYSCREEN);

} else {

iHeight = pabd->rc.bottom - pabd->rc.top;

pabd->rc.left = 0;

pabd->rc.right = GetSystemMetrics(SM_CXSCREEN);

}

// Query the system for an approved size and position.

SHAppBarMessage(ABM_QUERYPOS, pabd);

// Adjust the rectangle, depending on the edge to which the

// appbar is anchored.

switch (uEdge) {

case ABE_LEFT:

pabd->rc.right = pabd->rc.left + iWidth;

break;

case ABE_RIGHT:

pabd->rc.left = pabd->rc.right - iWidth;

break;

case ABE_TOP:

pabd->rc.bottom = pabd->rc.top + iHeight;

break;

case ABE_BOTTOM:

pabd->rc.top = pabd->rc.bottom - iHeight;

break;

}

// Pass the final bounding rectangle to the system.

SHAppBarMessage(ABM_SETPOS, pabd);

// Move and size the appbar so that it conforms to the

// bounding rectangle passed to the system.

MoveWindow(pabd->hWnd, pabd->rc.left, pabd->rc.top,

pabd->rc.right - pabd->rc.left,

pabd->rc.bottom - pabd->rc.top, TRUE);

}