📄 static.c
字号:
textA = NULL;
textW = ((LPCREATESTRUCTW)lParam)->lpszName;
}
else
{
textA = ((LPCREATESTRUCTA)lParam)->lpszName;
textW = NULL;
}
switch (style) {
case SS_ICON:
{
HICON hIcon;
if(unicode)
hIcon = STATIC_LoadIconW(hwnd, textW, full_style);
else
hIcon = STATIC_LoadIconA(hwnd, textA, full_style);
STATIC_SetIcon(hwnd, hIcon, full_style);
}
break;
case SS_BITMAP:
{
HBITMAP hBitmap;
if(unicode)
hBitmap = STATIC_LoadBitmapW(hwnd, textW);
else
hBitmap = STATIC_LoadBitmapA(hwnd, textA);
STATIC_SetBitmap(hwnd, hBitmap, full_style);
}
break;
}
/* SS_ENHMETAFILE: Despite what MSDN says, Windows does not load
the enhanced metafile that was specified as the window text. */
}
return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
DefWindowProcA(hwnd, uMsg, wParam, lParam);
case WM_SETTEXT:
if (hasTextStyle( full_style ))
{
if (HIWORD(lParam))
{
if(unicode)
lResult = DefWindowProcW( hwnd, uMsg, wParam, lParam );
else
lResult = DefWindowProcA( hwnd, uMsg, wParam, lParam );
STATIC_TryPaintFcn( hwnd, full_style );
}
}
break;
case WM_SETFONT:
if (hasTextStyle( full_style ))
{
SetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET, wParam );
if (LOWORD(lParam))
STATIC_TryPaintFcn( hwnd, full_style );
}
break;
case WM_GETFONT:
return GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
case WM_NCHITTEST:
if (full_style & SS_NOTIFY)
return HTCLIENT;
else
return HTTRANSPARENT;
case WM_GETDLGCODE:
return DLGC_STATIC;
case WM_LBUTTONDOWN:
case WM_NCLBUTTONDOWN:
if (full_style & SS_NOTIFY)
SendMessageW( GetParent(hwnd), WM_COMMAND,
MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_CLICKED ), (LPARAM)hwnd);
return 0;
case WM_LBUTTONDBLCLK:
case WM_NCLBUTTONDBLCLK:
if (full_style & SS_NOTIFY)
SendMessageW( GetParent(hwnd), WM_COMMAND,
MAKEWPARAM( GetWindowLongPtrW(hwnd,GWLP_ID), STN_DBLCLK ), (LPARAM)hwnd);
return 0;
case STM_GETIMAGE:
return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
#ifndef __REACTOS__
case STM_GETICON16:
#endif
case STM_GETICON:
return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
case STM_SETIMAGE:
switch(wParam) {
case IMAGE_BITMAP:
lResult = (LRESULT)STATIC_SetBitmap( hwnd, (HBITMAP)lParam, full_style );
break;
// case IMAGE_ENHMETAFILE:
// lResult = (LRESULT)STATIC_SetEnhMetaFile( hwnd, (HENHMETAFILE)lParam, full_style );
// break;
case IMAGE_ICON:
case IMAGE_CURSOR:
lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)lParam, full_style );
break;
default:
FIXME("STM_SETIMAGE: Unhandled type %x\n", wParam);
break;
}
STATIC_TryPaintFcn( hwnd, full_style );
break;
#ifndef __REACTOS__
case STM_SETICON16:
#endif
case STM_SETICON:
lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
STATIC_TryPaintFcn( hwnd, full_style );
break;
default:
return unicode ? DefWindowProcW(hwnd, uMsg, wParam, lParam) :
DefWindowProcA(hwnd, uMsg, wParam, lParam);
}
return lResult;
}
/***********************************************************************
* StaticWndProcA
*/
static LRESULT WINAPI StaticWndProcA( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
if (!IsWindow( hWnd )) return 0;
return StaticWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
}
/***********************************************************************
* StaticWndProcW
*/
static LRESULT WINAPI StaticWndProcW( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
if (!IsWindow( hWnd )) return 0;
return StaticWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
}
static void STATIC_PaintOwnerDrawfn( HWND hwnd, HDC hdc, DWORD style )
{
DRAWITEMSTRUCT dis;
HFONT font, oldFont = NULL;
UINT id = (UINT)GetWindowLongPtrW( hwnd, GWLP_ID );
dis.CtlType = ODT_STATIC;
dis.CtlID = id;
dis.itemID = 0;
dis.itemAction = ODA_DRAWENTIRE;
dis.itemState = IsWindowEnabled(hwnd) ? 0 : ODS_DISABLED;
dis.hwndItem = hwnd;
dis.hDC = hdc;
dis.itemData = 0;
GetClientRect( hwnd, &dis.rcItem );
font = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET );
if (font) oldFont = SelectObject( hdc, font );
SendMessageW( GetParent(hwnd), WM_CTLCOLORSTATIC, (WPARAM)hdc, (LPARAM)hwnd );
SendMessageW( GetParent(hwnd), WM_DRAWITEM, id, (LPARAM)&dis );
if (font) SelectObject( hdc, oldFont );
}
static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, DWORD style )
{
RECT rc;
HBRUSH hBrush;
HFONT hFont, hOldFont = NULL;
WORD wFormat;
INT len;
WCHAR *text;
GetClientRect( hwnd, &rc);
switch (style & SS_TYPEMASK)
{
case SS_LEFT:
wFormat = DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK;
break;
case SS_CENTER:
wFormat = DT_CENTER | DT_EXPANDTABS | DT_WORDBREAK;
break;
case SS_RIGHT:
wFormat = DT_RIGHT | DT_EXPANDTABS | DT_WORDBREAK;
break;
case SS_SIMPLE:
wFormat = DT_LEFT | DT_SINGLELINE;
break;
case SS_LEFTNOWORDWRAP:
wFormat = DT_LEFT | DT_EXPANDTABS;
break;
default:
return;
}
if (style & SS_NOPREFIX)
wFormat |= DT_NOPREFIX;
if ((style & SS_TYPEMASK) != SS_SIMPLE)
{
if (style & SS_CENTERIMAGE)
wFormat |= DT_SINGLELINE | DT_VCENTER;
if (style & SS_EDITCONTROL)
wFormat |= DT_EDITCONTROL;
if (style & SS_ENDELLIPSIS)
wFormat |= DT_SINGLELINE | DT_END_ELLIPSIS;
if (style & SS_PATHELLIPSIS)
wFormat |= DT_SINGLELINE | DT_PATH_ELLIPSIS;
if (style & SS_WORDELLIPSIS)
wFormat |= DT_SINGLELINE | DT_WORD_ELLIPSIS;
}
if ((hFont = (HFONT)GetWindowLongPtrW( hwnd, HFONT_GWL_OFFSET )))
hOldFont = (HFONT)SelectObject( hdc, hFont );
/* SS_SIMPLE controls: WM_CTLCOLORSTATIC is sent, but the returned
brush is not used */
hBrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
if ((style & SS_TYPEMASK) != SS_SIMPLE)
{
FillRect( hdc, &rc, hBrush );
if (!IsWindowEnabled(hwnd)) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
}
if (!(len = SendMessageW( hwnd, WM_GETTEXTLENGTH, 0, 0 ))) return;
if (!(text = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return;
SendMessageW( hwnd, WM_GETTEXT, len + 1, (LPARAM)text );
if (((style & SS_TYPEMASK) == SS_SIMPLE) && (style & SS_NOPREFIX))
{
/* Windows uses the faster ExtTextOut() to draw the text and
to paint the whole client rectangle with the text background
color. Reference: "Static Controls" by Kyle Marsh, 1992 */
ExtTextOutW( hdc, rc.left, rc.top, ETO_CLIPPED | ETO_OPAQUE,
&rc, text, len, NULL );
}
else
{
DrawTextW( hdc, text, -1, &rc, wFormat );
}
HeapFree( GetProcessHeap(), 0, text );
if (hFont)
SelectObject( hdc, hOldFont );
}
static void STATIC_PaintRectfn( HWND hwnd, HDC hdc, DWORD style )
{
RECT rc;
HBRUSH hBrush;
GetClientRect( hwnd, &rc);
switch (style & SS_TYPEMASK)
{
case SS_BLACKRECT:
hBrush = CreateSolidBrush(color_3ddkshadow);
FillRect( hdc, &rc, hBrush );
break;
case SS_GRAYRECT:
hBrush = CreateSolidBrush(color_3dshadow);
FillRect( hdc, &rc, hBrush );
break;
case SS_WHITERECT:
hBrush = CreateSolidBrush(color_3dhighlight);
FillRect( hdc, &rc, hBrush );
break;
case SS_BLACKFRAME:
hBrush = CreateSolidBrush(color_3ddkshadow);
FrameRect( hdc, &rc, hBrush );
break;
case SS_GRAYFRAME:
hBrush = CreateSolidBrush(color_3dshadow);
FrameRect( hdc, &rc, hBrush );
break;
case SS_WHITEFRAME:
hBrush = CreateSolidBrush(color_3dhighlight);
FrameRect( hdc, &rc, hBrush );
break;
default:
return;
}
DeleteObject( hBrush );
}
/* Modified for ReactOS */
static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
{
RECT rc, iconRect;
HBRUSH hbrush;
HICON hIcon;
ICONINFO info;
GetClientRect( hwnd, &rc );
hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
if (!hIcon || (!GetIconInfo(hIcon, &info)))
{
FillRect(hdc, &rc, hbrush);
}
else
{
BITMAP bm;
if (!GetObjectW(info.hbmColor, sizeof(BITMAP), &bm)) return;
if (style & SS_CENTERIMAGE)
{
iconRect.left = (rc.right - rc.left) / 2 - bm.bmWidth / 2;
iconRect.top = (rc.bottom - rc.top) / 2 - bm.bmHeight / 2;
iconRect.right = iconRect.left + bm.bmWidth;
iconRect.bottom = iconRect.top + bm.bmHeight;
}
else
iconRect = rc;
FillRect( hdc, &rc, hbrush );
DrawIconEx( hdc, iconRect.left, iconRect.top, hIcon, iconRect.right - iconRect.left,
iconRect.bottom - iconRect.top, 0, NULL, DI_NORMAL );
}
}
static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
{
HDC hMemDC;
HBITMAP hBitmap, oldbitmap;
HBRUSH hbrush;
/* message is still sent, even if the returned brush is not used */
hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
if ((hBitmap = (HBITMAP)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET ))
&& (GetObjectType(hBitmap) == OBJ_BITMAP)
&& (hMemDC = CreateCompatibleDC( hdc )))
{
BITMAP bm;
RECT rcClient;
LOGBRUSH brush;
GetObjectW(hBitmap, sizeof(bm), &bm);
oldbitmap = SelectObject(hMemDC, hBitmap);
/* Set the background color for monochrome bitmaps
to the color of the background brush */
if (GetObjectW( hbrush, sizeof(brush), &brush ))
{
if (brush.lbStyle == BS_SOLID)
SetBkColor(hdc, brush.lbColor);
}
GetClientRect(hwnd, &rcClient);
if (style & SS_CENTERIMAGE)
{
INT x, y;
x = (rcClient.right - rcClient.left)/2 - bm.bmWidth/2;
y = (rcClient.bottom - rcClient.top)/2 - bm.bmHeight/2;
FillRect( hdc, &rcClient, hbrush );
BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0,
SRCCOPY);
}
else
{
StretchBlt(hdc, 0, 0, rcClient.right - rcClient.left,
rcClient.bottom - rcClient.top, hMemDC,
0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
}
SelectObject(hMemDC, oldbitmap);
DeleteDC(hMemDC);
}
else
{
RECT rcClient;
GetClientRect( hwnd, &rcClient );
FillRect( hdc, &rcClient, hbrush );
}
}
//static void STATIC_PaintEnhMetafn(HWND hwnd, HDC hdc, DWORD style )
//{
// HENHMETAFILE hEnhMetaFile;
// RECT rc;
// HBRUSH hbrush;
//
// GetClientRect(hwnd, &rc);
// hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
// FillRect(hdc, &rc, hbrush);
// if ((hEnhMetaFile = (HENHMETAFILE)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET )))
// {
// /* The control's current font is not selected into the
// device context! */
// if (GetObjectType(hEnhMetaFile) == OBJ_ENHMETAFILE)
// PlayEnhMetaFile(hdc, hEnhMetaFile, &rc);
// }
//}
static void STATIC_PaintEtchedfn( HWND hwnd, HDC hdc, DWORD style )
{
RECT rc;
GetClientRect( hwnd, &rc );
switch (style & SS_TYPEMASK)
{
case SS_ETCHEDHORZ:
DrawEdge(hdc,&rc,EDGE_ETCHED,BF_TOP|BF_BOTTOM);
break;
case SS_ETCHEDVERT:
DrawEdge(hdc,&rc,EDGE_ETCHED,BF_LEFT|BF_RIGHT);
break;
case SS_ETCHEDFRAME:
DrawEdge (hdc, &rc, EDGE_ETCHED, BF_RECT);
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -