home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 8
/
CDASC08.ISO
/
NEWS
/
4418
/
DEMO
/
SOURCE.ZIP
/
GV_TBAR.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-22
|
31KB
|
789 lines
#include <windows.h>
#include <windowsx.h>
#include "winx31ad.h"
#include <string.h>
#include "GV_TBAR.h"
#define GETLPTBINFOHEADER(hwnd) ((LPTBINFOHEADER) GetWindowLong(hwnd,0))
// sequence /***+++***/ mark new WM_MENUITEM PostMessaging code
// plus message WM_CTLCOLORSTATIC renvoye
typedef struct
{
BOOL fButton; // Button or Window
UINT cxBefore;
UINT cx;
UINT cxAfter;
UINT cy;
// for Button :
WORD wId ; // ID of Button ou WIndow for Internal TB
WORD wIdFirst;
WORD wIdLast;
BYTE bStyle; // ACTION / RADIO / CHECK
WORD nFirst; // index to first toggle btn
WORD nLast; // index to last toggle btn
BYTE bState; // button state BTNS_RAISED, BTNS_PUSHED, BTNS_INVALID
WORD wPosBitmap; //
// for Window :
HWND hWnd; // Handle of the Windows (child of toolbar)
// private :
RECT Emplact;
} TBELEM;
typedef TBELEM FAR* LPTBELEM;
typedef struct
{
HWND hwndParent;
HWND hwndTB;
HBITMAP hPictBtn;
WORD wNbElem ; // Number of Btn or Window in TB
UINT wLastx;
UINT wFirstx,wFirsty;
LPTBELEM lpTbFirst;
LPTBELEM lpTbInPush;
BYTE bOldStateInPush;
BYTE bStateInPush;
BOOL fMouseOnButton;
} TBINFOHEADER;
typedef TBINFOHEADER FAR* LPTBINFOHEADER;
char szClassName[] = "classToolBar";
// Function prototyping
static BOOL AddBtnIndirect (HWND hWndTB,LPTBELEM lpBtnCreateStruct);
//BOOL SetBtnState (HWND hWndTB,WORD wId,BYTE bState);
//BOOL DelTbElem (HWND hWndTB,WORD wId);
//BOOL DeleteTB (HWND hWndTB,WORD wId);
LRESULT CALLBACK ToolbarWndProc (HWND hwnd, UINT uiMsg,
WPARAM wParam, LPARAM lParam);
// --------------------------------------------------------------------------
// FUNCTION RegisterTBClass
// PURPOSE Register the class of toolbar window
// --------------------------------------------------------------------------
// INPUT hInst Handle of instace
// OUTPUT TRUE if registering is OK
// --------------------------------------------------------------------------
// COMMENTS ...
// --------------------------------------------------------------------------
BOOL RegisterTBClass (HINSTANCE hInst)
{
WNDCLASS wc;
wc.style = 0;
wc.lpfnWndProc = ToolbarWndProc ;
wc.cbClsExtra = 0 ;
wc.cbWndExtra = sizeof(LPTBINFOHEADER) ;
wc.hInstance = hInst ;
wc.hIcon = NULL;
wc.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wc.hCursor = NULL ;
wc.hbrBackground = GetStockObject ( LTGRAY_BRUSH );
wc.lpszMenuName = (LPSTR) NULL ;
wc.lpszClassName = szClassName ;
if (!RegisterClass (&wc))
return (FALSE);
return TRUE;
}
// --------------------------------------------------------------------------
// FUNCTION UnregTBClass
// PURPOSE Unregister the class of toolbar window
// --------------------------------------------------------------------------
// INPUT hInst Handle of instace
// OUTPUT TRUE if unregistering is OK
// --------------------------------------------------------------------------
// COMMENTS ...
// --------------------------------------------------------------------------
BOOL UnregTBClass (HINSTANCE hInst)
{
return UnregisterClass(szClassName,hInst);
}
// --------------------------------------------------------------------------
// FUNCTION CreateTB
// PURPOSE Create the ToolBar window
// --------------------------------------------------------------------------
// INPUT hWndParent the handle of parent Toolbar
// hInst Handle of instace
// hPictBtn the handle of bitmap which contain Button
// rect the position of the ntoolbar in parent window
// OUTPUT the Handle of ToolBar window
// --------------------------------------------------------------------------
// COMMENTS The Toolbar class must be registered with RegisterTBClass
// before calling CreateTB
// --------------------------------------------------------------------------
HWND CreateTB (HWND hWndParent,HINSTANCE hInst,HBITMAP hPictBtn,RECT rect)
{
HWND hWndTB =
CreateWindow (szClassName, "ControlBar",
WS_CHILD,rect.left,rect.top,
rect.right-rect.left,rect.bottom-rect.top,
hWndParent,NULL, hInst, NULL) ;
SetBitmap (hWndTB,hPictBtn);
ShowWindow(hWndTB,SW_SHOW);
return hWndTB;
}
static BOOL AddBtnIndirect (HWND hWndTB,LPTBELEM lpBtnCreateStruct) ;
// --------------------------------------------------------------------------
// FUNCTION AddBtn
// PURPOSE Add a button on a toolbar
// --------------------------------------------------------------------------
// INPUT hWndTB the handle of ToolBar window
// wId IDentifier of the button to create
// wPosBitmap Index of the bitmap of the button in hPictBtn
// bStyle BTSY_xxx (see in the end of TOOLBAR.H)
// bState BTNS_xxx : initial state of the button
// cxBefore Space before button
// cxAfter Space after button
// wIdFirst,wIdLast id of the first and last button of a group
// (if bStyle = BSTY_GROUPTOOGLE[OPT])
// OUTPUT TRUE if the button is added
// --------------------------------------------------------------------------
// COMMENTS ...
// --------------------------------------------------------------------------
BOOL AddBtn (HWND hWndTB,WORD wId,WORD wPosBitmap,BYTE bStyle,BYTE bState,
WORD cxBefore,WORD cxAfter,WORD wIdFirst,WORD wIdLast)
{
TBELEM BtnCreateStruct;
BtnCreateStruct.fButton=TRUE;
BtnCreateStruct.cxBefore=cxBefore;
BtnCreateStruct.cxAfter=cxAfter;
BtnCreateStruct.cx=CXTBBUTTON-1;
BtnCreateStruct.cy=CYTBBUTTON;
BtnCreateStruct.wId=wId;
BtnCreateStruct.wIdFirst=wIdFirst;
BtnCreateStruct.wIdLast=wIdLast;
BtnCreateStruct.wPosBitmap=wPosBitmap;
BtnCreateStruct.bStyle=bStyle;
BtnCreateStruct.bState=bState;
return AddBtnIndirect(hWndTB,&BtnCreateStruct);
}
/***************************************************************************/
/***************************************************************************/
/* */
/* Function for WndProc */
/* */
/***************************************************************************/
/***************************************************************************/
// --------------------------------------------------------------------------
// FUNCTION CalcPosit
// PURPOSE calculate position of an element
// --------------------------------------------------------------------------
// INPUT lpTbInfoHeader toolbar's header
// lpNewElem elem to add
// lpElemPrec previous elem (NULL if first)
// OUTPUT lpElem is updated
// --------------------------------------------------------------------------
// COMMENTS ...
// --------------------------------------------------------------------------
static void CalcPosit(LPTBINFOHEADER lpTbInfoHeader,LPTBELEM lpNewElem,
LPTBELEM lpElemPrec)
{
lpNewElem->Emplact.bottom = lpNewElem -> cy +
(lpNewElem->Emplact.top = lpTbInfoHeader->wFirsty);
if (lpElemPrec == NULL) lpNewElem->Emplact.left= lpTbInfoHeader->wFirstx ;
else lpNewElem->Emplact.left=(lpElemPrec)->Emplact.right +
lpElemPrec->cxAfter ;
lpNewElem->Emplact.left += lpNewElem->cxBefore ;
lpNewElem->Emplact.right=lpNewElem->Emplact.left + lpNewElem->cx;
}
// --------------------------------------------------------------------------
// FUNCTION Toolbar_AddElem
// PURPOSE Add an element in toolber (btn or window)
// --------------------------------------------------------------------------
// INPUT lpTbInfoHeader toolbar's header
// lpElem elem to add
// OUTPUT lpTbInfoHeader new toolbar structure (old is destroy)
// --------------------------------------------------------------------------
// COMMENTS ...
// --------------------------------------------------------------------------
static LPTBELEM Toolbar_AddElem(LPTBINFOHEADER lpTbInfoHeader,
LPTBELEM lpElem)
{
WORD wNbElem = lpTbInfoHeader->wNbElem;
LPTBELEM lpTbFirst;
LPTBELEM lpNewElem;
lpTbFirst = lpTbInfoHeader->lpTbFirst;
if (lpTbFirst==NULL) lpTbFirst = (LPTBELEM) GlobalAllocPtr(GMEM_MOVEABLE,
(wNbElem+1)*sizeof(TBELEM));
else lpTbFirst = (LPTBELEM) GlobalReAllocPtr(lpTbFirst,
(wNbElem+1)*sizeof(TBELEM),GMEM_MOVEABLE);
lpTbInfoHeader->lpTbFirst = lpTbFirst;
lpNewElem = lpTbFirst + wNbElem;
_fmemcpy(lpNewElem,lpElem,sizeof(TBELEM));
CalcPosit(lpTbInfoHeader,lpNewElem,(wNbElem == 0) ? NULL : (lpNewElem-1));
lpTbInfoHeader->wNbElem ++;
return lpNewElem;
}
static BOOL AddBtnIndirect (HWND hwnd,LPTBELEM lpTbElem)
{
LPTBINFOHEADER lpTbInfoHeader ;
lpTbInfoHeader = GETLPTBINFOHEADER(hwnd);
Toolbar_AddElem(lpTbInfoHeader,lpTbElem);
return TRUE;
}
// --------------------------------------------------------------------------
// FUNCTION AddWndIndirect
// PURPOSE Add a window (control,... ) on a toolbar
// --------------------------------------------------------------------------
// INPUT hWndTB the handle of ToolBar window
// lpWindowInTbCreateStruct point to a structure which contain
// the information needed by CreateWindow
// OUTPUT TRUE if the button is added
// --------------------------------------------------------------------------
// COMMENTS ...
// --------------------------------------------------------------------------
HWND AddWndIndirect (HWND hwnd,LPWINDOWINTBCREATESTRUCT lpWindowInTbCreateStruct)
{
TBELEM tbElem;
LPTBELEM lpTbElem;
LPTBINFOHEADER lpTbInfoHeader ;
lpTbInfoHeader = GETLPTBINFOHEADER(hwnd);
tbElem.fButton = FALSE;
tbElem.cx = lpWindowInTbCreateStruct->cx;
tbElem.cxAfter = lpWindowInTbCreateStruct->cxAfter;
tbElem.cxBefore = lpWindowInTbCreateStruct->cxBefore;
tbElem.cy = lpWindowInTbCreateStruct->cy;
tbElem.wId = lpWindowInTbCreateStruct->wId;
lpTbElem = Toolbar_AddElem (lpTbInfoHeader,&tbElem);
SetWindowLong(hwnd,0,(LONG)lpTbInfoHeader);
lpTbElem->hWnd = CreateWindow(
lpWindowInTbCreateStruct->lpszClassName,
lpWindowInTbCreateStruct->lpszWindowName,
lpWindowInTbCreateStruct->dwstyle,
lpTbElem->Emplact.left,
lpTbElem->Emplact.top,
lpWindowInTbCreateStruct->cx,
lpWindowInTbCreateStruct->cy,
hwnd,
(HMENU)lpWindowInTbCreateStruct->wId,
lpWindowInTbCreateStruct->hOwner,
(LPVOID) NULL);
return lpTbElem->hWnd;
}
// --------------------------------------------------------------------------
// FUNCTION AddWnd
// PURPOSE Add a window (control,... ) on a toolbar
// --------------------------------------------------------------------------
// INPUT hWndTB the handle of ToolBar window
// cx, cxAfter, cxBefore,cy define space of window (see AddBtn)
// the other parameters contain the information needed by CreateWindow
// (see CreateWindow API for explanation)
// OUTPUT TRUE if the button is added
// --------------------------------------------------------------------------
// COMMENTS ...
// --------------------------------------------------------------------------
HWND AddWnd (HWND hwnd,WORD wId,LPCSTR lpszClassName,
LPCSTR lpszWindowName,DWORD dwstyle,
UINT cx,UINT cxAfter,UINT cxBefore,UINT cy,HINSTANCE hOwner)
{
WINDOWINTBCREATESTRUCT WinTBCS;
WinTBCS.wId = wId ;
WinTBCS.lpszClassName = lpszClassName ;
WinTBCS.lpszWindowName = lpszWindowName;
WinTBCS.dwstyle = dwstyle;
WinTBCS.cx = cx;
WinTBCS.cxAfter = cxAfter;
WinTBCS.cxBefore = cxBefore;
WinTBCS.cy = cy;
WinTBCS.hOwner = hOwner;
return AddWndIndirect(hwnd,&WinTBCS);
}
// --------------------------------------------------------------------------
// FUNCTION BtnInPoint
// PURPOSE Give the button in a point
// --------------------------------------------------------------------------
// INPUT lpTbInfoHeader toolbar's header
// x,y point where search btn
// OUTPUT NULL if no button on point, or if button is INVALID
// else button found
// --------------------------------------------------------------------------
// COMMENTS ...
// --------------------------------------------------------------------------
static LPTBELEM BtnInPoint(LPTBINFOHEADER lpTbInfoHeader,UINT x,UINT y)
{
WORD i;
LPTBELEM lpTbElem;
POINT pt;
pt.x = x;
pt.y = y;
lpTbElem = lpTbInfoHeader->lpTbFirst;
for(i = 0; i < lpTbInfoHeader->wNbElem; i++,lpTbElem++)
{
if (PtInRect(&(lpTbElem->Emplact),pt))
{
if ((lpTbElem->fButton) && (lpTbElem->bState != BTNS_INVALID))
return lpTbElem ;
else return (LPTBELEM) NULL;
}
}
return (LPTBELEM) NULL;
}
// --------------------------------------------------------------------------
// FUNCTION DoPaintBtn
// PURPOSE Show a button in a specified state, with hdc
// --------------------------------------------------------------------------
// INPUT hdc handle to valid dc to draw button
// hdcMemory handle to mem dc with bitmap selected
// lpTbInfoHeader
// lpTbElem the button to show
// bState the state for show
// OUTPUT void
// --------------------------------------------------------------------------
// COMMENTS ...
// --------------------------------------------------------------------------
static void DoPaintBtn(HDC hdc,HDC hdcMemory,LPTBELEM lpTbElem,BYTE bState)
{
BitBlt(hdc, lpTbElem->Emplact.left,lpTbElem->Emplact.top,
CXTBBUTTON, CYTBBUTTON,
hdcMemory, lpTbElem->wPosBitmap * (CXTBBUTTON - 1),
bState * (CYTBBUTTON - 1), SRCCOPY);
}
// --------------------------------------------------------------------------
// FUNCTION Toolbar_ShowBtn
// PURPOSE Show a button in a specified state
// --------------------------------------------------------------------------
// INPUT hwnd handle to window
// lpTbInfoHeader
// lpTbElem the button to show
// bState the state for show
// OUTPUT void
// --------------------------------------------------------------------------
// COMMENTS ...
// --------------------------------------------------------------------------
static void Toolbar_ShowBtn(HWND hwnd,LPTBINFOHEADER lpTbInfoHeader,
LPTBELEM lpTbElem,BYTE bState)
{
HDC hdcMemory;
HDC hdc;
HBITMAP hBmpOld;
hdc = GetDC(hwnd);
hdcMemory = CreateCompatibleDC(hdc);
hBmpOld=SelectObject(hdcMemory, lpTbInfoHeader->hPictBtn);
DoPaintBtn(hdc,hdcMemory,lpTbElem,bState);
SelectObject(hdcMemory,hBmpOld);
DeleteDC(hdcMemory);
ReleaseDC(hwnd, hdc);
}
// --------------------------------------------------------------------------
// FUNCTION Toolbar_OnPaint
// PURPOSE Toolbar Window WM_PAINT handler
// --------------------------------------------------------------------------
// INPUT hwnd handle to window
//
// OUTPUT void
// --------------------------------------------------------------------------
// COMMENTS ...
// --------------------------------------------------------------------------
static void Toolbar_OnPaint(HWND hwnd)
{
PAINTSTRUCT ps;
HBITMAP hBmpOld;
HBRUSH hBrush;
HPEN hOldPen;
HDC hdc, hdcMemory;
RECT rect;
WORD i;
LPTBINFOHEADER lpTbInfoHeader ;
LPTBELEM lpTbElem;
lpTbInfoHeader = GETLPTBINFOHEADER(hwnd);
hdc = BeginPaint(hwnd, &ps);
hdcMemory = CreateCompatibleDC(hdc);
GetClientRect(hwnd, &rect);
// Paint the background (COLOR_BTNFACE : gris)
hBrush=CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
FillRect(hdc,&rect,hBrush);
DeleteObject(hBrush);
// COLOR_BTNHIGHLIGHT : noir (RGB(0,0,0)
hOldPen=SelectObject(hdc,
CreatePen(PS_SOLID,1,RGB(0,0,0)));
MoveToEx(hdc,0,rect.bottom-1,NULL);
LineTo(hdc,rect.right,rect.bottom-1);
DeleteObject(SelectObject(hdc,hOldPen));
// Paint Buttons
hBmpOld = SelectBitmap(hdcMemory, lpTbInfoHeader->hPictBtn);
lpTbElem = lpTbInfoHeader->lpTbFirst;
for(i = 0; i < lpTbInfoHeader->wNbElem; i++,lpTbElem++)
if (lpTbElem->fButton)
DoPaintBtn(hdc,hdcMemory,lpTbElem,lpTbElem->bState);
// clean-up
SelectBitmap(hdcMemory, hBmpOld);
DeleteDC(hdcMemory);
EndPaint(hwnd, &ps);
}
// --------------------------------------------------------------------------
// FUNCTION PushBtn
// PURPOSE Push a button in a group a raise other
// --------------------------------------------------------------------------
// INPUT hwnd HWND of toolbar
// wIdFirst,wIdLast Bound of Group
// wIdPush Button to push
// wIdExcl Button on group to exclude
// (for a btn whe want change ourself)
// OUTPUT NULL
// --------------------------------------------------------------------------
// COMMENTS same use as CheckRadioButton
// --------------------------------------------------------------------------
void PushBtn(HWND hwnd,WORD wIdFirst,WORD wIdLast,WORD wIdPush,WORD wIdExcl)
{
WORD i;
LPTBELEM lpTbElem;
LPTBINFOHEADER lpTbInfoHeader ;
lpTbInfoHeader = GETLPTBINFOHEADER(hwnd);
lpTbElem = lpTbInfoHeader->lpTbFirst;
for(i = 0; i < lpTbInfoHeader->wNbElem; i++,lpTbElem++)
{
if ((lpTbElem->wId >= wIdFirst) && (lpTbElem->wId <= wIdLast) &&
(lpTbElem->wId != wIdPush) && (lpTbElem->wId != wIdExcl))
{
Toolbar_ShowBtn(hwnd,lpTbInfoHeader,lpTbElem,BTNS_RAISED);
lpTbElem -> bState = BTNS_RAISED ;
}
if (lpTbElem->wId == wIdPush)
{
Toolbar_ShowBtn(hwnd,lpTbInfoHeader,lpTbElem,BTNS_PUSHED);
lpTbElem -> bState = BTNS_PUSHED ;
}
}
}
// --------------------------------------------------------------------------
// FUNCTION FoundBtn
// PURPOSE Search a button in a toolbar
// --------------------------------------------------------------------------
// INPUT hwnd HWND of toolbar
// wIdSearch Button to search
// OUTPUT the button is found, otherwise NULL
// --------------------------------------------------------------------------
// COMMENTS
// --------------------------------------------------------------------------
static LPTBELEM FoundBtn(HWND hwnd,WORD wIdSearch)
{
WORD i;
LPTBELEM lpTbElem;
LPTBINFOHEADER lpTbInfoHeader ;
lpTbInfoHeader = GETLPTBINFOHEADER(hwnd);
lpTbElem = lpTbInfoHeader->lpTbFirst;
for(i = 0; i < lpTbInfoHeader->wNbElem; i++,lpTbElem++)
if (lpTbElem->wId == wIdSearch)
return lpTbElem;
return NULL ;
}
// --------------------------------------------------------------------------
// FUNCTION GetBtnState
// PURPOSE Get a button state
// --------------------------------------------------------------------------
// INPUT hwnd HWND of toolbar
// wId id of button to search
// OUTPUT bState of button
// 0xFF if the button isn't found
// --------------------------------------------------------------------------
// COMMENTS
// --------------------------------------------------------------------------
BYTE GetBtnState (HWND hwnd,WORD wId)
{
LPTBELEM lpTbElem = FoundBtn(hwnd,wId);
if (lpTbElem == NULL) return 0xFF;
else return lpTbElem->bState;
}
// --------------------------------------------------------------------------
// FUNCTION SetBtnState
// PURPOSE Set a button state
// --------------------------------------------------------------------------
// INPUT hwnd HWND of toolbar
// wId id of button to search
// bState new state of button
// OUTPUT BOOL say if button found and set
// --------------------------------------------------------------------------
// COMMENTS the button is draw
// --------------------------------------------------------------------------
BOOL SetBtnState (HWND hwnd,WORD wId,BYTE bState)
{
LPTBELEM lpTbElem = FoundBtn(hwnd,wId);
LPTBINFOHEADER lpTbInfoHeader ;
lpTbInfoHeader = GETLPTBINFOHEADER(hwnd);
if (lpTbElem == NULL) return FALSE;
lpTbElem->bState = bState;
Toolbar_ShowBtn(hwnd,lpTbInfoHeader,lpTbElem,bState);
return TRUE;
}
// --------------------------------------------------------------------------
// FUNCTION Toolbar_OnLButtonDown
// PURPOSE Toolbar WM_LBUTTONDOWN handler
// --------------------------------------------------------------------------
// INPUT hwnd Handle to window receiving messages
// fDoubleClick Double click flag
// x x position
// y y position
// keyFlags shift, ctrl ...
//
// OUTPUT void
// --------------------------------------------------------------------------
// COMMENTS
// --------------------------------------------------------------------------
static void Toolbar_OnLButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
{
LPTBINFOHEADER lpTbInfoHeader ;
LPTBELEM lpTbInPush;
lpTbInfoHeader = GETLPTBINFOHEADER(hwnd);
SetFocus(hwnd); // kill focus in toolbar's chid window
lpTbInfoHeader->fMouseOnButton=TRUE;
lpTbInPush = BtnInPoint(lpTbInfoHeader,x,y);
// Test if the btn is the pushed in a GROUPTOGGLE
if (lpTbInPush==NULL) return;
if ((lpTbInPush->bStyle == BSTY_GROUPTOGGLE) &&
(lpTbInPush->bState == BTNS_PUSHED))
return ;
lpTbInfoHeader->lpTbInPush = lpTbInPush ;
if (lpTbInPush==NULL) return;
lpTbInfoHeader->bOldStateInPush = lpTbInPush -> bState ;
SetCapture(hwnd);
Toolbar_ShowBtn(hwnd,lpTbInfoHeader,lpTbInPush,
lpTbInfoHeader->bStateInPush=(lpTbInPush->bState==BTNS_PUSHED) ?
BTNS_RAISED : BTNS_PUSHED) ;
/***+++***/ //begin
PostMessage(lpTbInfoHeader->hwndParent,WM_MENUSELECT,
GET_WM_MENUSELECT_MPS(lpTbInPush->wId,0,0));
/***+++***/ //end
}
// --------------------------------------------------------------------------
// FUNCTION Toolbar_OnMouseMove
// PURPOSE Toolbar WM_MOUSEMOVE handler
// --------------------------------------------------------------------------
// INPUT hwnd Handle to window receiving messages
// x x position
// y y position
// keyFlags shift, ctrl ...
//
// OUTPUT void
// --------------------------------------------------------------------------
// COMMENTS
// --------------------------------------------------------------------------
static void Toolbar_OnMouseMove(HWND hwnd, int x, int y, UINT keyFlags)
{
LPTBINFOHEADER lpTbInfoHeader ;
BOOL fOldMouseOnButton;
BOOL fNewMouseOnButton;
LPTBELEM lpTbInPush;
POINT pt;
pt.x = x;
pt.y = y;
SetCursor(LoadCursor(NULL,IDC_ARROW));
lpTbInfoHeader = GETLPTBINFOHEADER(hwnd);
lpTbInPush=lpTbInfoHeader->lpTbInPush;
if (lpTbInPush==NULL) return ;
fOldMouseOnButton = lpTbInfoHeader->fMouseOnButton ;
fNewMouseOnButton = PtInRect(&(lpTbInPush->Emplact),pt);
lpTbInPush->bState= (fNewMouseOnButton ? BTNS_PUSHED : BTNS_RAISED);
if (fNewMouseOnButton != fOldMouseOnButton)
Toolbar_ShowBtn(hwnd,lpTbInfoHeader,lpTbInPush,
(BYTE)(fNewMouseOnButton ? lpTbInfoHeader->bStateInPush :
lpTbInPush->bState));
lpTbInfoHeader->fMouseOnButton = fNewMouseOnButton ;
}
// --------------------------------------------------------------------------
// FUNCTION Toolbar_OnLButtonUp
// PURPOSE Toolbar WM_LBUTTONUP handler
// --------------------------------------------------------------------------
// INPUT hwnd Handle to window receiving messages
// fDoubleClick Double click flag
// x x position
// y y position
// keyFlags shift, ctrl ...
//
// OUTPUT void
// --------------------------------------------------------------------------
// COMMENTS :
// GET_WM_COMMAND_MPS defined in WINDOWSX.H for WIN32
// and in WINX31AD.H for WIN16
// --------------------------------------------------------------------------
void Toolbar_OnLButtonUp(HWND hwnd, int x, int y, UINT keyFlags)
{
LPTBINFOHEADER lpTbInfoHeader ;
LPTBELEM lpTbInPush;
lpTbInfoHeader = GETLPTBINFOHEADER(hwnd);
ReleaseCapture();
lpTbInPush=lpTbInfoHeader->lpTbInPush;
if (lpTbInPush==NULL) return;
if (BtnInPoint(lpTbInfoHeader,x,y)==lpTbInPush)
{
if ((lpTbInPush->bStyle == BSTY_GROUPTOGGLE) ||
(lpTbInPush->bStyle == BSTY_GROUPTOGGLEOPT))
PushBtn(hwnd,lpTbInPush->wIdFirst,lpTbInPush->wIdLast,0,
lpTbInPush->wId);
if (lpTbInPush->bStyle == BSTY_ACTION)
lpTbInPush->bState = BTNS_RAISED;
else
lpTbInPush->bState = (BYTE) (lpTbInfoHeader->bOldStateInPush ==
BTNS_PUSHED) ? BTNS_RAISED : BTNS_PUSHED ;
PostMessage(lpTbInfoHeader->hwndParent,WM_COMMAND,
GET_WM_COMMAND_MPS (lpTbInPush->wId,hwnd,lpTbInPush->bState));
}
/***+++***/ //begin
PostMessage(lpTbInfoHeader->hwndParent,WM_MENUSELECT,
GET_WM_MENUSELECT_MPS(0,0,0));
/***+++***/ //end
Toolbar_ShowBtn(hwnd,lpTbInfoHeader,lpTbInPush,lpTbInPush->bState);
lpTbInfoHeader->lpTbInPush=NULL;
}
// --------------------------------------------------------------------------
// FUNCTION SetBitmap
// PURPOSE Change the ToolBar bitmap
// --------------------------------------------------------------------------
// INPUT hWndTB the handle of ToolBar window
// hPictBtn the Handle of bitmap which contain Button
// OUTPUT the handle of the bitmap being replaced
// --------------------------------------------------------------------------
// COMMENTS ...
// --------------------------------------------------------------------------
HBITMAP SetBitmap(HWND hwnd,HBITMAP hPictBtn)
{
LPTBINFOHEADER lpTbInfoHeader ;
HBITMAP hOldBmp;
lpTbInfoHeader = GETLPTBINFOHEADER(hwnd);
hOldBmp = lpTbInfoHeader->hPictBtn;
lpTbInfoHeader->hPictBtn = hPictBtn;
return hOldBmp;
}
// --------------------------------------------------------------------------
// FUNCTION Toolbar_OnCreate
// PURPOSE initialize the Toolbar
// --------------------------------------------------------------------------
// INPUT hWnd handle to window receiving message
// lpCreateStruct lp to CreateStruct associated to window
//
// OUTPUT BOOL 0 to continue to process, -1 otherwise
// --------------------------------------------------------------------------
// COMMENTS
// --------------------------------------------------------------------------
static BOOL Toolbar_OnCreate(HWND hwnd, CREATESTRUCT FAR *lpCreateStruct)
{
LPTBINFOHEADER lpTbInfoHeader ;
lpTbInfoHeader = (LPTBINFOHEADER) GlobalAllocPtr(GHND,sizeof(TBINFOHEADER));
lpTbInfoHeader->wFirstx=MARGINX;
lpTbInfoHeader->wFirsty=MARGINY;
lpTbInfoHeader->hwndTB=hwnd;
lpTbInfoHeader->hwndParent=lpCreateStruct->hwndParent;
SetWindowLong(hwnd,0,(LONG)lpTbInfoHeader);
return TRUE;
}
// --------------------------------------------------------------------------
// FUNCTION Toolbar_OnDestroy
// PURPOSE Toolbar WM_DESTROY handler
// --------------------------------------------------------------------------
// INPUT hwnd Handle to window receiving messages
//
// OUTPUT void
// --------------------------------------------------------------------------
// COMMENTS
// --------------------------------------------------------------------------
static void Toolbar_OnDestroy(HWND hwnd)
{
LPTBINFOHEADER lpTbInfoHeader ;
lpTbInfoHeader = GETLPTBINFOHEADER(hwnd);
GlobalFreePtr(lpTbInfoHeader);
// PostQuitMessage(0); /**** A VOIR ***/
}
LRESULT CALLBACK ToolbarWndProc(HWND hwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
switch (uiMsg)
{
HANDLE_MSG(hwnd, WM_CREATE, Toolbar_OnCreate);
HANDLE_MSG(hwnd, WM_PAINT, Toolbar_OnPaint);
HANDLE_MSG(hwnd, WM_LBUTTONDOWN, Toolbar_OnLButtonDown);
HANDLE_MSG(hwnd, WM_LBUTTONUP, Toolbar_OnLButtonUp);
HANDLE_MSG(hwnd, WM_MOUSEMOVE, Toolbar_OnMouseMove);
HANDLE_MSG(hwnd, WM_DESTROY, Toolbar_OnDestroy);
// here are messages from Child Window which must be send to parent window
// you can add somes message here
case WM_DRAWITEM :
#ifdef WIN32
case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN:
case WM_CTLCOLORDLG:
case WM_CTLCOLOREDIT:
case WM_CTLCOLORLISTBOX:
case WM_CTLCOLORMSGBOX:
case WM_CTLCOLORSCROLLBAR:
#else
case WM_CTLCOLOR:
#endif
case WM_COMMAND :
case WM_MEASUREITEM :
return SendMessage(GETLPTBINFOHEADER(hwnd)
->hwndParent,
uiMsg,wParam,lParam);
}
return DefWindowProc(hwnd, uiMsg, wParam, lParam);
}