?? gizmo.c
字號(hào):
, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
pGizmo=pGizmo->pNext;
}
return;
}
/*
* GizmosCompact
*
* Purpose:
* Given a gizmo, moves all other gizmos to the right of it to the
* left by its width on the GizmoBar. Used when removing or hiding
* the gizmo.
*
* Parameters:
* pGizmo PGIZMO that is going away, visibly or physically.
*
* Return Value:
* None
*/
void GizmosCompact(PGIZMO pGizmo)
{
UINT cx;
PGIZMO pCur;
//Move all the gizmos beyond us back by our width.
if (NULL!=pGizmo->pNext)
{
cx=pGizmo->pNext->x - pGizmo->x;
pCur=pGizmo->pNext;
while (NULL!=pCur)
{
pCur->x-=cx;
if (NULL!=pCur->hWnd)
{
SetWindowPos(pCur->hWnd, NULL, pCur->x, pCur->y
, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
pCur=pCur->pNext;
}
}
return;
}
/*
* GizmoPFind
*
* Purpose:
* Given a GIZMO identifier, locates and returns a pointer to the
* structure for that position.
*
* Parameters:
* ppFirst PPGIZMO providing the first gizmo in this list.
* uID UINT identifier to find.
*
* Return Value:
* PGIZMO A pointer to a GIZMO structure allocated through
* GizmoPAllocate, NULL if iGizmo is out of range.
*/
PGIZMO GizmoPFind(PPGIZMO ppFirst, UINT uID)
{
PGIZMO pGizmo;
pGizmo=*ppFirst;
/*
* Yep, linear search, but a better search algorithm won't
* improve things appreciably. The better thing to optimize
* is what the caller passes as ppFirst.
*/
while (NULL!=pGizmo && uID!=pGizmo->uID)
pGizmo=pGizmo->pNext;
return pGizmo;
}
/*
* GizmoFEnum
*
* Purpose:
* Enumerates the list of GIZMO structures, passing each one to
* an application-defined callback.
*
* Parameters:
* ppFirst PPGIZMO providing the first gizmo in this list.
* pfnEnum PFNGIZMOENUM to call for each enumerated
* structure.
* dw DWORD extra data to pass to the enumeration
* function.
*
* Return Value:
* PGIZMO NULL if the enumeration completed. Otherwise a
* pointer to the gizmo that enumeration stopped on.
*/
PGIZMO GizmoPEnum(PPGIZMO ppFirst, PFNGIZMOENUM pfnEnum, DWORD dw)
{
PGIZMO pGizmo;
UINT i=0;
pGizmo=*ppFirst;
while (NULL!=pGizmo)
{
if (!(*pfnEnum)(pGizmo, i++, dw))
break;
pGizmo=pGizmo->pNext;
}
return pGizmo;
}
/*
* GizmoPStateSet
*
* Purpose:
* State maniuplation functions. Set and Clear also invalidate
* this gizmo's rectangle on the given window and forces a repaint.
*
* Parameters:
* hWnd HWND of the window to repaint.
* pGizmo PGIZMO affected.
* dwNew DWORD new state flags.
*
* Return Value:
* UINT Previous state.
*/
UINT GizmoPStateSet(HWND hWnd, PGIZMO pGizmo, UINT uNew)
{
UINT uRet;
RECT rc;
if (GIZMOTYPE_SEPARATOR==pGizmo->iType)
return pGizmo->uState;
//Preserve the color conversion flags across this state change.
uRet=pGizmo->uState;
pGizmo->uState=(uNew & 0x00FF) | (uRet & 0xFF00);
//Adjust the rectangle by one to avoid repainting borders.
SetRect(&rc, pGizmo->x+1, pGizmo->y+1, pGizmo->x+pGizmo->dx-1
, pGizmo->y+pGizmo->dy-1);
InvalidateRect(hWnd, &rc, FALSE);
UpdateWindow(hWnd);
return uRet;
}
/*
* GizmoPCheck
*
* Purpose:
* Handles checking a single button in a group of attribute buttons.
* If the gizmo belongs to a group of mutually exclusive buttons
* then the others surrounding it are unchecked appropriately.
*
* Parameters:
* hWnd HWND of the GizmoBar.
* pGizmo PGIZMO of the gizmo affected.
* fCheck BOOL TRUE to check the button, FALSE to uncheck.
*
* Return Value:
* BOOL TRUE if the gizmo was previously checked, FALSE
* otherwise.
*/
BOOL GizmoPCheck(HWND hWnd, PGIZMO pGizmo, BOOL fCheck)
{
BOOL fPrevCheck;
PGIZMO pCur;
//Ignore command buttons.
if (GIZMOTYPE_BUTTONCOMMAND==pGizmo->iType)
return FALSE;
//Get the previous state
fPrevCheck=(BOOL)(BUTTONGROUP_DOWN & pGizmo->uState);
//Simply set the state for inclusive attribute buttons.
if (GIZMOTYPE_BUTTONATTRIBUTEIN==pGizmo->iType)
{
if (pGizmo->fDisabled)
{
GizmoPStateSet(hWnd, pGizmo
, fCheck ? ATTRIBUTEBUTTON_DOWNDISABLED
: ATTRIBUTEBUTTON_DISABLED);
}
else
{
GizmoPStateSet(hWnd, pGizmo, fCheck
? ATTRIBUTEBUTTON_DOWN : ATTRIBUTEBUTTON_UP);
}
}
if (GIZMOTYPE_BUTTONATTRIBUTEEX==pGizmo->iType)
//We cannot uncheck an exclusive attribute
if (!fCheck)
return fPrevCheck;
/*
* For exclusive buttons we have to do more work. First, if
* we're already checked (incliding DOWN and MOUSEDOWN) then
* we set DOWN and exit. If we're not already checked, then
* we look for the gizmo around us, backwards and forwards,
* that is checked and uncheck him.
*/
//Search backwards.
pCur=pGizmo->pPrev;
while (NULL!=pCur)
{
//Stop at any non-exclusive attribute.
if (GIZMOTYPE_BUTTONATTRIBUTEEX!=pCur->iType)
{
pCur=NULL;
break;
}
//If it's down, set it up and we've finished.
if (BUTTONGROUP_DOWN & pCur->uState)
break;
pCur=pCur->pPrev;
}
//If we didn't find a previous one, pCur is NULL, look ahead.
if (NULL==pCur)
{
pCur=pGizmo->pNext;
while (NULL!=pCur)
{
//Stop at any non-exclusive attribute.
if (GIZMOTYPE_BUTTONATTRIBUTEEX!=pCur->iType)
{
pCur=NULL;
break;
}
//If it's down, set it up and we've finished.
if (BUTTONGROUP_DOWN & pCur->uState)
break;
pCur=pCur->pNext;
}
}
//If pCur is non-NULL, we found a neighbor, so uncheck it
if (NULL!=pCur)
{
GizmoPStateSet(hWnd, pCur, (pGizmo->fDisabled)
? ATTRIBUTEBUTTON_DISABLED : ATTRIBUTEBUTTON_UP);
}
//Always set ourselves down
GizmoPStateSet(hWnd, pGizmo, (pGizmo->fDisabled)
? ATTRIBUTEBUTTON_DOWNDISABLED : ATTRIBUTEBUTTON_DOWN);
}
return fPrevCheck;
}
/*
* GenericSubProc
*
* Purpose:
* Subclasses window controls in Gizmos so we can trap the tab key
* and tab to the next control. We can have one shared generic
* subclass procedure because we save the type index for this
* control in the property "iType." This allows us to look up the
* original procedure in the pfnOrg array.
*
* Parameters:
* Standard
*
* Return Value:
* Standard
*/
LRESULT APIENTRY GenericSubProc(HWND hWnd, UINT iMsg
, WPARAM wParam, LPARAM lParam)
{
LONG lRet;
RECT rc;
RECT rcE;
HWND hWndE;
HBRUSH hBr;
HDC hDC;
UINT dx;
UINT iType, i;
i=(int)GetProp(hWnd, SZTYPEPROP);
iType=POSITIONBIT(i);
//Special: paint the gap in drop-down comboboxes.
if (GIZMOTYPE_COMBOBOX==iType && WM_PAINT==iMsg)
{
//Do default painting.
lRet=(*pfnOrg[i])(hWnd, iMsg, wParam, lParam);
hWndE=GetDlgItem(hWnd, ID_COMBOEDIT);
GetClientRect(hWnd, &rc);
GetClientRect(hWndE, &rcE);
//The width of the button is the scroll bar width.
dx=GetSystemMetrics(SM_CXVSCROLL);
//Calculate the rectangle
rc.right -=dx;
rc.left =rcE.right;
rc.bottom+=1;
//Paint the gap
hDC=GetDC(hWnd); //Already did BeginPaint and EndPaint
hBr=CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
FillRect(hDC, &rc, hBr);
DeleteObject(hBr);
ReleaseDC(hWnd, hDC);
return lRet;
}
//Control tabbing to the next or previous control
if (WM_KEYDOWN==iMsg && VK_TAB==wParam)
{
hWndE=hWnd;
if (-1==i)
hWndE=GetParent(hWnd);
hWndE=GetNextDlgTabItem(GetParent(hWndE), hWnd
, (BOOL)(GetKeyState(VK_SHIFT)));
SetFocus(hWndE);
return 0L;
}
if (-1==i) i=0;
//Eat tab chars in edit controls to prevent beeping.
if (0==i && WM_CHAR==iMsg && VK_TAB==wParam)
return 0L;
//Do this or edit controls bomb big-time.
return CallWindowProc(pfnOrg[i], hWnd, iMsg, wParam, lParam);
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -