时间的痕迹
posts - 16, comments - 128, trackbacks - 0, articles - 261
C++博客
首页
新随笔
联系
管理
聚合
很好的button类 实现文件 5
//
This functions sets the button to have a standard or flat style.
//
//
Parameters:
//
[IN] bFlat
//
If TRUE the button will have a flat style, else
//
will have a standard style.
//
By default, CButtonST buttons are flat.
//
[IN] bRepaint
//
If TRUE the control will be repainted.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
DWORD CButtonST::SetFlat(BOOL bFlat, BOOL bRepaint)
{
m_bIsFlat
=
bFlat;
if
(bRepaint) Invalidate();
return
BTNST_OK;
}
//
End of SetFlat
//
This function sets the alignment type between icon/bitmap and text.
//
//
Parameters:
//
[IN] byAlign
//
Alignment type. Can be one of the following values:
//
ST_ALIGN_HORIZ Icon/bitmap on the left, text on the right
//
ST_ALIGN_VERT Icon/bitmap on the top, text on the bottom
//
ST_ALIGN_HORIZ_RIGHT Icon/bitmap on the right, text on the left
//
ST_ALIGN_OVERLAP Icon/bitmap on the same space as text
//
By default, CButtonST buttons have ST_ALIGN_HORIZ alignment.
//
[IN] bRepaint
//
If TRUE the control will be repainted.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
BTNST_INVALIDALIGN
//
Alignment type not supported.
//
DWORD CButtonST::SetAlign(BYTE byAlign, BOOL bRepaint)
{
switch
(byAlign)
{
case
ST_ALIGN_HORIZ:
case
ST_ALIGN_HORIZ_RIGHT:
case
ST_ALIGN_VERT:
case
ST_ALIGN_OVERLAP:
m_byAlign
=
byAlign;
if
(bRepaint) Invalidate();
return
BTNST_OK;
break
;
}
//
switch
return
BTNST_INVALIDALIGN;
}
//
End of SetAlign
//
This function sets the pressed style.
//
//
Parameters:
//
[IN] byStyle
//
Pressed style. Can be one of the following values:
//
BTNST_PRESSED_LEFTRIGHT Pressed style from left to right (as usual)
//
BTNST_PRESSED_TOPBOTTOM Pressed style from top to bottom
//
By default, CButtonST buttons have BTNST_PRESSED_LEFTRIGHT style.
//
[IN] bRepaint
//
If TRUE the control will be repainted.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
BTNST_INVALIDPRESSEDSTYLE
//
Pressed style not supported.
//
DWORD CButtonST::SetPressedStyle(BYTE byStyle, BOOL bRepaint)
{
switch
(byStyle)
{
case
BTNST_PRESSED_LEFTRIGHT:
m_ptPressedOffset.x
=
1
;
m_ptPressedOffset.y
=
1
;
break
;
case
BTNST_PRESSED_TOPBOTTOM:
m_ptPressedOffset.x
=
0
;
m_ptPressedOffset.y
=
2
;
break
;
default
:
return
BTNST_INVALIDPRESSEDSTYLE;
}
//
switch
if
(bRepaint) Invalidate();
return
BTNST_OK;
}
//
End of SetPressedStyle
//
This function sets the state of the checkbox.
//
If the button is not a checkbox, this function has no meaning.
//
//
Parameters:
//
[IN] nCheck
//
1 to check the checkbox.
//
0 to un-check the checkbox.
//
[IN] bRepaint
//
If TRUE the control will be repainted.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
DWORD CButtonST::SetCheck(
int
nCheck, BOOL bRepaint)
{
if
(m_bIsCheckBox)
{
if
(nCheck
==
0
) m_nCheck
=
0
;
else
m_nCheck
=
1
;
if
(bRepaint) Invalidate();
}
//
if
return
BTNST_OK;
}
//
End of SetCheck
//
This function returns the current state of the checkbox.
//
If the button is not a checkbox, this function has no meaning.
//
//
Return value:
//
The current state of the checkbox.
//
1 if checked.
//
0 if not checked or the button is not a checkbox.
//
int
CButtonST::GetCheck()
{
return
m_nCheck;
}
//
End of GetCheck
//
This function sets all colors to a default value.
//
//
Parameters:
//
[IN] bRepaint
//
If TRUE the control will be repainted.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
DWORD CButtonST::SetDefaultColors(BOOL bRepaint)
{
m_crColors[BTNST_COLOR_BK_IN]
=
::GetSysColor(COLOR_BTNFACE);
m_crColors[BTNST_COLOR_FG_IN]
=
::GetSysColor(COLOR_BTNTEXT);
m_crColors[BTNST_COLOR_BK_OUT]
=
::GetSysColor(COLOR_BTNFACE);
m_crColors[BTNST_COLOR_FG_OUT]
=
::GetSysColor(COLOR_BTNTEXT);
m_crColors[BTNST_COLOR_BK_FOCUS]
=
::GetSysColor(COLOR_BTNFACE);
m_crColors[BTNST_COLOR_FG_FOCUS]
=
::GetSysColor(COLOR_BTNTEXT);
if
(bRepaint) Invalidate();
return
BTNST_OK;
}
//
End of SetDefaultColors
//
This function sets the color to use for a particular state.
//
//
Parameters:
//
[IN] byColorIndex
//
Index of the color to set. Can be one of the following values:
//
BTNST_COLOR_BK_IN Background color when mouse is over the button
//
BTNST_COLOR_FG_IN Text color when mouse is over the button
//
BTNST_COLOR_BK_OUT Background color when mouse is outside the button
//
BTNST_COLOR_FG_OUT Text color when mouse is outside the button
//
BTNST_COLOR_BK_FOCUS Background color when the button is focused
//
BTNST_COLOR_FG_FOCUS Text color when the button is focused
//
[IN] crColor
//
New color.
//
[IN] bRepaint
//
If TRUE the control will be repainted.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
BTNST_INVALIDINDEX
//
Invalid color index.
//
DWORD CButtonST::SetColor(BYTE byColorIndex, COLORREF crColor, BOOL bRepaint)
{
if
(byColorIndex
>=
BTNST_MAX_COLORS)
return
BTNST_INVALIDINDEX;
//
Set new color
m_crColors[byColorIndex]
=
crColor;
if
(bRepaint) Invalidate();
return
BTNST_OK;
}
//
End of SetColor
//
This functions returns the color used for a particular state.
//
//
Parameters:
//
[IN] byColorIndex
//
Index of the color to get.
//
See SetColor for the list of available colors.
//
[OUT] crpColor
//
A pointer to a COLORREF that will receive the color.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
BTNST_INVALIDINDEX
//
Invalid color index.
//
DWORD CButtonST::GetColor(BYTE byColorIndex, COLORREF
*
crpColor)
{
if
(byColorIndex
>=
BTNST_MAX_COLORS)
return
BTNST_INVALIDINDEX;
//
Get color
*
crpColor
=
m_crColors[byColorIndex];
return
BTNST_OK;
}
//
End of GetColor
//
This function applies an offset to the RGB components of the specified color.
//
This function can be seen as an easy way to make a color darker or lighter than
//
its default value.
//
//
Parameters:
//
[IN] byColorIndex
//
Index of the color to set.
//
See SetColor for the list of available colors.
//
[IN] shOffsetColor
//
A short value indicating the offset to apply to the color.
//
This value must be between -255 and 255.
//
[IN] bRepaint
//
If TRUE the control will be repainted.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
BTNST_INVALIDINDEX
//
Invalid color index.
//
BTNST_BADPARAM
//
The specified offset is out of range.
//
DWORD CButtonST::OffsetColor(BYTE byColorIndex,
short
shOffset, BOOL bRepaint)
{
BYTE byRed
=
0
;
BYTE byGreen
=
0
;
BYTE byBlue
=
0
;
short
shOffsetR
=
shOffset;
short
shOffsetG
=
shOffset;
short
shOffsetB
=
shOffset;
if
(byColorIndex
>=
BTNST_MAX_COLORS)
return
BTNST_INVALIDINDEX;
if
(shOffset
<
-
255
||
shOffset
>
255
)
return
BTNST_BADPARAM;
//
Get RGB components of specified color
byRed
=
GetRValue(m_crColors[byColorIndex]);
byGreen
=
GetGValue(m_crColors[byColorIndex]);
byBlue
=
GetBValue(m_crColors[byColorIndex]);
//
Calculate max. allowed real offset
if
(shOffset
>
0
)
{
if
(byRed
+
shOffset
>
255
) shOffsetR
=
255
-
byRed;
if
(byGreen
+
shOffset
>
255
) shOffsetG
=
255
-
byGreen;
if
(byBlue
+
shOffset
>
255
) shOffsetB
=
255
-
byBlue;
shOffset
=
min(min(shOffsetR, shOffsetG), shOffsetB);
}
//
if
else
{
if
(byRed
+
shOffset
<
0
) shOffsetR
=
-
byRed;
if
(byGreen
+
shOffset
<
0
) shOffsetG
=
-
byGreen;
if
(byBlue
+
shOffset
<
0
) shOffsetB
=
-
byBlue;
shOffset
=
max(max(shOffsetR, shOffsetG), shOffsetB);
}
//
else
//
Set new color
m_crColors[byColorIndex]
=
RGB(byRed
+
shOffset, byGreen
+
shOffset, byBlue
+
shOffset);
if
(bRepaint) Invalidate();
return
BTNST_OK;
}
//
End of OffsetColor
//
This function sets the hilight logic for the button.
//
Applies only to flat buttons.
//
//
Parameters:
//
[IN] bAlwaysTrack
//
If TRUE the button will be hilighted even if the window that owns it, is
//
not the active window.
//
If FALSE the button will be hilighted only if the window that owns it,
//
is the active window.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
DWORD CButtonST::SetAlwaysTrack(BOOL bAlwaysTrack)
{
m_bAlwaysTrack
=
bAlwaysTrack;
return
BTNST_OK;
}
//
End of SetAlwaysTrack
//
This function sets the cursor to be used when the mouse is over the button.
//
//
Parameters:
//
[IN] nCursorId
//
ID number of the cursor resource.
//
Pass NULL to remove a previously loaded cursor.
//
[IN] bRepaint
//
If TRUE the control will be repainted.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
BTNST_INVALIDRESOURCE
//
Failed loading the specified resource.
//
DWORD CButtonST::SetBtnCursor(
int
nCursorId, BOOL bRepaint)
{
HINSTANCE hInstResource
=
NULL;
//
Destroy any previous cursor
if
(m_hCursor)
{
::DestroyCursor(m_hCursor);
m_hCursor
=
NULL;
}
//
if
//
Load cursor
if
(nCursorId)
{
hInstResource
=
AfxFindResourceHandle(MAKEINTRESOURCE(nCursorId), RT_GROUP_CURSOR);
//
Load cursor resource
m_hCursor
=
(HCURSOR)::LoadImage(hInstResource, MAKEINTRESOURCE(nCursorId), IMAGE_CURSOR,
0
,
0
,
0
);
//
Repaint the button
if
(bRepaint) Invalidate();
//
If something wrong
if
(m_hCursor
==
NULL)
return
BTNST_INVALIDRESOURCE;
}
//
if
return
BTNST_OK;
}
//
End of SetBtnCursor
//
This function sets if the button border must be drawn.
//
Applies only to flat buttons.
//
//
Parameters:
//
[IN] bDrawBorder
//
If TRUE the border will be drawn.
//
[IN] bRepaint
//
If TRUE the control will be repainted.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
DWORD CButtonST::DrawBorder(BOOL bDrawBorder, BOOL bRepaint)
{
m_bDrawBorder
=
bDrawBorder;
//
Repaint the button
if
(bRepaint) Invalidate();
return
BTNST_OK;
}
//
End of DrawBorder
//
This function sets if the focus rectangle must be drawn for flat buttons.
//
//
Parameters:
//
[IN] bDrawFlatFocus
//
If TRUE the focus rectangle will be drawn also for flat buttons.
//
[IN] bRepaint
//
If TRUE the control will be repainted.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
DWORD CButtonST::DrawFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint)
{
m_bDrawFlatFocus
=
bDrawFlatFocus;
//
Repaint the button
if
(bRepaint) Invalidate();
return
BTNST_OK;
}
//
End of DrawFlatFocus
void
CButtonST::InitToolTip()
{
if
(m_ToolTip.m_hWnd
==
NULL)
{
//
Create ToolTip control
m_ToolTip.Create(
this
, m_dwToolTipStyle);
//
Create inactive
m_ToolTip.Activate(FALSE);
//
Enable multiline
m_ToolTip.SendMessage(TTM_SETMAXTIPWIDTH,
0
,
400
);
//
m_ToolTip.SendMessage(TTM_SETTITLE, TTI_INFO, (LPARAM)_T("Title"));
}
//
if
}
//
End of InitToolTip
//
This function sets the text to show in the button tooltip.
//
//
Parameters:
//
[IN] nText
//
ID number of the string resource containing the text to show.
//
[IN] bActivate
//
If TRUE the tooltip will be created active.
//
void
CButtonST::SetTooltipText(
int
nText, BOOL bActivate)
{
CString sText;
//
Load string resource
sText.LoadString(nText);
//
If string resource is not empty
if
(sText.IsEmpty()
==
FALSE) SetTooltipText((LPCTSTR)sText, bActivate);
}
//
End of SetTooltipText
//
This function sets the text to show in the button tooltip.
//
//
Parameters:
//
[IN] lpszText
//
Pointer to a null-terminated string containing the text to show.
//
[IN] bActivate
//
If TRUE the tooltip will be created active.
//
void
CButtonST::SetTooltipText(LPCTSTR lpszText, BOOL bActivate)
{
//
We cannot accept NULL pointer
if
(lpszText
==
NULL)
return
;
//
Initialize ToolTip
InitToolTip();
//
If there is no tooltip defined then add it
if
(m_ToolTip.GetToolCount()
==
0
)
{
CRect rectBtn;
GetClientRect(rectBtn);
m_ToolTip.AddTool(
this
, lpszText, rectBtn,
1
);
}
//
if
//
Set text for tooltip
m_ToolTip.UpdateTipText(lpszText,
this
,
1
);
m_ToolTip.Activate(bActivate);
}
//
End of SetTooltipText
//
This function enables or disables the button tooltip.
//
//
Parameters:
//
[IN] bActivate
//
If TRUE the tooltip will be activated.
//
void
CButtonST::ActivateTooltip(BOOL bActivate)
{
//
If there is no tooltip then do nothing
if
(m_ToolTip.GetToolCount()
==
0
)
return
;
//
Activate tooltip
m_ToolTip.Activate(bActivate);
}
//
End of EnableTooltip
//
This function enables the tooltip to be displayed using the balloon style.
//
This function must be called before any call to SetTooltipText is made.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
DWORD CButtonST::EnableBalloonTooltip()
{
m_dwToolTipStyle
|=
TTS_BALLOON;
return
BTNST_OK;
}
//
End of EnableBalloonTooltip
//
This function returns if the button is the default button.
//
//
Return value:
//
TRUE
//
The button is the default button.
//
FALSE
//
The button is not the default button.
//
BOOL CButtonST::GetDefault()
{
return
m_bIsDefault;
}
//
End of GetDefault
//
This function enables the transparent mode.
//
Note: this operation is not reversible.
//
DrawTransparent should be called just after the button is created.
//
Do not use trasparent buttons until you really need it (you have a bitmapped
//
background) since each transparent button makes a copy in memory of its background.
//
This may bring unnecessary memory use and execution overload.
//
//
Parameters:
//
[IN] bRepaint
//
If TRUE the control will be repainted.
//
void
CButtonST::DrawTransparent(BOOL bRepaint)
{
m_bDrawTransparent
=
TRUE;
//
Restore old bitmap (if any)
if
(m_dcBk.m_hDC
!=
NULL
&&
m_pbmpOldBk
!=
NULL)
{
m_dcBk.SelectObject(m_pbmpOldBk);
}
//
if
m_bmpBk.DeleteObject();
m_dcBk.DeleteDC();
//
Repaint the button
if
(bRepaint) Invalidate();
}
//
End of DrawTransparent
DWORD CButtonST::SetBk(CDC
*
pDC)
{
if
(m_bDrawTransparent
&&
pDC)
{
//
Restore old bitmap (if any)
if
(m_dcBk.m_hDC
!=
NULL
&&
m_pbmpOldBk
!=
NULL)
{
m_dcBk.SelectObject(m_pbmpOldBk);
}
//
if
m_bmpBk.DeleteObject();
m_dcBk.DeleteDC();
CRect rect;
CRect rect1;
GetClientRect(rect);
GetWindowRect(rect1);
GetParent()
->
ScreenToClient(rect1);
m_dcBk.CreateCompatibleDC(pDC);
m_bmpBk.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
m_pbmpOldBk
=
m_dcBk.SelectObject(
&
m_bmpBk);
m_dcBk.BitBlt(
0
,
0
, rect.Width(), rect.Height(), pDC, rect1.left, rect1.top, SRCCOPY);
return
BTNST_OK;
}
//
if
return
BTNST_BADPARAM;
}
//
End of SetBk
//
This function sets the URL that will be opened when the button is clicked.
//
//
Parameters:
//
[IN] lpszURL
//
Pointer to a null-terminated string that contains the URL.
//
Pass NULL to removed any previously specified URL.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
DWORD CButtonST::SetURL(LPCTSTR lpszURL)
{
//
Remove any existing URL
memset(m_szURL,
0
,
sizeof
(m_szURL));
if
(lpszURL)
{
//
Store the URL
_tcsncpy(m_szURL, lpszURL, _MAX_PATH);
}
//
if
return
BTNST_OK;
}
//
End of SetURL
//
This function associates a menu to the button.
//
The menu will be displayed clicking the button.
//
//
Parameters:
//
[IN] nMenu
//
ID number of the menu resource.
//
Pass NULL to remove any menu from the button.
//
[IN] hParentWnd
//
Handle to the window that owns the menu.
//
This window receives all messages from the menu.
//
[IN] bRepaint
//
If TRUE the control will be repainted.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
BTNST_INVALIDRESOURCE
//
Failed loading the specified resource.
//
#ifndef BTNST_USE_BCMENU
DWORD CButtonST::SetMenu(UINT nMenu, HWND hParentWnd, BOOL bRepaint)
{
HINSTANCE hInstResource
=
NULL;
//
Destroy any previous menu
if
(m_hMenu)
{
::DestroyMenu(m_hMenu);
m_hMenu
=
NULL;
m_hParentWndMenu
=
NULL;
m_bMenuDisplayed
=
FALSE;
}
//
if
//
Load menu
if
(nMenu)
{
//
Find correct resource handle
hInstResource
=
AfxFindResourceHandle(MAKEINTRESOURCE(nMenu), RT_MENU);
//
Load menu resource
m_hMenu
=
::LoadMenu(hInstResource, MAKEINTRESOURCE(nMenu));
m_hParentWndMenu
=
hParentWnd;
//
If something wrong
if
(m_hMenu
==
NULL)
return
BTNST_INVALIDRESOURCE;
}
//
if
//
Repaint the button
if
(bRepaint) Invalidate();
return
BTNST_OK;
}
//
End of SetMenu
#endif
//
This function associates a menu to the button.
//
The menu will be displayed clicking the button.
//
The menu will be handled by the BCMenu class.
//
//
Parameters:
//
[IN] nMenu
//
ID number of the menu resource.
//
Pass NULL to remove any menu from the button.
//
[IN] hParentWnd
//
Handle to the window that owns the menu.
//
This window receives all messages from the menu.
//
[IN] bWinXPStyle
//
If TRUE the menu will be displayed using the new Windows XP style.
//
If FALSE the menu will be displayed using the standard style.
//
[IN] nToolbarID
//
Resource ID of the toolbar to be associated to the menu.
//
[IN] sizeToolbarIcon
//
A CSize object indicating the size (in pixels) of each icon into the toolbar.
//
All icons into the toolbar must have the same size.
//
[IN] crToolbarBk
//
A COLORREF value indicating the color to use as background for the icons into the toolbar.
//
This color will be used as the "transparent" color.
//
[IN] bRepaint
//
If TRUE the control will be repainted.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
BTNST_INVALIDRESOURCE
//
Failed loading the specified resource.
//
#ifdef BTNST_USE_BCMENU
DWORD CButtonST::SetMenu(UINT nMenu, HWND hParentWnd, BOOL bWinXPStyle, UINT nToolbarID, CSize sizeToolbarIcon, COLORREF crToolbarBk, BOOL bRepaint)
{
BOOL bRetValue
=
FALSE;
//
Destroy any previous menu
if
(m_menuPopup.m_hMenu)
{
m_menuPopup.DestroyMenu();
m_hParentWndMenu
=
NULL;
m_bMenuDisplayed
=
FALSE;
}
//
if
//
Load menu
if
(nMenu)
{
m_menuPopup.SetMenuDrawMode(bWinXPStyle);
//
Load menu
bRetValue
=
m_menuPopup.LoadMenu(nMenu);
//
If something wrong
if
(bRetValue
==
FALSE)
return
BTNST_INVALIDRESOURCE;
//
Load toolbar
if
(nToolbarID)
{
m_menuPopup.SetBitmapBackground(crToolbarBk);
m_menuPopup.SetIconSize(sizeToolbarIcon.cx, sizeToolbarIcon.cy);
bRetValue
=
m_menuPopup.LoadToolbar(nToolbarID);
//
If something wrong
if
(bRetValue
==
FALSE)
{
m_menuPopup.DestroyMenu();
return
BTNST_INVALIDRESOURCE;
}
//
if
}
//
if
m_hParentWndMenu
=
hParentWnd;
}
//
if
//
Repaint the button
if
(bRepaint) Invalidate();
return
BTNST_OK;
}
//
End of SetMenu
#endif
//
This function sets the callback message that will be sent to the
//
specified window just before the menu associated to the button is displayed.
//
//
Parameters:
//
[IN] hWnd
//
Handle of the window that will receive the callback message.
//
Pass NULL to remove any previously specified callback message.
//
[IN] nMessage
//
Callback message to send to window.
//
[IN] lParam
//
A 32 bits user specified value that will be passed to the callback function.
//
//
Remarks:
//
the callback function must be in the form:
//
LRESULT On_MenuCallback(WPARAM wParam, LPARAM lParam)
//
Where:
//
[IN] wParam
//
If support for BCMenu is enabled: a pointer to BCMenu
//
else a HMENU handle to the menu that is being to be displayed.
//
[IN] lParam
//
The 32 bits user specified value.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
DWORD CButtonST::SetMenuCallback(HWND hWnd, UINT nMessage, LPARAM lParam)
{
m_csCallbacks.hWnd
=
hWnd;
m_csCallbacks.nMessage
=
nMessage;
m_csCallbacks.lParam
=
lParam;
return
BTNST_OK;
}
//
End of SetMenuCallback
//
This function resizes the button to the same size of the image.
//
To get good results both the IN and OUT images should have the same size.
//
void
CButtonST::SizeToContent()
{
if
(m_csIcons[
0
].hIcon)
{
m_ptImageOrg.x
=
0
;
m_ptImageOrg.y
=
0
;
SetWindowPos( NULL,
-
1
,
-
1
, m_csIcons[
0
].dwWidth, m_csIcons[
0
].dwHeight,
SWP_NOMOVE
|
SWP_NOZORDER
|
SWP_NOREDRAW
|
SWP_NOACTIVATE);
}
//
if
else
if
(m_csBitmaps[
0
].hBitmap)
{
m_ptImageOrg.x
=
0
;
m_ptImageOrg.y
=
0
;
SetWindowPos( NULL,
-
1
,
-
1
, m_csBitmaps[
0
].dwWidth, m_csBitmaps[
0
].dwHeight,
SWP_NOMOVE
|
SWP_NOZORDER
|
SWP_NOREDRAW
|
SWP_NOACTIVATE);
}
//
if
}
//
End of SizeToContent
//
This function sets the sound that must be played on particular button states.
//
//
Parameters:
//
[IN] lpszSound
//
A string that specifies the sound to play.
//
If hMod is NULL this string is interpreted as a filename, else it
//
is interpreted as a resource identifier.
//
Pass NULL to remove any previously specified sound.
//
[IN] hMod
//
Handle to the executable file that contains the resource to be loaded.
//
This parameter must be NULL unless lpszSound specifies a resource identifier.
//
[IN] bPlayOnClick
//
TRUE if the sound must be played when the button is clicked.
//
FALSE if the sound must be played when the mouse is moved over the button.
//
[IN] bPlayAsync
//
TRUE if the sound must be played asynchronously.
//
FALSE if the sound must be played synchronously. The application takes control
//
when the sound is completely played.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
#ifdef BTNST_USE_SOUND
DWORD CButtonST::SetSound(LPCTSTR lpszSound, HMODULE hMod, BOOL bPlayOnClick, BOOL bPlayAsync)
{
BYTE byIndex
=
bPlayOnClick
?
1
:
0
;
//
Store new sound
if
(lpszSound)
{
if
(hMod)
//
From resource identifier ?
{
m_csSounds[byIndex].lpszSound
=
lpszSound;
}
//
if
else
{
_tcscpy(m_csSounds[byIndex].szSound, lpszSound);
m_csSounds[byIndex].lpszSound
=
m_csSounds[byIndex].szSound;
}
//
else
m_csSounds[byIndex].hMod
=
hMod;
m_csSounds[byIndex].dwFlags
=
SND_NODEFAULT
|
SND_NOWAIT;
m_csSounds[byIndex].dwFlags
|=
hMod
?
SND_RESOURCE : SND_FILENAME;
m_csSounds[byIndex].dwFlags
|=
bPlayAsync
?
SND_ASYNC : SND_SYNC;
}
//
if
else
{
//
Or remove any existing
::ZeroMemory(
&
m_csSounds[byIndex],
sizeof
(STRUCT_SOUND));
}
//
else
return
BTNST_OK;
}
//
End of SetSound
#endif
//
This function is called every time the button background needs to be painted.
//
If the button is in transparent mode this function will NOT be called.
//
This is a virtual function that can be rewritten in CButtonST-derived classes
//
to produce a whole range of buttons not available by default.
//
//
Parameters:
//
[IN] pDC
//
Pointer to a CDC object that indicates the device context.
//
[IN] pRect
//
Pointer to a CRect object that indicates the bounds of the
//
area to be painted.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
DWORD CButtonST::OnDrawBackground(CDC
*
pDC, CRect
*
pRect)
{
COLORREF crColor;
if
(m_bIsFlat
==
FALSE)
{
if
(m_bIsFocused
||
m_bIsDefault)
{
CBrush br(RGB(
0
,
0
,
0
));
pDC
->
FrameRect(pRect,
&
br);
pRect
->
DeflateRect(
1
,
1
);
}
//
if
}
//
if
if
(m_bMouseOnButton
||
m_bIsPressed)
crColor
=
m_crColors[BTNST_COLOR_BK_IN];
else
{
if
(m_bIsFocused)
crColor
=
m_crColors[BTNST_COLOR_BK_FOCUS];
else
crColor
=
m_crColors[BTNST_COLOR_BK_OUT];
}
//
else
CBrush brBackground(crColor);
pDC
->
FillRect(pRect,
&
brBackground);
return
BTNST_OK;
}
//
End of OnDrawBackground
//
This function is called every time the button border needs to be painted.
//
This is a virtual function that can be rewritten in CButtonST-derived classes
//
to produce a whole range of buttons not available by default.
//
//
Parameters:
//
[IN] pDC
//
Pointer to a CDC object that indicates the device context.
//
[IN] pRect
//
Pointer to a CRect object that indicates the bounds of the
//
area to be painted.
//
//
Return value:
//
BTNST_OK
//
Function executed successfully.
//
DWORD CButtonST::OnDrawBorder(CDC
*
pDC, CRect
*
pRect)
{
//
Draw pressed button
if
(m_bIsPressed)
{
if
(m_bIsFlat)
{
if
(m_bDrawBorder)
pDC
->
Draw3dRect(pRect, ::GetSysColor(COLOR_BTNSHADOW), ::GetSysColor(COLOR_BTNHILIGHT));
}
else
{
CBrush brBtnShadow(GetSysColor(COLOR_BTNSHADOW));
pDC
->
FrameRect(pRect,
&
brBtnShadow);
}
}
else
//
else draw non pressed button
{
CPen penBtnHiLight(PS_SOLID,
0
, GetSysColor(COLOR_BTNHILIGHT));
//
White
CPen pen3DLight(PS_SOLID,
0
, GetSysColor(COLOR_3DLIGHT));
//
Light gray
CPen penBtnShadow(PS_SOLID,
0
, GetSysColor(COLOR_BTNSHADOW));
//
Dark gray
CPen pen3DDKShadow(PS_SOLID,
0
, GetSysColor(COLOR_3DDKSHADOW));
//
Black
if
(m_bIsFlat)
{
if
(m_bMouseOnButton
&&
m_bDrawBorder)
pDC
->
Draw3dRect(pRect, ::GetSysColor(COLOR_BTNHILIGHT), ::GetSysColor(COLOR_BTNSHADOW));
}
else
{
//
Draw top-left borders
//
White line
CPen
*
pOldPen
=
pDC
->
SelectObject(
&
penBtnHiLight);
pDC
->
MoveTo(pRect
->
left, pRect
->
bottom
-
1
);
pDC
->
LineTo(pRect
->
left, pRect
->
top);
pDC
->
LineTo(pRect
->
right, pRect
->
top);
//
Light gray line
pDC
->
SelectObject(pen3DLight);
pDC
->
MoveTo(pRect
->
left
+
1
, pRect
->
bottom
-
1
);
pDC
->
LineTo(pRect
->
left
+
1
, pRect
->
top
+
1
);
pDC
->
LineTo(pRect
->
right, pRect
->
top
+
1
);
//
Draw bottom-right borders
//
Black line
pDC
->
SelectObject(pen3DDKShadow);
pDC
->
MoveTo(pRect
->
left, pRect
->
bottom
-
1
);
pDC
->
LineTo(pRect
->
right
-
1
, pRect
->
bottom
-
1
);
pDC
->
LineTo(pRect
->
right
-
1
, pRect
->
top
-
1
);
//
Dark gray line
pDC
->
SelectObject(penBtnShadow);
pDC
->
MoveTo(pRect
->
left
+
1
, pRect
->
bottom
-
2
);
pDC
->
LineTo(pRect
->
right
-
2
, pRect
->
bottom
-
2
);
pDC
->
LineTo(pRect
->
right
-
2
, pRect
->
top);
//
pDC
->
SelectObject(pOldPen);
}
//
else
}
//
else
return
BTNST_OK;
}
//
End of OnDrawBorder
#undef
BS_TYPEMASK
Posted on 2007-04-12 11:49
艾凡赫
阅读(752)
评论(0)
编辑
收藏
引用
只有注册用户
登录
后才能发表评论。
【推荐】100%开源!大型工业跨平台软件C++源码提供,建模,组态!
网站导航:
博客园
IT新闻
BlogJava
博问
Chat2DB
管理
<
2024年12月
>
日
一
二
三
四
五
六
24
25
26
27
28
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
常用链接
我的随笔
我的评论
我参与的随笔
留言簿
(19)
给我留言
查看公开留言
查看私人留言
随笔分类
(12)
ADO(2)
Arithmetic
C/C++(1)
COM
DLL
MFC(4)
NET WORK(1)
ORACLE
OTL
OTL
SQL Server
STL
Thread
traits技术
设计模式
兴致所至(4)
随笔档案
(16)
2008年9月 (1)
2007年1月 (8)
2006年12月 (1)
2006年10月 (1)
2006年3月 (1)
2005年9月 (4)
文章分类
(295)
ADO.NET(1)
ADO编程技术(19)
C++(71)
COM(11)
C语言(5)
DLL 技术(13)
Linux(2)
MFC技术(41)
ORACLE(17)
P2P(7)
SqlServer(9)
win32 sdk 编程(7)
Windows Mobile开发(8)
多线程(8)
共享内存
好 玩(1)
基础知识(16)
加密解密(1)
其 他(2)
设计模式
手机编程
数据库(14)
数据类型(7)
算 法(12)
网络编程(23)
文章档案
(261)
2007年12月 (1)
2007年11月 (3)
2007年9月 (1)
2007年4月 (40)
2007年3月 (4)
2007年1月 (1)
2006年12月 (4)
2006年11月 (15)
2006年10月 (4)
2006年9月 (50)
2006年7月 (1)
2006年4月 (5)
2006年1月 (20)
2005年12月 (47)
2005年11月 (56)
2005年10月 (9)
收藏夹
美文
C#
COM
MFC
【 Visual C++ 教 程 】
MFC 教程
VC编程技巧
VC编程网
VC学习
Web
基础知识
PE文件格式详解
汇编语言
数据结构
网络教学
开发学习
天新网
移动开发网
网络
注册过的论坛网站
最新随笔
1. 麦兜故事
2. 转载--地主与长工
3. 呵呵,还不怎么会用,差点出事
4. 第一次
5. 呵呵!开业大吉!!!
搜索
积分与排名
积分 - 483276
排名 - 42
最新评论
1. re: 哈夫曼编码的源代码[未登录]
有没有联系方式,大神求带,本人qq1984425565,大神求带
--无
2. re: 消除回溯算法的程序实现
设计内容及要求:构造一程序,实现:消除文法每一条产生式候选式的公共左因子。对于用户任意输入的文法G,输出一个无回溯的等价文法,可显示输出,或输出到指定文件中。
--王康
3. re: MFC规则DLL 简单的例子
这个文章是从课本上复制的不?
--张亚成
4. re: _variant_t 到 CString 转换
帮了我一把!拜谢
--苦想者
5. re: ADO连接字符串
评论内容较长,点击标题查看
--BestEssays rewiew
阅读排行榜
1. 使用wxWidgets开发跨平台的GUI程序(转)(4461)
2. CRichEditCtrl (3465)
3. 转载--地主与长工 (2644)
4. VC中自动改变控件位置和大小的对话框类(转)(2196)
5. VC6.0中使用Stream Object读取数据中流文件并显示Bmp,JPG等图片 (转)(1756)
评论排行榜
1. 呵呵!开业大吉!!!(5)
2. 转载--地主与长工 (4)
3. 麦兜故事(1)
4. 第一次(1)
5. 呵呵,还不怎么会用,差点出事(1)