/* ----------------------------------------------------------------------

	CNFTEST sample for Microsoft ActiveX Conferencing

	Copyright (c) 1996, Microsoft Corporation
	All rights reserved.

	sbar.c - Status bar routines


---------------------------------------------------------------------- */

#include "main.h"


/* M S G  N O T I F Y */
/*----------------------------------------------------------------------------
	%%Function: MsgNotify

----------------------------------------------------------------------------*/
LRESULT MsgNotify(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
	LPTOOLTIPTEXT lpToolTipText;
	static char szBuffer[MAX_PATH];

	lpToolTipText = (LPTOOLTIPTEXT)lparam;
	switch (lpToolTipText->hdr.code)
		{
	case TTN_NEEDTEXT:
	{
		int cb;

		// Try special toolbar version first
		cb = LoadString(ghInst, lpToolTipText->hdr.idFrom - 10000,
			szBuffer, sizeof(szBuffer));
		if (cb == 0)
		{
			cb = LoadString(ghInst, lpToolTipText->hdr.idFrom,   // string ID == command ID
				szBuffer, sizeof(szBuffer));
		}
		if (cb == 0)
		{
			szBuffer[0] = '\0';
		}

		lpToolTipText->lpszText = szBuffer;
		break;
	}
	case TBN_QUERYINSERT:
	case TBN_QUERYDELETE:
		return 1;
	case PSM_SETCURSEL:
		return 1;
	default:
		break;
		}

	return 0;
}



/* F  C R E A T E  S B A R */
/*----------------------------------------------------------------------------
	%%Function: FCreateSbar

	Create the status bar.

----------------------------------------------------------------------------*/
BOOL FCreateSbar(void)
{
	ghwndSbar = CreateWindow(STATUSCLASSNAME, NULL,
		WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
		0, 0, 0, 0,
		ghwndMain, (HMENU) IDW_SBAR, ghInst, NULL);

	return (ghwndSbar != NULL);
}



/* U P D A T E  S T A T U S  B A R */
/*----------------------------------------------------------------------------
	%%Function: UpdateStatusBar

	Update the text for part of the status bar

----------------------------------------------------------------------------*/
void UpdateStatusBar(LPSTR lpsz, WORD wPart, WORD wFlags)
{
	SendMessage(ghwndSbar, SB_SETTEXT, wPart | wFlags, (LPARAM) lpsz);
}



/* M S G  M E N U  S E L E C T */
/*----------------------------------------------------------------------------
	%%Function: MsgMenuSelect

	Change the status bar text to display the menu help.

----------------------------------------------------------------------------*/
LRESULT MsgMenuSelect(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
	static char szBuffer[MAX_PATH];
	UINT   nStringID;
	UINT   fuFlags = GET_WM_MENUSELECT_FLAGS(wparam, lparam) & 0xffff;
	UINT   uCmd    = GET_WM_MENUSELECT_CMD(wparam, lparam);
	HMENU  hMenu   = GET_WM_MENUSELECT_HMENU(wparam, lparam);

	szBuffer[0] = 0;
	nStringID = 0;

	if (fuFlags == 0xffff && hMenu == NULL)     // Menu has been closed
	{
		return 0;
	}
	else if (fuFlags & MFT_SEPARATOR)           // Ignore separators
	{
		nStringID = 0;
	}
	else if (fuFlags & MF_POPUP)                // Popup menu
	{
		if (fuFlags & MF_SYSMENU)               // System menu
			nStringID = IDS_SYSMENU;
	}
	else                                        // Must be a command item
	{
		nStringID = uCmd;               // String ID == Command ID
	}

	// Load the string if we have an ID
	if (nStringID != 0)
		LoadString(ghInst, nStringID, szBuffer, sizeof(szBuffer));

	// Finally... send the string to the status bar
	UpdateStatusBar(szBuffer, 0, 0);

	return 0;
}
