⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 button.c

📁 一个嵌入式操作系统(microwindows)的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	case BS_CHECKBOX:	case BS_AUTOCHECKBOX:		FastFillRect(hdc, &rc, GetSysColor(COLOR_BTNFACE));		/*rc.left += 2;*/		/*rc.top += 2;*/		rc.right = rc.left + 12;		rc.bottom = rc.top + 12;		/*Draw3dBox(hdc, rc.left, rc.top, 8, 8,			GetSysColor(COLOR_BTNSHADOW), GetSysColor(COLOR_3DLIGHT));*/		Draw3dInset(hdc, rc.left, rc.top, 12, 12);		InsetR(&rc, 2, 2);		FastFillRect(hdc, &rc, GetSysColor(COLOR_BTNHIGHLIGHT));		iFaceOffset = 1;		if(wEnumState & PBS_CHECKED) {			MoveToEx(hdc, rc.left, rc.top,NULL);			LineTo(hdc, rc.right, rc.bottom);			MoveToEx(hdc, rc.left, rc.bottom,NULL);			LineTo(hdc, rc.right, rc.top);		}		break;       	case BS_AUTORADIOBUTTON:        case BS_RADIOBUTTON:		FastFillRect(hdc, &rc, GetSysColor(COLOR_BTNFACE));		rc.left = 0;		rc.top += 1;		rc.right = rc.left + 10;		rc.bottom = rc.top + 10;		SelectObject(hdc, GetStockObject(NULL_BRUSH));		hOldPen = SelectObject(hdc, CreatePen(PS_SOLID, 1,			GetSysColor(COLOR_BTNSHADOW)));		SelectObject(hdc, GetStockObject(WHITE_BRUSH));		Ellipse(hdc,rc.left,rc.top, rc.right,rc.bottom);		InsetR(&rc, 1, 1);		SelectObject(hdc, GetStockObject(WHITE_BRUSH));		DeleteObject(SelectObject(hdc, 			CreatePen(PS_SOLID, 1,GetSysColor(COLOR_WINDOWFRAME))));		Ellipse(hdc,rc.left,rc.top, rc.right,rc.bottom);		DeleteObject(SelectObject(hdc, hOldPen));		iFaceOffset = 0;		if(wEnumState & PBS_CHECKED)			Ellipse(hdc, rc.left+2, rc.top+2, rc.right-2,					rc.bottom-2);		break;	}	/*	 * draw text	 */	if(buf[ 0]) {		hNewFont = GetStockObject( DEFAULT_GUI_FONT);		hOldFont = SelectObject( hdc, hNewFont);		/* calculate text bounding rect*/		rect.left = 0;		rect.top = 0;		DrawText( hdc, buf, -1, &rect, DT_CALCRECT | DT_LEFT |			DT_SINGLELINE | DT_TOP);		rectSave = rect;		/*		 * calculate text draw location		 */		switch((int)(dwStyle & (BS_LEFT|BS_CENTER|BS_RIGHT))) {		case BS_CENTER:		default:			rect.left = (uiWidth - (rect.right - rect.left)) / 2				+ iFaceOffset;			break; 		case BS_LEFT:			rect.left = uiWidthFrame + uiWidthShadow + 2				+ iFaceOffset;			break;		case BS_RIGHT:			rect.left = (rect.right - rect.left) + uiWidthFrame				+ uiWidthShadow + 4 + iFaceOffset;			break;		}		switch((int)(dwStyle & 0x0f)) {		case BS_CHECKBOX:		case BS_AUTOCHECKBOX:		case BS_AUTORADIOBUTTON:		case BS_RADIOBUTTON:			rect.left = 12;			break;		}		rect.right += rect.left - rectSave.left;		switch((int)(dwStyle & (BS_TOP|BS_VCENTER|BS_BOTTOM))) {		case BS_VCENTER:		default:			rect.top = (uiHeight - (rect.bottom - rect.top)) / 2				+ iFaceOffset;			break;		case BS_TOP:			rect.top = 2 + uiWidthFrame + uiWidthShadow				+ iFaceOffset;			break;		case BS_BOTTOM:			rect.top = uiHeight - uiWidthFrame - uiWidthShadow -				(rect.bottom - rect.top) - 1 + iFaceOffset;			break;		}		switch((int)(dwStyle & 0x0f)) {		case BS_CHECKBOX:		case BS_AUTOCHECKBOX:		case BS_AUTORADIOBUTTON:		case BS_RADIOBUTTON:			rect.top = 0;			break;		}		rect.bottom += rect.top - rectSave.top;		oldBkMode = SetBkMode( hdc, TRANSPARENT);		if(wEnumState & PBS_DISABLED)			hOldColor = SetTextColor( hdc,				GetSysColor( COLOR_GRAYTEXT));		else			hOldColor = SetTextColor( hdc,				GetSysColor( COLOR_BTNTEXT));		DrawText( hdc, buf, -1, &rect,DT_LEFT | DT_SINGLELINE | DT_TOP);		SetBkMode( hdc, oldBkMode);		SetTextColor( hdc, hOldColor);		SelectObject( hdc, hOldFont);	}#if 0	if( (!(wEnumState&PBS_CHECKED) && (wEnumState&PBS_FOCUSDOWN)) || 						(wEnumState & PBS_FOCUSUP)) {		rect = rectClient;		uiWidth = uiWidthFrame + uiWidthShadow + 2;		rect.left += uiWidth;		rect.top += uiWidth;		rect.right -= uiWidth;		rect.bottom -= uiWidth;		if((dwStyle & (BS_FLAT|BS_NOFOCUSRECT)) == 0)			DrawFocusRect( hdc, &rect);	}#endif	SetTextColor( hdc, crOld);	SetBkColor( hdc, crBkOld);Return:	EndPaint(hwnd, &ps);}static void WINAPIcenButton_OnSetFocus(HWND		hwnd,HWND		hwndOldFocus){	/* WM_SETFOCUS is sent when the user clicks on the control */	/* or when the dialog manager determines that a keystroke  */	/* should cause the control to be focused.	This affects   */	/* the appearance of the control so the state is saved for */	/* future drawing.										   */	WORD		wState;	wState = cenButton_FnStart( hwnd);	/*if(!IsWindowEnabled(hwnd))		cenButton_SetState( hwnd, PUSH_FOCUS, TRUE );*/	cenButton_FnEnd( hwnd, wState);}static void WINAPIcenButton_OnSetStyle(HWND		hwnd,WORD		style,BOOL		bRedraw){	WORD		wState;	wState = cenButton_FnStart( hwnd);	cenButton_SetState( hwnd, PUSH_DEFAULT,		(style & 0x0f) == BS_DEFPUSHBUTTON);	cenButton_FnEnd( hwnd, wState);}static void WINAPIcenButton_OnSetState(HWND		hwnd,WORD		wState){	WORD		wStateOld;	wStateOld = cenButton_FnStart( hwnd);	cenButton_SetState( hwnd, PUSH_DOWN, (wState ? TRUE : FALSE ) );	cenButton_FnEnd( hwnd, wStateOld);}static void WINAPIcenButton_SetState(HWND	hwnd,WORD	wState,BOOL	bEnable ){	/* Turn on/off state bits according to the bEnable flag.  If the   */	/* new state is different, invalidate the client window so that	   */	/* the proper bitmap is displayed.								   */	WORD	wNewState;	WORD	wOldState;	RECT	rectClient;	wOldState = GET_PBSTATE( hwnd);	wNewState = (bEnable ? (wOldState | wState) : (wOldState & ~wState));	if (wOldState != wNewState)	{	SET_PBSTATE( hwnd, wNewState );		GetClientRect(hwnd, &rectClient);		InvalidateRect(hwnd, &rectClient, FALSE);	}}#if 0static void WINAPIcenButton_OnSetFont(HWND		hwnd,HFONT		hFont,BOOL		bRedraw){	BOOL		bDeleteFont = FALSE;	HFONT		hFontNew = 0;	LOGFONT		logFont;	/* create a thin font*/	if( GetObject( hFont, sizeof( logFont), &logFont) != 0) {		if( logFont.lfWeight != FW_NORMAL) {			logFont.lfWeight = FW_NORMAL;			if( ( hFontNew = CreateFontIndirect( &logFont)) != 0) {				hFont = hFontNew;				bDeleteFont = TRUE;			}		}	}	if( GET_PBDELETEFONT( hwnd))		DeleteObject( GET_PBFONT( hwnd));	SET_PBDELETEFONT( hwnd, bDeleteFont);	SET_PBFONT( hwnd, hFont);	FORWARD_WM_SETFONT( hwnd, hFont, bRedraw, DefWindowProc);}#endifstatic void WINAPIcenButton_OnSetText(HWND		hwnd,LPCSTR		lpszText){	/* WM_SETTEXT is sent to change the text of the button	   */	/* control.	 In this case we allow the default window proc */	/* to handle the message first.	 But this only affects the */	/* internal Windows data structure of the control, it does */	/* not display the change.	To do this we invalidate and   */	/* update the client area of the control which displays	   */	/* the new text.										   */	FORWARD_WM_SETTEXT( hwnd, lpszText, DefWindowProc);	InvalidateRect( hwnd, NULL, FALSE);	UpdateWindow( hwnd);}LRESULT CALLBACKcenButtonWndFn(HWND	hwnd,UINT	message,WPARAM	wParam,LPARAM	lParam){	/* This is the window proc for the pushbutton control.	Most of	   */	/* the drawing is accomplished in the DrawPushButton() function. */	/* The code below is mainly concerned with the keyboard and mouse  */	/* events that the control detects.								   */	switch( message) {	HANDLE_MSG( hwnd, WM_CREATE, cenButton_OnCreate);	/*HANDLE_MSG( hwnd, WM_ENABLE, cenButton_OnEnable);*/	HANDLE_MSG( hwnd, WM_SETFOCUS, cenButton_OnSetFocus);	HANDLE_MSG( hwnd, WM_KILLFOCUS, cenButton_OnKillFocus);	HANDLE_MSG( hwnd, WM_LBUTTONDOWN, cenButton_OnLButtonDown);	HANDLE_MSG( hwnd, WM_LBUTTONDBLCLK, cenButton_OnLButtonDown);	HANDLE_MSG( hwnd, WM_LBUTTONUP, cenButton_OnLButtonUp);	HANDLE_MSG( hwnd, WM_MOUSEMOVE, cenButton_OnMouseMove);	/*HANDLE_MSG( hwnd, WM_KEYDOWN, cenButton_OnKey);*/	/*HANDLE_MSG( hwnd, WM_KEYUP, cenButton_OnKey);*/	HANDLE_MSG( hwnd, WM_ERASEBKGND, cenButton_OnEraseBkgnd);	HANDLE_MSG( hwnd, WM_PAINT_SPECIAL, cenButton_OnPaint);	/*HANDLE_MSG( hwnd, WM_GETDLGCODE, cenButton_OnGetDlgCode);*/	HANDLE_MSG( hwnd, BM_SETSTYLE, cenButton_OnSetStyle);	HANDLE_MSG( hwnd, BM_GETSTATE, cenButton_OnGetState);	HANDLE_MSG( hwnd, BM_SETSTATE, cenButton_OnSetState);	/*HANDLE_MSG( hwnd, WM_DESTROY, cenButton_OnDestroy);*/	/*HANDLE_MSG( hwnd, WM_SETFONT, cenButton_OnSetFont);*/	HANDLE_MSG( hwnd, WM_SETTEXT, cenButton_OnSetText);	case BM_GETCHECK:#if 0 		return cenButton_OnGetState(hwnd);#else 		return( ( GET_PBSTATE(hwnd) & PUSH_CHECKED) == PUSH_CHECKED);#endif	case BM_SETCHECK:#if 0		cenButton_OnSetState(hwnd, (WORD)wParam);#else{		WORD		wStateOld;		wStateOld = cenButton_FnStart( hwnd);		cenButton_SetState( hwnd, PUSH_CHECKED,			((WORD)wParam ? TRUE : FALSE) );		cenButton_FnEnd( hwnd, wStateOld);}#endif		return 0;	case BM_SETIMAGE:            	hwnd->userdata = (DWORD)wParam;            	InvalidateRect(hwnd, NULL, FALSE);		return 0;	}	return DefWindowProc( hwnd, message, wParam, lParam);}/* backwards compatibility*/int WINAPIMwButtonRegister(HINSTANCE hInstance){	return MwRegisterButtonControl(hInstance);}int WINAPIMwRegisterButtonControl(HINSTANCE hInstance){	WNDCLASS	wc;	wc.style	= CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_GLOBALCLASS;	wc.lpfnWndProc	= (WNDPROC)cenButtonWndFn;	wc.cbClsExtra	= 0;	wc.cbWndExtra	= 10;	wc.hInstance	= hInstance;	wc.hIcon	= NULL;	wc.hCursor	= 0; /*LoadCursor(NULL, IDC_ARROW);*/	wc.hbrBackground= GetStockObject(LTGRAY_BRUSH);	wc.lpszMenuName	= NULL;	wc.lpszClassName= "BUTTON";	return RegisterClass(&wc);}static void WINAPIDrawGroupBox(HWND hwnd,HDC hDCwParam,DWORD dwStyle){	HDC		hdc;	HFONT 		hFont;	RECT		rcClient;	RECT		rcText;	RECT		rc;	PAINTSTRUCT	ps;	char		buf[256];	HPEN		hPenTop, hPenBottom, holdPen;	COLORREF 	crTop,crBottom;	hdc = BeginPaint(hwnd, &ps);	if(!hdc)		goto Return;	GetWindowText(hwnd, buf, sizeof(buf));	GetClientRect( hwnd, &rcClient );	hFont = GetStockObject( DEFAULT_GUI_FONT);	if (hFont)		hFont = SelectObject(hdc,hFont);	rc.left = 0;	rc.top = 0;	DrawText( hdc, buf, -1, &rc, DT_CALCRECT);	if(buf[ 0]) {		SetTextColor(hdc,GetSysColor(COLOR_WINDOWTEXT));		SetBkMode(hdc,TRANSPARENT);		SetRect(&rcText,8,2,rc.right+8,rc.bottom+2);		DrawText(hdc,buf,-1,&rcText,DT_CENTER);	}	crTop=GetSysColor(COLOR_BTNHIGHLIGHT);	crBottom=GetSysColor(COLOR_BTNSHADOW);	hPenTop = CreatePen( PS_SOLID, 1, crTop);	hPenBottom = CreatePen( PS_SOLID, 1, crBottom);	holdPen = SelectObject( hdc, hPenTop);	MoveToEx(hdc,0,rc.bottom/2,NULL);	if(buf[ 0]) {		LineTo(hdc,5,rc.bottom/2);		MoveToEx(hdc,rc.right+11,rc.bottom/2,NULL);		LineTo(hdc,rcClient.right-1,rc.bottom/2);	}	else		LineTo(hdc,rcClient.right-1,rc.bottom/2);	LineTo(hdc,rcClient.right-1,rcClient.bottom-1);	SelectObject( hdc, hPenBottom);	LineTo(hdc,rcClient.left,rcClient.bottom-1);	LineTo(hdc,rcClient.left,rc.bottom/2);	SelectObject( hdc, holdPen);	DeleteObject( hPenTop);	DeleteObject( hPenBottom);	if (hFont)		SelectObject(hdc,hFont);Return:	EndPaint(hwnd, &ps);}/* temporarily here, should move to winuser.c*/void WINAPICheckRadioButton(HWND hDlg, int nIDFirst,int nIDLast,int nIDCheckButton){	HWND	hWndCheck,hWndTemp;	DWORD 	dwStyle;	if (!(hWndCheck = GetDlgItem(hDlg,nIDCheckButton)))	    return;	for(hWndTemp=hDlg->children; hWndTemp; hWndTemp=hWndTemp->siblings) {		if(hWndCheck == hWndTemp) continue;		dwStyle = GetWindowLong(hWndTemp,GWL_STYLE);		if ((hWndTemp->id >= (WORD)nIDFirst) && 		    (hWndTemp->id <= (WORD)nIDLast) &&			((LOWORD(dwStyle) == BS_RADIOBUTTON) ||			 (LOWORD(dwStyle) == BS_AUTORADIOBUTTON)))			SendMessage(hWndTemp,BM_SETCHECK,FALSE,0);	}	SendMessage(hWndCheck,BM_SETCHECK,TRUE,0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -